Data Structures | Typedefs | Functions
socket_dgram_server.h File Reference

Datagram based network server. More...

Data Structures

struct  vtm_socket_dgram
struct  vtm_socket_dgram_srv_cbs
struct  vtm_socket_dgram_srv_opts


typedef struct vtm_socket_dgram_srv vtm_socket_dgram_srv


VTM_API vtm_socket_dgram_srv * vtm_socket_dgram_srv_new (void)
VTM_API void vtm_socket_dgram_srv_free (vtm_socket_dgram_srv *srv)
VTM_API void * vtm_socket_dgram_srv_get_usr_data (vtm_socket_dgram_srv *srv)
VTM_API void vtm_socket_dgram_srv_set_usr_data (vtm_socket_dgram_srv *srv, void *data)
VTM_API int vtm_socket_dgram_srv_run (vtm_socket_dgram_srv *srv, struct vtm_socket_dgram_srv_opts *opts)
VTM_API int vtm_socket_dgram_srv_stop (vtm_socket_dgram_srv *srv)
VTM_API int vtm_socket_dgram_srv_send (vtm_socket_dgram_srv *srv, void *buf, size_t len, const struct vtm_socket_saddr *saddr)

Function Documentation

VTM_API vtm_socket_dgram_srv* vtm_socket_dgram_srv_new ( void  )

Creates a new server.

the created server which can be used in the other functions
NULL if an error occured
VTM_API void vtm_socket_dgram_srv_free ( vtm_socket_dgram_srv *  srv)

Releases the server and all allocated resources.

After this call the server pointer is no longer valid.

srvthe server which should be released
VTM_API void* vtm_socket_dgram_srv_get_usr_data ( vtm_socket_dgram_srv *  srv)

Retrieves the stored user data.

srvthe server
the previous saved user data
NULL if no data was stored
VTM_API void vtm_socket_dgram_srv_set_usr_data ( vtm_socket_dgram_srv *  srv,
void *  data 

Stores arbitrary user data with the server.

srvthe server that should store the user data
datathe data that should be stored
VTM_API int vtm_socket_dgram_srv_run ( vtm_socket_dgram_srv *  srv,
struct vtm_socket_dgram_srv_opts opts 

Runs the server.

This method blocks until the server is stopped or if an error occurs.

srvthe previously created server
optsthe options for running the server
VTM_OK if the server has been started successfully and has already been shut down again
VTM_ERROR or other more specific error code when the server could not be started
VTM_API int vtm_socket_dgram_srv_stop ( vtm_socket_dgram_srv *  srv)

Stops the server.

This method blocks until the server is gracefully shutdown.

srvthe server which should be stopped
VTM_OK if the shutdown was successful
VTM_ERROR if an error occured
VTM_API int vtm_socket_dgram_srv_send ( vtm_socket_dgram_srv *  srv,
void *  buf,
size_t  len,
const struct vtm_socket_saddr saddr 

Sends a datagram to the given address.

srvthe server that should send the message
bufthe payload of the datagram
lenthe the length in bytes of the payload
saddrthe destination address
VTM_OK if the datagram was sent successfully
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured