Crossfire Server, Branch 1.12  R12190
Functions
lowlevel.c File Reference

Low-level socket-related functions. More...

#include <assert.h>
#include <stdarg.h>
#include <global.h>
#include <newclient.h>
#include <sproto.h>
#include <errno.h>
Include dependency graph for lowlevel.c:

Go to the source code of this file.

Functions

static void add_to_buffer (socket_struct *ns, const unsigned char *buf, int len)
 Adds data to a socket buffer for whatever reason.
int GetInt_String (const unsigned char *data)
 Basically does the reverse of SockList_AddInt, but on strings instead.
short GetShort_String (const unsigned char *data)
void Send_With_Handling (socket_struct *ns, SockList *sl)
 Calls Write_To_Socket to send data to the client.
void SockList_AddChar (SockList *sl, char data)
 Adds an 8 bit value.
void SockList_AddData (SockList *sl, const void *data, size_t len)
 Adds a data block.
void SockList_AddInt (SockList *sl, uint32 data)
 Adds a 32 bit value.
void SockList_AddInt64 (SockList *sl, uint64 data)
 Adds a 64 bit value.
void SockList_AddLen8Data (SockList *sl, const void *data, size_t len)
 Adds a data block prepended with an 8 bit length field.
void SockList_AddPrintf (SockList *sl, const char *format,...)
 Adds a printf like formatted string.
void SockList_AddShort (SockList *sl, uint16 data)
 Adds a 16 bit value.
void SockList_AddString (SockList *sl, const char *data)
 Adds a string without length.
void SockList_AddStringBuffer (SockList *sl, StringBuffer *sb)
 Deallocates string buffer instance and appends its contents.
size_t SockList_Avail (const SockList *sl)
 Returns the available bytes in a SockList instance.
static void SockList_Ensure (const SockList *sl, size_t size)
 Checks that at least a given number of bytes is available in a SockList instance.
void SockList_Init (SockList *sl)
 Initializes the SockList instance.
void SockList_NullTerminate (SockList *sl)
 Adds a NUL byte without changing the length.
int SockList_ReadPacket (int fd, SockList *sl, int len)
 This reads from fd and puts the data in sl.
void SockList_Reset (SockList *sl)
 Resets the length of the stored data for writing.
void SockList_ResetRead (SockList *sl)
 Resets the length of the stored data for reading.
void SockList_Term (SockList *sl)
 Frees all resources allocated by a SockList instance.
void write_socket_buffer (socket_struct *ns)
 Writes data to socket.
static void Write_To_Socket (socket_struct *ns, const unsigned char *buf, int len)
 This writes data to the socket.

Detailed Description

Low-level socket-related functions.

Date:
2003-12-02

Contains some base functions that both the client and server can use. As such, depending what we are being compiled for will determine what we can include. the client is designed have CFCLIENT defined as part of its compile flags.

Definition in file lowlevel.c.


Function Documentation

static void add_to_buffer ( socket_struct ns,
const unsigned char *  buf,
int  len 
) [static]

Adds data to a socket buffer for whatever reason.

ns is the socket we are adding the data to, buf is the start of the data, and len is the number of bytes to add.

Definition at line 383 of file lowlevel.c.

References buffer_struct::data, socket_struct::fd, buffer_struct::len, llevDebug, LOG(), Ns_Dead, socket_struct::outputbuffer, SOCKETBUFSIZE, buffer_struct::start, and socket_struct::status.

Referenced by Write_To_Socket().

Here is the call graph for this function:

Here is the caller graph for this function:

int GetInt_String ( const unsigned char *  data)

Basically does the reverse of SockList_AddInt, but on strings instead.

Same for the GetShort, but for 16 bits.

Definition at line 239 of file lowlevel.c.

Referenced by inscribe_scroll_cmd(), lock_item_cmd(), mark_item_cmd(), and new_player_cmd().

Here is the caller graph for this function:

short GetShort_String ( const unsigned char *  data)

Definition at line 243 of file lowlevel.c.

Referenced by new_player_cmd().

Here is the caller graph for this function:

