Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created August 17, 2011 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/cc11217bf271d8a897c7 to your computer and use it in GitHub Desktop.
Save bnoordhuis/cc11217bf271d8a897c7 to your computer and use it in GitHub Desktop.
/*
* UDP support.
*/
/* Flag constants. Input flags are meant to be passed to `uv_udp_init()`
* and `uv_udp_init6()`. Uutput flags are passed to your `uv_udp_recv_cb`
* callback.
*/
/* Input flag. Disables dual stack mode. Only valid for `uv_udp_init6()`. */
#define UV_UDP_IPV6ONLY (1 << 0)
/* Input flag. Sets SO_REUSEADDR socket option. Allows you
* to steal a bound address:port but only if the currently
* bound process has set the SO_REUSEADDR flag too.
*/
#define UV_UDP_REUSEADDR (1 << 1)
/* Output flag. Incoming message was truncated because the
* read buffer was too small.
*/
#define UV_UDP_PARTIAL (1 << 10)
/*
*
*/
typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
/*
* `handle` UDP handle.
* `nread` Number of bytes read. 0 indicates you should free the buffer.
* Never -1 because UDP errors don't exist.
* `buf` uv_buf_t with the received data.
* `addr` struct sockaddr_in or struct sockaddr_in6. Valid for the duration
* of the callback.
* `flags` One or more or'ed UV_UDP_* constants.
*/
typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
ssize_t nread,
uv_buf_t buf,
struct sockaddr* addr,
unsigned flags);
/*
* Subclass of uv_handle_t
*/
struct uv_udp_s {
UV_HANDLE_FIELDS
UV_UDP_PRIVATE_FIELDS
};
/*
* Subclass of uv_req_t
*/
struct uv_udp_send_s {
UV_REQ_FIELDS
UV_UDP_SEND_PRIVATE_FIELDS
};
int uv_udp_init(uv_udp_t* handle);
int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in, unsigned flags);
int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6, unsigned flags);
int uv_udp_send(uv_udp_send_t* req,
uv_udp_t* handle,
uv_buf_t bufs[],
int bufcnt,
struct sockaddr_in addr,
uv_udp_send_cb send_cb);
int uv_udp_send6(uv_udp_send_t* req,
uv_udp_t* handle,
uv_buf_t bufs[],
int bufcnt,
struct sockaddr_in6 addr,
uv_udp_send_cb send_cb);
int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb);
int uv_udp_recv_stop(uv_udp_t* handle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment