libssh
0.5.4
|
Add a generic way to handle sockets asynchronously. More...
Functions | |
void | ssh_poll_add_events (ssh_poll_handle p, short events) |
Add extra events to a poll object. More... | |
int | ssh_poll_ctx_add (ssh_poll_ctx ctx, ssh_poll_handle p) |
Add a poll object to a poll context. More... | |
int | ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, ssh_socket s) |
Add a socket object to a poll context. More... | |
int | ssh_poll_ctx_dopoll (ssh_poll_ctx ctx, int timeout) |
Poll all the sockets associated through a poll object with a poll context. More... | |
void | ssh_poll_ctx_free (ssh_poll_ctx ctx) |
Free a poll context. More... | |
ssh_poll_ctx | ssh_poll_ctx_new (size_t chunk_size) |
Create a new poll context. More... | |
void | ssh_poll_ctx_remove (ssh_poll_ctx ctx, ssh_poll_handle p) |
Remove a poll object from a poll context. More... | |
void | ssh_poll_free (ssh_poll_handle p) |
Free a poll object. More... | |
ssh_poll_ctx | ssh_poll_get_ctx (ssh_poll_handle p) |
Get the poll context of a poll object. More... | |
short | ssh_poll_get_events (ssh_poll_handle p) |
Get the events of a poll object. More... | |
socket_t | ssh_poll_get_fd (ssh_poll_handle p) |
Get the raw socket of a poll object. More... | |
ssh_poll_handle | ssh_poll_new (socket_t fd, short events, ssh_poll_callback cb, void *userdata) |
Allocate a new poll object, which could be used within a poll context. More... | |
void | ssh_poll_remove_events (ssh_poll_handle p, short events) |
Remove events from a poll object. More... | |
void | ssh_poll_set_callback (ssh_poll_handle p, ssh_poll_callback cb, void *userdata) |
Set the callback of a poll object. More... | |
void | ssh_poll_set_events (ssh_poll_handle p, short events) |
Set the events of a poll object. More... | |
void | ssh_poll_set_fd (ssh_poll_handle p, socket_t fd) |
Set the file descriptor of a poll object. More... | |
Add a generic way to handle sockets asynchronously.
It's based on poll objects, each of which store a socket, its events and a callback, which gets called whenever an event is set. The poll objects are attached to a poll context, which should be allocated on per thread basis.
Polling the poll context will poll all the attached poll objects and call their callbacks (handlers) if any of the socket events are set. This should be done within the main loop of an application.
void ssh_poll_add_events | ( | ssh_poll_handle | p, |
short | events | ||
) |
Add extra events to a poll object.
Duplicates are ignored. The events will also be propagated to an associated poll context.
p | Pointer to an already allocated poll object. |
events | Poll events. |
References ssh_poll_get_events(), and ssh_poll_set_events().
int ssh_poll_ctx_add | ( | ssh_poll_ctx | ctx, |
ssh_poll_handle | p | ||
) |
Add a poll object to a poll context.
ctx | Pointer to an already allocated poll context. |
p | Pointer to an already allocated poll object. |
Referenced by ssh_poll_ctx_add_socket().
int ssh_poll_ctx_add_socket | ( | ssh_poll_ctx | ctx, |
ssh_socket | s | ||
) |
Add a socket object to a poll context.
ctx | Pointer to an already allocated poll context. |
s | A SSH socket handle |
References ssh_poll_ctx_add().
int ssh_poll_ctx_dopoll | ( | ssh_poll_ctx | ctx, |
int | timeout | ||
) |
Poll all the sockets associated through a poll object with a poll context.
If any of the events are set after the poll, the call back function of the socket will be called. This function should be called once within the programs main loop.
ctx | Pointer to an already allocated poll context. |
timeout | An upper limit on the time for which ssh_poll_ctx() will block, in milliseconds. Specifying a negative value means an infinite timeout. This parameter is passed to the poll() function. |
void ssh_poll_ctx_free | ( | ssh_poll_ctx | ctx | ) |
Free a poll context.
ctx | Pointer to an already allocated poll context. |
References ssh_poll_ctx_remove().
Referenced by ssh_free().
ssh_poll_ctx ssh_poll_ctx_new | ( | size_t | chunk_size | ) |
Create a new poll context.
It could be associated with many poll object which are going to be polled at the same time as the poll context. You would need a single poll context per thread.
chunk_size | The size of the memory chunk that will be allocated, when more memory is needed. This is for efficiency reasons, i.e. don't allocate memory for each new poll object, but for the next 5. Set it to 0 if you want to use the library's default value. |
void ssh_poll_ctx_remove | ( | ssh_poll_ctx | ctx, |
ssh_poll_handle | p | ||
) |
Remove a poll object from a poll context.
ctx | Pointer to an already allocated poll context. |
p | Pointer to an already allocated poll object. |
Referenced by ssh_poll_ctx_free(), and ssh_poll_free().
void ssh_poll_free | ( | ssh_poll_handle | p | ) |
Free a poll object.
p | Pointer to an already allocated poll object. |
References ssh_poll_ctx_remove().
ssh_poll_ctx ssh_poll_get_ctx | ( | ssh_poll_handle | p | ) |
Get the poll context of a poll object.
p | Pointer to an already allocated poll object. |
short ssh_poll_get_events | ( | ssh_poll_handle | p | ) |
Get the events of a poll object.
p | Pointer to an already allocated poll object. |
Referenced by ssh_poll_add_events(), and ssh_poll_remove_events().
socket_t ssh_poll_get_fd | ( | ssh_poll_handle | p | ) |
Get the raw socket of a poll object.
p | Pointer to an already allocated poll object. |
ssh_poll_handle ssh_poll_new | ( | socket_t | fd, |
short | events, | ||
ssh_poll_callback | cb, | ||
void * | userdata | ||
) |
Allocate a new poll object, which could be used within a poll context.
fd | Socket that will be polled. |
events | Poll events that will be monitored for the socket. i.e. POLLIN, POLLPRI, POLLOUT |
cb | Function to be called if any of the events are set. |
userdata | Userdata to be passed to the callback function. NULL if not needed. |
void ssh_poll_remove_events | ( | ssh_poll_handle | p, |
short | events | ||
) |
Remove events from a poll object.
Non-existent are ignored. The events will also be propagated to an associated poll context.
p | Pointer to an already allocated poll object. |
events | Poll events. |
References ssh_poll_get_events(), and ssh_poll_set_events().
void ssh_poll_set_callback | ( | ssh_poll_handle | p, |
ssh_poll_callback | cb, | ||
void * | userdata | ||
) |
Set the callback of a poll object.
p | Pointer to an already allocated poll object. |
cb | Function to be called if any of the events are set. |
userdata | Userdata to be passed to the callback function. NULL if not needed. |
void ssh_poll_set_events | ( | ssh_poll_handle | p, |
short | events | ||
) |
Set the events of a poll object.
The events will also be propagated to an associated poll context.
p | Pointer to an already allocated poll object. |
events | Poll events. |
Referenced by ssh_poll_add_events(), and ssh_poll_remove_events().
void ssh_poll_set_fd | ( | ssh_poll_handle | p, |
socket_t | fd | ||
) |
Set the file descriptor of a poll object.
The FD will also be propagated to an associated poll context.
p | Pointer to an already allocated poll object. |
fd | New file descriptor. |