FreeRDP
ringbuffer.c File Reference
#include <freerdp/config.h>
#include <freerdp/utils/ringbuffer.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/assert.h>
#include <winpr/crt.h>
#include <freerdp/log.h>

Macros

#define TAG   FREERDP_TAG("utils.ringbuffer")
 
#define DEBUG_RINGBUFFER(...)
 

Functions

BOOL ringbuffer_init (RingBuffer *rb, size_t initialSize)
 
size_t ringbuffer_used (const RingBuffer *rb)
 
size_t ringbuffer_capacity (const RingBuffer *rb)
 
void ringbuffer_destroy (RingBuffer *rb)
 
static BOOL ringbuffer_realloc (RingBuffer *rb, size_t targetSize)
 
BOOL ringbuffer_write (RingBuffer *rb, const BYTE *ptr, size_t sz)
 
BYTEringbuffer_ensure_linear_write (RingBuffer *rb, size_t sz)
 
BOOL ringbuffer_commit_written_bytes (RingBuffer *rb, size_t sz)
 
int ringbuffer_peek (const RingBuffer *rb, DataChunk chunks[2], size_t sz)
 
void ringbuffer_commit_read_bytes (RingBuffer *rb, size_t sz)
 

Macro Definition Documentation

◆ DEBUG_RINGBUFFER

#define DEBUG_RINGBUFFER (   ...)
Value:
do \
{ \
} while (0)

◆ TAG

#define TAG   FREERDP_TAG("utils.ringbuffer")

FreeRDP: A Remote Desktop Protocol Implementation

Copyright 2014 Thincast Technologies GmbH Copyright 2014 Hardening conta.nosp@m.ct@h.nosp@m.arden.nosp@m.ing-.nosp@m.consu.nosp@m.ltin.nosp@m.g.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ ringbuffer_capacity()

size_t ringbuffer_capacity ( const RingBuffer ringbuffer)

returns the capacity of the ring buffer

Parameters
ringbufferA pointer to the ringbuffer
Returns
the capacity of this ring buffer
Here is the caller graph for this function:

◆ ringbuffer_commit_read_bytes()

void ringbuffer_commit_read_bytes ( RingBuffer rb,
size_t  sz 
)

move ahead the read head in case some byte were read using ringbuffer_peek() This function is used to commit the bytes that were effectively consumed.

Parameters
rbthe ring buffer
szthe number of bytes to read
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ringbuffer_commit_written_bytes()

BOOL ringbuffer_commit_written_bytes ( RingBuffer rb,
size_t  sz 
)

move ahead the write head in case some byte were written directly by using a pointer retrieved via ringbuffer_ensure_linear_write(). This function is used to commit the written bytes. The provided size should not exceed the size ensured by ringbuffer_ensure_linear_write()

Parameters
rbthe ring buffer
szthe number of bytes that have been written
Returns
if the operation was successful, FALSE is sz is too big
Here is the caller graph for this function:

◆ ringbuffer_destroy()

void ringbuffer_destroy ( RingBuffer ringbuffer)

destroys internal data used by this ringbuffer

Parameters
ringbufferA pointer to the ringbuffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ringbuffer_ensure_linear_write()

BYTE* ringbuffer_ensure_linear_write ( RingBuffer rb,
size_t  sz 
)

ensures that we have sz bytes available at the write head, and return a pointer on the write head

Parameters
rbthe ring buffer
szthe size to ensure
Returns
a pointer on the write head, or NULL in case of OOM
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ringbuffer_init()

BOOL ringbuffer_init ( RingBuffer rb,
size_t  initialSize 
)

initialise a ringbuffer

Parameters
initialSizethe initial capacity of the ringBuffer
Returns
if the initialisation was successful
Here is the caller graph for this function:

◆ ringbuffer_peek()

int ringbuffer_peek ( const RingBuffer rb,
DataChunk  chunks[2],
size_t  sz 
)

peeks the buffer chunks for sz bytes and returns how many chunks are filled. Note that the sum of the resulting chunks may be smaller than sz.

Parameters
rbthe ringbuffer
chunksan array of data chunks that will contain data / size of chunks
szthe requested size
Returns
the number of chunks used for reading sz bytes
Here is the caller graph for this function:

◆ ringbuffer_realloc()

static BOOL ringbuffer_realloc ( RingBuffer rb,
size_t  targetSize 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ringbuffer_used()

size_t ringbuffer_used ( const RingBuffer ringbuffer)

computes the space used in this ringbuffer

Parameters
ringbufferA pointer to the ringbuffer
Returns
the number of bytes stored in that ringbuffer
Here is the caller graph for this function:

◆ ringbuffer_write()

BOOL ringbuffer_write ( RingBuffer rb,
const BYTE ptr,
size_t  sz 
)

Write to a ringbuffer

Parameters
rbA pointer to the ringbuffer
ptrA pointer to the data to write
szThe number of bytes to write
Returns
TRUE for success, FALSE for failure
Here is the call graph for this function:
Here is the caller graph for this function: