uvcc
libuv C++ bindings
uv::udp Class Reference

UDP handle. More...

#include "handle-udp.hpp"

Inheritance diagram for uv::udp:
uv::io uv::handle

Classes

struct  io_info
 Supplemental data passed as the last argument to io::on_read_t callback function called by recv_start(). More...
 

Public Types

using uv_t = ::uv_udp_t
 
- Public Types inherited from uv::io
using uv_t = void
 
using on_read_t = std::function< void(io _handle, ssize_t _nread, buffer _buffer, int64_t _offset, void *_info) >
 The function type of the callback called by read_start() when data was read from an I/O endpoint. More...
 
- Public Types inherited from uv::handle
using uv_t = ::uv_handle_t
 
using on_destroy_t = std::function< void(void *_data) >
 The function type of the callback called when the handle has been closed and about to be destroyed. More...
 

Public Member Functions

 udp (const udp &)=default
 
udpoperator= (const udp &)=default
 
 udp (udp &&) noexcept=default
 
udpoperator= (udp &&) noexcept=default
 
 udp (uv::loop &_loop, unsigned int _flags=AF_UNSPEC)
 
 udp (uv::loop &_loop, ::uv_os_sock_t _socket)
 
::uv_os_sock_t socket () const noexcept
 Get the platform dependent socket descriptor. The alias for handle::fileno().
 
std::size_t send_queue_size () const noexcept
 Number of bytes queued for sending. This field strictly shows how much information is currently queued.
 
std::size_t send_queue_count () const noexcept
 Number of send requests currently in the queue awaiting to be processed.
 
template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
int bind (const _T_ &_sockaddr, unsigned int _flags=0) noexcept
 
template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
bool getsockname (_T_ &_sockaddr) const noexcept
 Get the local address and port which this handle is bound to. More...
 
int set_ttl (int _value) noexcept
 Set the time to live value. More...
 
int recv_start (const on_buffer_alloc_t &_alloc_cb, const on_read_t &_recv_cb, std::size_t _size=0) const
 Alias for io::read_start().
 
int recv_start (std::size_t _size=0) const
 Idem.
 
int recv_stop () const
 Alias for io::read_stop().
 
unsigned int send_buffer_size () const noexcept
 Get the size of the send buffer that the operating system uses for the socket. More...
 
void send_buffer_size (unsigned int _value) noexcept
 Set the size of the send buffer that the operating system uses for the socket. More...
 
unsigned int recv_buffer_size () const noexcept
 Get the size of the receive buffer that the operating system uses for the socket. More...
 
void recv_buffer_size (unsigned int _value) noexcept
 Set the size of the receive buffer that the operating system uses for the socket. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
UDP multicast/broadcast features:
int set_multicast_membership (const char *_multicast_addr, const char *_interface_addr, ::uv_membership _membership) noexcept
 Set membership for a multicast address. More...
 
int set_multicast_loop (bool _enable) noexcept
 Set IP multicast loop flag. Makes multicast packets loop back to local sockets. More...
 
int set_multicast_ttl (int _value) noexcept
 Set the multicast TTL value. More...
 
int set_multicast_interface (const char *_interface_addr) noexcept
 Set the multicast interface to send or receive data on. More...
 
int set_broadcast (bool _enable) noexcept
 Set broadcast on or off. More...
 
- Public Member Functions inherited from uv::io
 io (const io &)=default
 
iooperator= (const io &)=default
 
 io (io &&) noexcept=default
 
iooperator= (io &&) noexcept=default
 
std::size_t write_queue_size () const noexcept
 The amount of queued bytes waiting to be written/sent to the I/O endpoint. More...
 
on_buffer_alloc_ton_alloc () const noexcept
 Set the input buffer allocation callback.
 
on_read_ton_read () const noexcept
 Set the read callback function.
 
int read_start (std::size_t _size=0, int64_t _offset=-1) const
 Start reading incoming data from the I/O endpoint. More...
 
int read_start (const on_buffer_alloc_t &_alloc_cb, const on_read_t &_read_cb, std::size_t _size=0, int64_t _offset=-1) const
 Start reading incoming data from the I/O endpoint with provided input buffer allocation callback (_alloc_cb) and read callback function (_read_cb). More...
 
int read_stop () const
 Stop reading data from the I/O endpoint. More...
 
int read_pause (bool _trigger_condition) const
 Pause reading data from the I/O endpoint. More...
 
int read_resume (bool _trigger_condition)
 Resume reading data from the I/O endpoint after having been paused. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
- Public Member Functions inherited from uv::handle
 handle (const handle &_that)
 
handleoperator= (const handle &_that)
 
 handle (handle &&_that) noexcept
 
handleoperator= (handle &&_that) noexcept
 
void swap (handle &_that) noexcept
 
std::uintptr_t id () const noexcept
 The unique ID of the instance managed by this handle variable or 0 if the handle is void.
 
long nrefs () const noexcept
 The current number of existing references to the same object as this handle variable refers to.
 
int uv_status () const noexcept
 The status value returned by the last executed libuv API function on this handle.
 
on_destroy_ton_destroy () const noexcept
 
::uv_handle_type type () const noexcept
 The tag indicating the libuv type of the handle.
 
const char * type_name () const noexcept
 A string containing the name of the handle type.
 
