Event based socket listener (epoll, kqueue, select)
More...
|
typedef struct vtm_socket_listener | vtm_socket_listener |
|
VTM_API vtm_socket_listener* vtm_socket_listener_new |
( |
size_t |
max_events | ) |
|
Creates a new socket listener.
- Parameters
-
max_events | maximum 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
-
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
-
li | the listener where the socket should be removed from |
sock | the 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
-
li | the corresponding listener |
sock | the 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
-
| li | the target listener |
[out] | events | pointer to array of socket event pointers |
[out] | num_events | number 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
-
li | the listener that should be interrupted |
- Returns
- VTM_OK if the call succeed
-
VTM_ERROR if an error occured