libgslutil  1.2.3
Functions
Network I/O routines

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...
 

Detailed Description

Routines for I/O on network connections.

Function Documentation

◆ membuf_recv()

int membuf_recv ( int  fd,
struct membuf_t **  m,
struct addrinfo *  addr 
)

Read a packet into a membuf [non-blocking].

Parameters
fdFile descriptor of the packet socket (may be blocking or non-blocking).
[in,out]mMembuf to read into (may dereference to 0).
[out]addrPointer to struct addrinfo. Source address written here. May be 0.
Return values
0on success.
-1on 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()).

Note
This function will return with 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.

◆ membuf_recv_wait()

int membuf_recv_wait ( int  fd,
struct membuf_t **  m,
struct addrinfo *  addr,
int  timeout 
)

Read a packet into a membuf [blocking].

Parameters
fdFile descriptor of the packet socket (may be blocking or non-blocking).
[in,out]mMembuf to read into (may dereference to 0).
[out]addrPointer to struct addrinfo. Source address written here. May be 0.
timeoutTimeout, in milliseconds, as per poll(2).
Return values
0on success.
-1on 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.