Typedefs | Functions
socket_listener.h File Reference

Event based socket listener (epoll, kqueue, select) More...

Typedefs

typedef struct vtm_socket_listener vtm_socket_listener
 

Functions

VTM_API vtm_socket_listener * vtm_socket_listener_new (size_t max_events)
 
VTM_API void vtm_socket_listener_free (vtm_socket_listener *li)
 
VTM_API int vtm_socket_listener_add (vtm_socket_listener *li, vtm_socket *sock)
 
VTM_API int vtm_socket_listener_remove (vtm_socket_listener *li, vtm_socket *sock)
 
VTM_API int vtm_socket_listener_rearm (vtm_socket_listener *li, vtm_socket *sock)
 
VTM_API int vtm_socket_listener_run (vtm_socket_listener *li, struct vtm_socket_event **events, size_t *num_events)
 
VTM_API int vtm_socket_listener_interrupt (vtm_socket_listener *li)
 

Function Documentation

VTM_API vtm_socket_listener* vtm_socket_listener_new ( size_t  max_events)

Creates a new socket listener.

Parameters
max_eventsmaximum number of events this listener should return at once
Returns
a socket listener handle
NULL if an error occured
VTM_API void vtm_socket_listener_free ( vtm_socket_listener *  li)

Releases the socker listener and all allocated resources.

Parameters
lithe target listener
VTM_API int vtm_socket_listener_add ( vtm_socket_listener *  li,
vtm_socket *  sock 
)

Registers a socket for receiving events.

The socket hints (for example VTM_SOCK_HINT_NBL_READ) must be set before the socket is registered.

Returns
VTM_OK if the socket was successfully registered
VTM_E_MAX_REACHED if the maximum number of sockets this type of socket listener could handle is reached
VTM_ERROR if an error occured
VTM_API int vtm_socket_listener_remove ( vtm_socket_listener *  li,
vtm_socket *  sock 
)

Unregisters a socket.

Parameters
lithe listener where the socket should be removed from
sockthe socket that should be removed
Returns
VTM_OK if the socket was successfully unregistered
VTM_ERROR if the socket was not registered
VTM_API int vtm_socket_listener_rearm ( vtm_socket_listener *  li,
vtm_socket *  sock 
)

Marks the socket so that new events are received.

Parameters
lithe corresponding listener
sockthe socket that should be re-armed.
Returns
VTM_OK if call succeeded
VTM_ERROR if an error occcured
VTM_API int vtm_socket_listener_run ( vtm_socket_listener *  li,
struct vtm_socket_event **  events,
size_t *  num_events 
)

Wait for new socket events.

This call may block a certain time if no events are available.

Parameters
lithe target listener
[out]eventspointer to array of socket event pointers
[out]num_eventsnumber of events read
Returns
VTM_OK if the call succeed
VTM_ERROR if an error occcured
VTM_API int vtm_socket_listener_interrupt ( vtm_socket_listener *  li)

Interrupts the listener if he is blocked in waiting for events.

Parameters
lithe listener that should be interrupted
Returns
VTM_OK if the call succeed
VTM_ERROR if an error occured