dbuffer.h File Reference

Data buffers (struct dbuffer). More...

#include <sys/types.h>
Include dependency graph for dbuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dbuffer
 Opaque dbuffer struct. More...

Defines

#define dbuffer_len(A)   (A ? (A)->len : 0)

Functions

struct dbuffernew_dbuffer (void) __attribute__((malloc))
 Allocate a dbuffer.
void free_dbuffer (struct dbuffer *)
 Deallocate a dbuffer.
void dbuffer_add (struct dbuffer *, const char *, size_t)
 Append data to a dbuffer.
size_t dbuffer_get (const struct dbuffer *, char *, size_t)
 Read data from a dbuffer.
size_t dbuffer_get_at (const struct dbuffer *, size_t, char *, size_t)
 Read data from a dbuffer.
size_t dbuffer_remove (struct dbuffer *, size_t)
 Deletes data from a dbuffer.
size_t dbuffer_extract (struct dbuffer *, char *, size_t)
 Read and delete data from a dbuffer.
struct dbufferdbuffer_dup (struct dbuffer *)
 Allocate a dbuffer.
struct dbufferdbuffer_prepend (struct dbuffer *old, const char *data, size_t len)
 Allocate a dbuffer and prepend the given data to it.
struct dbufferdbuffer_merge (struct dbuffer *old, struct dbuffer *old2)
 Merges two dbuffers.
void dbuffer_shutdown (void)
void dbuffer_init (void)

Detailed Description

Data buffers (struct dbuffer).

Definition in file dbuffer.h.


Define Documentation

#define dbuffer_len (  )     (A ? (A)->len : 0)

Function Documentation

void dbuffer_add ( struct dbuffer buf,
const char *  data,
size_t  len 
)

Append data to a dbuffer.

Parameters:
[in,out] buf the target buffer
[in] data pointer to the start of the bytes to add
[in] len number of bytes to add Adds the given sequence of bytes to the end of the buffer.

Definition at line 263 of file dbuffer.c.

References dbuffer_element::data, dbuffer_grow(), dbuffer::end, dbuffer::len, dbuffer_element::len, dbuffer_element::next, dbuffer_element::space, dbuffer::space, and dbuffer::tail.

Referenced by CL_ForwardToServer_f(), Cmd_ForwardToServer(), dbuffer_dup(), dbuffer_merge(), dbuffer_prepend(), NET_ReadMsg(), NET_StreamEnqueue(), NET_VPrintf(), NET_Wait(), NET_WriteByte(), NET_WriteChar(), NET_WriteLong(), NET_WriteRawString(), NET_WriteShort(), and NET_WriteString().

struct dbuffer* dbuffer_dup ( struct dbuffer old  )  [read]

Allocate a dbuffer.

Parameters:
[in] old the source buffer
Returns:
the newly allocated buffer Allocates a new dbuffer and initialises it to contain a copy of the data in old

Definition at line 397 of file dbuffer.c.

References dbuffer_element::data, dbuffer_add(), dbuffer::head, dbuffer_element::len, new_dbuffer(), dbuffer_element::next, and dbuffer::start.

Referenced by CL_ParseEvent().

size_t dbuffer_extract ( struct dbuffer buf,
char *  data,
size_t  len 
)

Read and delete data from a dbuffer.

Parameters:
[in,out] buf the source buffer
[out] data pointer to where the data should be copied
[in] len maximum number of bytes to copy
Returns:
number of bytes copied
Copies up to len bytes into data, and removes them from the dbuffer
If the buffer does not contain at least len bytes, then as many bytes as are present will be copied.
However many bytes are copied, exactly that many will be removed from the start of the dbuffer.

Definition at line 471 of file dbuffer.c.

References dbuffer_element::data, DBUFFER_ELEMENT_SIZE, dbuffer::end, free_element(), dbuffer::head, dbuffer_element::len, dbuffer::len, dbuffer_element::next, dbuffer::space, and dbuffer::start.

Referenced by NET_ReadByte(), NET_ReadChar(), NET_ReadLong(), NET_ReadShort(), NET_StreamDequeue(), and NET_WriteMsg().

size_t dbuffer_get ( const struct dbuffer buf,
char *  data,
size_t  len 
)

Read data from a dbuffer.

Parameters:
[in] buf the source buffer
[out] data pointer to where the data should be copied
[in] len maximum number of bytes to copy
Returns:
number of bytes copied
Copies up to len bytes into data
If the buffer does not contain at least len bytes, then as many bytes as are present will be copied.

Definition at line 310 of file dbuffer.c.

References dbuffer_element::data, dbuffer::head, dbuffer_element::len, dbuffer_element::next, and dbuffer::start.

Referenced by NET_PeekShort(), NET_StreamPeek(), and NET_Wait().

size_t dbuffer_get_at ( const struct dbuffer buf,
size_t  offset,
char *  data,
size_t  len 
)

Read data from a dbuffer.

Parameters:
[in] buf the source buffer
[in] offset the offset in the source buffer where data should be copied from
[out] data pointer to where the data should be copied
[in] len maximum number of bytes to copy
Returns:
number of bytes copied
Copies up to len bytes into data
If the buffer does not contain at least len bytes after offset, then as many bytes as are present will be copied.

Definition at line 350 of file dbuffer.c.

References dbuffer_element::data, dbuffer::head, dbuffer_element::len, dbuffer_element::next, and dbuffer::start.

Referenced by NET_WriteConstMsg().

void dbuffer_init ( void   ) 

Definition at line 503 of file dbuffer.c.

References dbuf_lock.

Referenced by NET_Init().

struct dbuffer* dbuffer_merge ( struct dbuffer old,
struct dbuffer old2 
) [read]

Merges two dbuffers.

Parameters:
[in] old the source buffer
[in] old2 the second source buffer
Returns:
the newly allocated buffer Allocates a new dbuffer and initialises it to contain a copy of the data in old ones

Definition at line 201 of file dbuffer.c.

References dbuffer_element::data, dbuffer_add(), dbuffer::head, dbuffer_element::len, new_dbuffer(), dbuffer_element::next, and dbuffer::start.

struct dbuffer* dbuffer_prepend ( struct dbuffer old,
const char *  data,
size_t  len 
) [read]

Allocate a dbuffer and prepend the given data to it.

Parameters:
[in] old The source buffer
[in] data The data to insert at the beginning
[in] len The length of that data
Returns:
the newly allocated buffer Allocates a new dbuffer and initialises it to contain a copy of the data in old

Definition at line 236 of file dbuffer.c.

References dbuffer_element::data, dbuffer_add(), dbuffer::head, dbuffer_element::len, new_dbuffer(), dbuffer_element::next, and dbuffer::start.

size_t dbuffer_remove ( struct dbuffer buf,
size_t  len 
)

Deletes data from a dbuffer.

Parameters:
[in,out] buf the target buffer
[in] len number of bytes to delete Deletes the given number of bytes from the start of the dbuffer

Definition at line 421 of file dbuffer.c.

References dbuffer_element::data, DBUFFER_ELEMENT_SIZE, dbuffer::end, free_element(), dbuffer::head, dbuffer_element::len, dbuffer::len, dbuffer_element::next, dbuffer::space, and dbuffer::start.

Referenced by NET_Wait().

void dbuffer_shutdown ( void   ) 

Definition at line 508 of file dbuffer.c.

References dbuf_lock.

Referenced by NET_Shutdown().

void free_dbuffer ( struct dbuffer buf  ) 
struct dbuffer* new_dbuffer ( void   )  [read]

Generated by  doxygen 1.6.2