Data Structures | Functions
socket_connection.h File Reference

Stream socket connection. More...

Data Structures

struct  vtm_socket_con
 

Functions

VTM_API struct vtm_socket_convtm_socket_con_new (vtm_socket *sock)
 
VTM_API void vtm_socket_con_free (struct vtm_socket_con *con)
 
VTM_API int vtm_socket_con_init (struct vtm_socket_con *con, vtm_socket *sock)
 
VTM_API void vtm_socket_con_release (struct vtm_socket_con *con)
 
VTM_API void vtm_socket_con_set_usr_data (struct vtm_socket_con *con, void *data)
 
VTM_API void * vtm_socket_con_get_usr_data (struct vtm_socket_con *con)
 
VTM_API void vtm_socket_con_write_lock (struct vtm_socket_con *con)
 
VTM_API void vtm_socket_con_write_unlock (struct vtm_socket_con *con)
 
VTM_API int vtm_socket_con_write_start (struct vtm_socket_con *con)
 
VTM_API int vtm_socket_con_write (struct vtm_socket_con *con)
 

Function Documentation

VTM_API struct vtm_socket_con* vtm_socket_con_new ( vtm_socket *  sock)

Creates and initializes a new socket connection on the heap.

Parameters
sockthe socket that should be associated with the connection
Returns
the created connection
NULL if memory allocation or initialization failed
VTM_API void vtm_socket_con_free ( struct vtm_socket_con con)

Releases a socket connection and frees the pointer.

After this call the connection pointer is no longer valid.

Parameters
conthe connection that should be released
VTM_API int vtm_socket_con_init ( struct vtm_socket_con con,
vtm_socket *  sock 
)

Initializes a new socket connection.

Returns
VTM_OK if the initialization was successful
VTM_ERROR if an error occured
VTM_API void vtm_socket_con_release ( struct vtm_socket_con con)

Releases a socket connection.

After this call the connection structure is no longer valid.

Parameters
conthe connection that should be released
VTM_API void vtm_socket_con_set_usr_data ( struct vtm_socket_con con,
void *  data 
)

Stores arbitrary user data with the connection.

Parameters
conthe connection that should store the user data
datathe data that should be stored
VTM_API void* vtm_socket_con_get_usr_data ( struct vtm_socket_con con)

Retrieves the stored user data.

Parameters
conthe connection
Returns
the previous saved user data
NULL if no data was stored
VTM_API void vtm_socket_con_write_lock ( struct vtm_socket_con con)

Locks the internal writer buffer.

This method must be called if new data should be stored in the output buffer of the connection.

Parameters
conthe connection that should be locked
VTM_API void vtm_socket_con_write_unlock ( struct vtm_socket_con con)

Unlocks the internal writer buffer.

This method must be called after new data was tored in the output buffer of the connection.

Parameters
conthe connection that should be unlocked
VTM_API int vtm_socket_con_write_start ( struct vtm_socket_con con)

Starts sending the contents of the output buffer.

vtm_socket_con_write_lock() must be called prior to this function.

Parameters
conthe connection that should send data
Returns
VTM_OK if the call succeed
VTM_ERROR if an error occured
VTM_API int vtm_socket_con_write ( struct vtm_socket_con con)

Sends the next chunk of data from the output buffer

Parameters
conthe connection that should send data
Returns
VTM_OK if all remaining data was sent
VTM_E_IO_AGAIN if the function must be called again later
VTM_E_IO_CLOSED if the connection was closed
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured