Data buffers (struct dbuffer). More...
#include <sys/types.h>
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 dbuffer * | new_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 dbuffer * | dbuffer_dup (struct dbuffer *) |
Allocate a dbuffer. | |
struct dbuffer * | dbuffer_prepend (struct dbuffer *old, const char *data, size_t len) |
Allocate a dbuffer and prepend the given data to it. | |
struct dbuffer * | dbuffer_merge (struct dbuffer *old, struct dbuffer *old2) |
Merges two dbuffers. | |
void | dbuffer_shutdown (void) |
void | dbuffer_init (void) |
Data buffers (struct dbuffer).
Definition in file dbuffer.h.
#define dbuffer_len | ( | A | ) | (A ? (A)->len : 0) |
Definition at line 107 of file dbuffer.h.
Referenced by NET_ShowStreams_f(), NET_StreamClose(), NET_StreamFinished(), NET_StreamGetLength(), NET_StreamPeek(), NET_Wait(), NET_WriteConstMsg(), and NET_WriteMsg().
void dbuffer_add | ( | struct dbuffer * | buf, | |
const char * | data, | |||
size_t | len | |||
) |
Append data to a dbuffer.
[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().
Allocate a dbuffer.
[in] | old | the source buffer |
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.
[in,out] | buf | the source buffer |
[out] | data | pointer to where the data should be copied |
[in] | len | maximum number of bytes to copy |
len
bytes into data
, and removes them from the dbufferlen
bytes, then as many bytes as are present will be copied.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.
[in] | buf | the source buffer |
[out] | data | pointer to where the data should be copied |
[in] | len | maximum number of bytes to copy |
len
bytes into data
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.
[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 |
len
bytes into data
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 | ) |
Merges two dbuffers.
[in] | old | the source buffer |
[in] | old2 | the second source buffer |
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.
Allocate a dbuffer and prepend the given data to it.
[in] | old | The source buffer |
[in] | data | The data to insert at the beginning |
[in] | len | The length of that data |
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.
[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 | ) |
void free_dbuffer | ( | struct dbuffer * | buf | ) |
Deallocate a dbuffer.
[in,out] | buf | the dbuffer to deallocate Deallocates a dbuffer, and all memory it uses |
Definition at line 146 of file dbuffer.c.
References allocated_dbuffers, dbuf_lock, DBUFFER_FREE_THRESHOLD, free_dbuffers, free_element(), dbuffer::head, Mem_Free, dbuffer_element::next, and dbuffer::next_free.
Referenced by CL_ExecuteBattlescapeEvent(), CL_FreeBattlescapeEvent(), CL_ReadPackets(), NET_StreamClose(), NET_StreamFinished(), NET_WriteMsg(), SV_AbortEvents(), SV_BroadcastPrintf(), SV_FinalMessage(), SV_Multicast(), and SV_ReadPacket().
struct dbuffer* new_dbuffer | ( | void | ) | [read] |
Allocate a dbuffer.
Definition at line 111 of file dbuffer.c.
References allocate_element(), allocated_dbuffers, com_genericPool, dbuffer_element::data, dbuf_lock, DBUFFER_ELEMENT_SIZE, dbuffer::end, free_dbuffers, dbuffer::head, dbuffer::len, Mem_PoolAlloc, dbuffer::next_free, dbuffer::space, dbuffer::start, and dbuffer::tail.
Referenced by CL_ConnectionlessPacket(), CL_Disconnect(), CL_ForwardToServer_f(), CL_NextRound_f(), CL_RequestNextDownload(), CL_SendChangedUserinfos(), Cmd_ForwardToServer(), dbuffer_dup(), dbuffer_merge(), dbuffer_prepend(), do_accept(), GAME_CP_InitializeBattlescape(), GAME_SpawnSoldiers(), MSG_Write_PA(), NET_ConnectToLoopBack(), NET_DoConnect(), NET_ReadMsg(), SV_AddEvent(), SV_BroadcastPrintf(), SV_ClientCommand(), SV_ClientPrintf(), SV_Configstring(), SV_DropClient(), SV_FinalMessage(), SV_FindIndex(), SV_New_f(), SV_StartSound(), SVC_Status(), and SVC_TeamInfo().