Next: , Previous: , Up: Embedding API   [Contents][Index]

5.2.8 Socket management

The functions described in this section deal with the operations on C structures called svz_socket_t. See the description of each function for details on which kind of socket it can handle and what they are for.

Function: int svz_sock_nconnections (void)

Return the number of currently connected sockets.

Function: int svz_sock_write (svz_socket_t *sock, char *buf, int len)

Write len bytes from the memory location pointed to by buf to the output buffer of the socket sock. Also try to flush the buffer to the socket of sock if possible. Return a non-zero value on error, which normally means a buffer overflow.

Function: int svz_sock_printf (svz_socket_t *sock, const char *fmt, …)

Print a formatted string on the socket sock. fmt is the printf-style format string, which describes how to format the optional arguments.

Function: int svz_sock_resize_buffers (svz_socket_t *sock, int send_buf_size, int recv_buf_size)

Resize the send and receive buffers for the socket sock. send_buf_size is the new size for the send buffer, recv_buf_size for the receive buffer. Note that data may be lost when the buffers shrink. For a new buffer size of 0 the buffer is freed and the pointer set to NULL.

Function: int svz_sock_check_request (svz_socket_t *sock)

Check for the kind of packet delimiter within sock and and assign one of the default check_request routines (one or more byte delimiters or a fixed size).

Afterwards this function will never ever be called again because the callback gets overwritten here.

Function: void svz_sock_reduce_recv (svz_socket_t *sock, int len)

Shorten the receive buffer of sock by len bytes.

Function: void svz_sock_reduce_send (svz_socket_t *sock, int len)

Reduce the send buffer of sock by len bytes.

Because libserveez manages the creation and destruction of svz_socket_t objects internally, the following API element is useful for syncronizing client-code references to those objects with those objects.

Function: void svz_sock_prefree (int addsub, svz_sock_prefree_fn fn)

Register (if addsub is non-zero), or unregister (otherwise) the function fn to be called immediately prior to a svz_socket_t being freed. fn is called with one arg sock, and should not return anything. In other words:

typedef void (svz_sock_prefree_fn) (const svz_socket_t *);

Note the const!

Next: Coserver functions, Previous: Client connections, Up: Embedding API   [Contents][Index]