void Send_With_Handling ( socket_struct ns,
SockList sl 
)
void SockList_AddChar ( SockList sl,
char  data 
)

Adds an 8 bit value.

sl the SockList instance to add to

Parameters:
cthe value to add

Definition at line 103 of file lowlevel.c.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by add_object_to_socklist(), append_spell(), check_space_for_heads(), draw_client_map2(), draw_magic_map(), esrv_draw_look(), esrv_send_face(), esrv_update_item(), esrv_update_spells(), esrv_update_stats(), map2_add_ob(), map2_delete_layer(), play_sound_player_only(), send_image_sums(), and SockList_AddLen8Data().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddData ( SockList sl,
const void *  data,
size_t  len 
)

Adds a data block.

Parameters:
slthe SockList instance to add to
datathe value to add
lenthe length in byte

Definition at line 164 of file lowlevel.c.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by append_spell(), esrv_send_face(), SockList_AddLen8Data(), and SockList_AddString().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddInt ( SockList sl,
uint32  data 
)

Adds a 32 bit value.

sl the SockList instance to add to

Parameters:
datathe value to add

Definition at line 124 of file lowlevel.c.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by add_object_to_socklist(), append_spell(), esrv_del_item(), esrv_draw_look(), esrv_new_player(), esrv_remove_spell(), esrv_send_face(), esrv_send_inventory(), esrv_send_item(), esrv_send_pickup(), esrv_update_item(), esrv_update_spells(), new_player_cmd(), send_image_sums(), and send_tick().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddInt64 ( SockList sl,
uint64  data 
)

Adds a 64 bit value.

sl the SockList instance to add to

Parameters:
datathe value to add

Definition at line 137 of file lowlevel.c.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by esrv_update_stats(), and send_exp_table().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddLen8Data ( SockList sl,
const void *  data,
size_t  len 
)

Adds a data block prepended with an 8 bit length field.

Parameters:
slthe SockList instance to add to
datathe value to add
lenthe length in byte; must not exceed 255

Definition at line 176 of file lowlevel.c.

References SockList_AddChar(), and SockList_AddData().

Referenced by add_object_to_socklist(), append_spell(), esrv_draw_look(), esrv_new_player(), esrv_update_item(), play_sound_player_only(), and send_image_sums().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddPrintf ( SockList sl,
const char *  format,
  ... 
)

Adds a printf like formatted string.

Parameters:
slthe SockList instance to add to
formatthe format specifier

Definition at line 187 of file lowlevel.c.

References SockList::buf, fatal(), SockList::len, OUT_OF_MEMORY, and vsnprintf.

Referenced by build_class_list_reply(), build_race_list_reply(), draw_magic_map(), esrv_draw_look(), esrv_print_ext_msg(), esrv_print_msg(), esrv_send_inventory(), init_connection(), send_image_info(), send_image_sums(), send_query(), send_race_info(), send_skill_info(), send_spell_paths(), set_face_mode_cmd(), set_up_cmd(), and toggle_extended_text_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddShort ( SockList sl,
uint16  data 
)

Adds a 16 bit value.

sl the SockList instance to add to

Parameters:
datathe value to add

Definition at line 113 of file lowlevel.c.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by add_object_to_socklist(), append_spell(), check_space_for_heads(), draw_client_map2(), esrv_draw_look(), esrv_send_animation(), esrv_send_face(), esrv_update_item(), esrv_update_spells(), map2_add_ob(), map2_delete_layer(), new_player_cmd(), send_exp_table(), send_image_sums(), and send_smooth().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_AddString ( SockList sl,
const char *  data 
)
void SockList_AddStringBuffer ( SockList sl,
StringBuffer sb 
)

Deallocates string buffer instance and appends its contents.

The passed StringBuffer must not be accessed afterwards.

Parameters:
slthe SockList instance to add to
sbthe StringBuffer to deallocate

Definition at line 210 of file lowlevel.c.

References SockList_AddString(), and stringbuffer_finish().

Here is the call graph for this function:

size_t SockList_Avail ( const SockList sl)