uv::loop loop () const noexcept
 The libuv loop where the handle is running on. More...
 
void *& data () const noexcept
 The pointer to the user-defined arbitrary data. libuv and uvcc does not use this field.
 
int is_active () const noexcept
 Check if the handle is active. More...
 
int is_closing () const noexcept
 Check if the handle is closing or closed. More...
 
::uv_os_fd_t fileno () const noexcept
 Get the platform dependent handle/file descriptor. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
 operator bool () const noexcept
 Equivalent to (id() and uv_status() >= 0).
 
void attached (bool _state) const noexcept
 
bool attached () const noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from uv::io
static io guess_handle (uv::loop &, ::uv_file)
 Create an io handle object which actual type is derived from an existing file descriptor. More...
 

Detailed Description

UDP handle.

See also
libuv API documentation: uv_udp_t — UDP handle.

Definition at line 23 of file handle-udp.hpp.

Constructor & Destructor Documentation

◆ udp() [1/2]

uv::udp::udp ( uv::loop _loop,
unsigned int  _flags = AF_UNSPEC 
)
inline

Create a UDP socket with the specified flags.

Note
With AF_UNSPEC flag no socket is actually created on the system.
See also
libuv API documentation: uv_udp_init_ex().
libuv enhancement proposals: https://github.com/libuv/leps/blob/master/003-create-sockets-early.md.

Definition at line 95 of file handle-udp.hpp.

◆ udp() [2/2]

uv::udp::udp ( uv::loop _loop,
::uv_os_sock_t  _socket 
)
inline

Create a handle object from an existing native platform depended datagram socket descriptor.

See also
libuv API documentation: uv_udp_open(), uv_udp_init().

Definition at line 107 of file handle-udp.hpp.

Member Function Documentation

◆ set_multicast_membership()

int uv::udp::set_multicast_membership ( const char *  _multicast_addr,
const char *  _interface_addr,
::uv_membership  _membership 
)
inlinenoexcept

Set membership for a multicast address.

See also
libuv API documentation: uv_udp_set_membership(), uv_membership.

Definition at line 137 of file handle-udp.hpp.

◆ set_multicast_loop()

int uv::udp::set_multicast_loop ( bool  _enable)
inlinenoexcept

Set IP multicast loop flag. Makes multicast packets loop back to local sockets.

See also
libuv API documentation: uv_udp_set_multicast_loop().

Definition at line 146 of file handle-udp.hpp.

◆ set_multicast_ttl()

int uv::udp::set_multicast_ttl ( int  _value)
inlinenoexcept

Set the multicast TTL value.

See also
libuv API documentation: uv_udp_set_multicast_ttl().

Definition at line 150 of file handle-udp.hpp.

◆ set_multicast_interface()

int uv::udp::set_multicast_interface ( const char *  _interface_addr)
inlinenoexcept

Set the multicast interface to send or receive data on.

See also
libuv API documentation: uv_udp_set_multicast_interface().

Definition at line 154 of file handle-udp.hpp.

◆ set_broadcast()

int uv::udp::set_broadcast ( bool  _enable)
inlinenoexcept

Set broadcast on or off.

See also
libuv API documentation: uv_udp_set_broadcast().

Definition at line 158 of file handle-udp.hpp.

◆ bind()

template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
int uv::udp::bind ( const _T_ &  _sockaddr,
unsigned int  _flags = 0 
)
inlinenoexcept

Bind the handle to an address and port.

See also
libuv API documentation: uv_udp_bind(), uv_udp_flags.

Definition at line 169 of file handle-udp.hpp.

◆ getsockname()

template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
bool uv::udp::getsockname ( _T_ &  _sockaddr) const
inlinenoexcept

Get the local address and port which this handle is bound to.

Returns
true if the operation has completed successfully (can be checked with uv_status()) and the size of the passed argument (i.e. sizeof(_T_)) is enough to hold the returned socket address structure.
See also
libuv API documentation: uv_udp_getsockname().

Definition at line 179 of file handle-udp.hpp.

◆ set_ttl()

int uv::udp::set_ttl ( int  _value)
inlinenoexcept

Set the time to live value.

See also
libuv API documentation: uv_udp_set_ttl().

Definition at line 190 of file handle-udp.hpp.

◆ send_buffer_size() [1/2]

unsigned int uv::udp::send_buffer_size ( ) const
inlinenoexcept

Get the size of the send buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_send_buffer_size().

Definition at line 203 of file handle-udp.hpp.

◆ send_buffer_size() [2/2]

void uv::udp::send_buffer_size ( unsigned int  _value)
inlinenoexcept

Set the size of the send buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_send_buffer_size().

Definition at line 211 of file handle-udp.hpp.

◆ recv_buffer_size() [1/2]

unsigned int uv::udp::recv_buffer_size ( ) const
inlinenoexcept

Get the size of the receive buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_recv_buffer_size().

Definition at line 215 of file handle-udp.hpp.

◆ recv_buffer_size() [2/2]

void uv::udp::recv_buffer_size ( unsigned int  _value)
inlinenoexcept

Set the size of the receive buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_recv_buffer_size().

Definition at line 223 of file handle-udp.hpp.


The documentation for this class was generated from the following file: