#include <icy/net/udpsocket.h>Inherits:
Handle< uv_udp_t >,Socket
UDP socket implementation.
| Return | Name | Description |
|---|---|---|
UDPSocket | Constructs the UDPSocket and initializes the underlying libuv handle. | |
UDPSocket | Deleted constructor. | |
UDPSocket | Deleted constructor. | |
void | connect virtual | Records the peer address and fires the Connect signal to mimic TCP socket behaviour. UDP is connectionless; this call does not send any data. |
void | connect virtual | Resolves host via DNS (or maps "localhost"), then calls connect(Address). |
void | close virtual | Stops receiving and closes the underlying UDP handle. |
void | bind virtual | Binds the socket to address and starts the receive loop. |
ssize_t | send virtual | Sends len bytes to the previously connected peer address. Returns -1 if no peer address has been set. |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
ssize_t | send virtual | Sends len bytes to peerAddress. Returns -1 if the socket is uninitialized or the address is not authorized. |
ssize_t | sendOwned virtual | |
bool | setBroadcast | Enables or disables UDP broadcast. |
bool | setMulticastLoop | Enables or disables IP multicast loopback. |
bool | setMulticastTTL | Sets the IP multicast time-to-live (hop limit). |
net::Address | address virtual const | Returns the locally bound address, or a wildcard address if unbound. |
net::Address | peerAddress virtual const | Returns the connected peer address set by connect(), or a wildcard address if unconnected. |
net::TransportType | transport virtual const | Returns the UDP transport protocol. |
void | setError virtual | Sets the socket error and triggers close. |
const icy::Error & | error virtual const | Returns the current socket error, if any. |
bool | closed virtual const | Returns true if the native socket handle is closed. |
uv::Loop * | loop virtual const | Returns the event loop associated with this socket. |
void | onRecv virtual | Dispatches a received datagram to all socket adapters via onSocketRecv. |
UDPSocket(uv::Loop * loop)Constructs the UDPSocket and initializes the underlying libuv handle.
loop Event loop to use; defaults to the default loop.UDPSocket(const UDPSocket &) = deleteDeleted constructor.
UDPSocket(UDPSocket &&) = deleteDeleted constructor.
virtual
virtual void connect(const net::Address & peerAddress)Records the peer address and fires the Connect signal to mimic TCP socket behaviour. UDP is connectionless; this call does not send any data.
peerAddress The remote address to associate with this socket.virtual
virtual void connect(std::string_view host, uint16_t port)Resolves host via DNS (or maps "localhost"), then calls connect(Address).
host Hostname or IP address string.
port Destination port.
virtual
virtual void close()Stops receiving and closes the underlying UDP handle.
virtual
virtual void bind(const net::Address & address, unsigned flags)Binds the socket to address and starts the receive loop.
address Local address to bind to.
flags Optional bind flags (UV_UDP_IPV6ONLY is added automatically for IPv6).
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Sends len bytes to the previously connected peer address. Returns -1 if no peer address has been set.
data Pointer to the data to send.
len Number of bytes to send.
flags Reserved; currently unused.
Number of bytes accepted for sending, or -1 on error.
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)Sends an owned payload buffer to the connected peer.
virtual
virtual ssize_t send(const char * data, size_t len, const net::Address & peerAddress, int flags)Sends len bytes to peerAddress. Returns -1 if the socket is uninitialized or the address is not authorized.
data Pointer to the data to send.
len Number of bytes to send.
peerAddress Destination address; must match the connected peer if one is set.
flags Reserved; currently unused.
Number of bytes accepted for sending, or -1 on error.
virtual
virtual ssize_t sendOwned(Buffer && buffer, const net::Address & peerAddress, int flags)bool setBroadcast(bool flag)Enables or disables UDP broadcast.
flag true to enable broadcast.true if the option was set successfully.
bool setMulticastLoop(bool flag)Enables or disables IP multicast loopback.
flag true to enable multicast loopback.true if the option was set successfully.
bool setMulticastTTL(int ttl)Sets the IP multicast time-to-live (hop limit).
ttl Value in the range [1, 255].true if the option was set successfully.
std::invalid_argument if ttl is out of range.virtual const
virtual net::Address address() constReturns the locally bound address, or a wildcard address if unbound.
virtual const
virtual net::Address peerAddress() constReturns the connected peer address set by connect(), or a wildcard address if unconnected.
virtual const
virtual net::TransportType transport() constReturns the UDP transport protocol.
virtual
virtual void setError(const icy::Error & err)Sets the socket error and triggers close.
err The error to record.virtual const
virtual const icy::Error & error() constReturns the current socket error, if any.
virtual const
virtual bool closed() constReturns true if the native socket handle is closed.
virtual const
virtual uv::Loop * loop() constReturns the event loop associated with this socket.
virtual
virtual void onRecv(const MutableBuffer & buf, const net::Address & address)Dispatches a received datagram to all socket adapters via onSocketRecv.
buf Buffer containing the received datagram payload.
address Address of the sender.
net::Address _peerBuffer _buffer| Return | Name | Description |
|---|---|---|
void | init virtual | Initializes the underlying socket context. |
void | reset virtual | Resets the socket context for reuse. |
void | onError virtual | Called by [setError()](#seterror-4) after the error state has been updated. |
void | onClose virtual | Called by [close()](#close-23) after the context has been released. |
bool | recvStart virtual | |
bool | recvStop virtual |
virtual
virtual void init()Initializes the underlying socket context.
virtual
virtual void reset()Resets the socket context for reuse.
virtual
virtual void onError(const icy::Error & error)Called by [setError()](#seterror-4) after the error state has been updated.
Override to react to errors. The default implementation is a no-op.
error The error that was set.virtual
virtual void onClose()Called by [close()](#close-23) after the context has been released.
Override to perform cleanup on handle closure. The default implementation is a no-op.
virtual
virtual bool recvStart()virtual
virtual bool recvStop()std::shared_ptr< UDPSocket > Ptr()std::vector< Ptr > Vec()