Returns the available bytes in a SockList instance.

Returns:
the available bytes

Definition at line 231 of file lowlevel.c.

References SockList::buf, and SockList::len.

Referenced by esrv_add_spells(), esrv_draw_look(), esrv_send_inventory(), send_exp_table(), send_image_sums(), send_skill_info(), and send_spell_paths().

Here is the caller graph for this function:

static void SockList_Ensure ( const SockList sl,
size_t  size 
) [static]

Checks that at least a given number of bytes is available in a SockList instance.

Returns normal if the space is available. Otherwise calls fatal(OUT_OF_MEMORY);

Parameters:
slthe SockList instance to check
sizethe number of bytes to ensure

Definition at line 584 of file lowlevel.c.

References SockList::buf, fatal(), SockList::len, and OUT_OF_MEMORY.

Referenced by SockList_AddChar(), SockList_AddData(), SockList_AddInt(), SockList_AddInt64(), SockList_AddShort(), and SockList_NullTerminate().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_Init ( SockList sl)

Adds a NUL byte without changing the length.

Parameters:
slthe SockList instance to add to

Definition at line 222 of file lowlevel.c.

References SockList::buf, SockList::len, and SockList_Ensure().

Referenced by handle_client().

Here is the call graph for this function:

Here is the caller graph for this function:

int SockList_ReadPacket ( int  fd,
SockList sl,
int  len 
)

This reads from fd and puts the data in sl.

We return true if we think we have a full packet, 0 if we have a partial packet, or -1 if an error occurred. The only processing we do is remove the initial size value. len (As passed) is the size of the buffer allocated in the socklist. We make the assumption the buffer is at least 2 bytes long.

Definition at line 260 of file lowlevel.c.

References SockList::buf, cst_lst, cst_tot, CS_Stats::ibytes, SockList::len, llevDebug, llevError, LOG(), MAX_BUF, and strerror_local().

Referenced by handle_client().

Here is the call graph for this function:

Here is the caller graph for this function:

void SockList_Reset ( SockList sl)

Resets the length of the stored data for writing.

Does not free or re-allocate resources.

Parameters:
slthe SockList instance to reset

Definition at line 85 of file lowlevel.c.

References SockList::len.

Referenced by build_class_list_reply(), esrv_add_spells(), esrv_draw_look(), esrv_send_inventory(), send_image_sums(), and SockList_Init().

Here is the caller graph for this function:

void SockList_ResetRead ( SockList sl)

Resets the length of the stored data for reading.

Does not free or re-allocate resources.

Parameters:
slthe SockList instance to reset

Definition at line 94 of file lowlevel.c.

References SockList::len.

Referenced by add_player(), handle_client(), and init_connection().

Here is the caller graph for this function:

void SockList_Term ( SockList sl)

Writes data to socket.

When the socket is clear to write, and we have backlogged data, this is called to write it out.

Definition at line 418 of file lowlevel.c.

References socket_struct::can_write, cst_lst, cst_tot, buffer_struct::data, socket_struct::fd, buffer_struct::len, llevDebug, llevError, LOG(), MAX_BUF, Ns_Dead, CS_Stats::obytes, socket_struct::outputbuffer, SOCKETBUFSIZE, buffer_struct::start, socket_struct::status, and strerror_local().

Referenced by do_server().

Here is the call graph for this function:

Here is the caller graph for this function:

static void Write_To_Socket ( socket_struct ns,
const unsigned char *  buf,
int  len 
) [static]

This writes data to the socket.

  • It is very low level - all we try and do is write out the data to the socket provided (ns). buf is the data to write, len is the number of bytes to write. IT doesn't return anything - rather, it updates the ns structure if we get an error.

Definition at line 477 of file lowlevel.c.

References add_to_buffer(), socket_struct::can_write, cst_lst, cst_tot, socket_struct::fd, llevDebug, llevError, LOG(), MAX_BUF, Ns_Dead, CS_Stats::obytes, socket_struct::status, and strerror_local().

Referenced by Send_With_Handling().

Here is the call graph for this function:

Here is the caller graph for this function: