libgslutil
1.2.3
|
Functions | |
int | membuf_recv (int fd, struct membuf_t **m, struct addrinfo *addr))) |
Read a packet into a membuf [non-blocking]. More... | |
int | membuf_recv_wait (int fd, struct membuf_t **m, struct addrinfo *addr, int timeout))) |
Read a packet into a membuf [blocking]. More... | |
Routines for I/O on network connections.
int membuf_recv | ( | int | fd, |
struct membuf_t ** | m, | ||
struct addrinfo * | addr | ||
) |
Read a packet into a membuf [non-blocking].
fd | File descriptor of the packet socket (may be blocking or non-blocking). | |
[in,out] | m | Membuf to read into (may dereference to 0). |
[out] | addr | Pointer to struct addrinfo . Source address written here. May be 0. |
0 | on success. |
-1 | on error (and see errno). |
This function will read a single packet into a memory buffer, which it will first clear (and possibly allocate) using membuf_realloc(). On error, -1 is returned and errno set as per recvfrom().
The client's remote address may be retrieved by passing a pointer to a struct addrinfo
in addr (see sockaddr_to_addrinfo()).
EAGAIN
if there are no packets available, even if the socket is in blocking mode. See membuf_recv_wait() for an alternative solution that blocks, with an optional timeout. int membuf_recv_wait | ( | int | fd, |
struct membuf_t ** | m, | ||
struct addrinfo * | addr, | ||
int | timeout | ||
) |
Read a packet into a membuf [blocking].
fd | File descriptor of the packet socket (may be blocking or non-blocking). | |
[in,out] | m | Membuf to read into (may dereference to 0). |
[out] | addr | Pointer to struct addrinfo . Source address written here. May be 0. |
timeout | Timeout, in milliseconds, as per poll(2) . |
0 | on success. |
-1 | on error (and see errno). |
This function will read a single packet into a memory buffer, which it will first clear (and possibly allocate) using membuf_realloc(). On error, -1 is returned and errno set as per recvfrom().
The client's remote address may be retrieved by passing a pointer to a struct addrinfo
in addr (see sockaddr_to_addrinfo()).
This function uses poll(2)
internally so it will block even if the socket is set to non-blocking mode. The timeout argument may be negative for no timeout, 0 for instant timeout, or a positive number for that many milliseconds. On a timeout, errno will be set to EAGAIN
.