UDPSocket
UDPSocket
#include <icy/net/udpsocket.h>class UDPSocketDefined in src/net/include/icy/net/udpsocket.h:28
Inherits:
Handle< uv_udp_t >,Socket
UDP socket implementation.
List of all members
| Name | Kind | Owner |
|---|---|---|
UDPSocket | function | Declared here |
~UDPSocket | function | Declared here |
UDPSocket | function | Declared here |
operator= | function | Declared here |
UDPSocket | function | Declared here |
operator= | function | Declared here |
connect | function | Declared here |
connect | function | Declared here |
close | function | Declared here |
bind | function | Declared here |
send | function | Declared here |
sendOwned | function | Declared here |
send | function | Declared here |
sendOwned | function | Declared here |
setBroadcast | function | Declared here |
setMulticastLoop | function | Declared here |
setMulticastTTL | function | Declared here |
address | function | Declared here |
peerAddress | function | Declared here |
transport | function | Declared here |
setError | function | Declared here |
error | function | Declared here |
closed | function | Declared here |
loop | function | Declared here |
onRecv | function | Declared here |
_peer | variable | Declared here |
_buffer | variable | Declared here |
init | function | Declared here |
reset | function | Declared here |
onError | function | Declared here |
onClose | function | Declared here |
recvStart | function | Declared here |
recvStop | function | Declared here |
Ptr | typedef | Declared here |
Vec | typedef | Declared here |
Handle | function | Inherited from Handle |
~Handle | function | Inherited from Handle |
init | function | Inherited from Handle |
invoke | function | Inherited from Handle |
invokeOrThrow | function | Inherited from Handle |
close | function | Inherited from Handle |
ref | function | Inherited from Handle |
unref | function | Inherited from Handle |
initialized | function | Inherited from Handle |
active | function | Inherited from Handle |
closing | function | Inherited from Handle |
closed | function | Inherited from Handle |
error | function | Inherited from Handle |
setError | function | Inherited from Handle |
setUVError | function | Inherited from Handle |
setAndThrowError | function | Inherited from Handle |
throwLastError | function | Inherited from Handle |
loop | function | Inherited from Handle |
reset | function | Inherited from Handle |
get | function | Inherited from Handle |
tid | function | Inherited from Handle |
context | function | Inherited from Handle |
setCloseCleanup | function | Inherited from Handle |
clearCloseCleanup | function | Inherited from Handle |
assertThread | function | Inherited from Handle |
_loop | variable | Inherited from Handle |
_context | variable | Inherited from Handle |
_tid | variable | Inherited from Handle |
_error | variable | Inherited from Handle |
onError | function | Inherited from Handle |
onClose | function | Inherited from Handle |
Handle | function | Inherited from Handle |
operator= | function | Inherited from Handle |
Handle | function | Inherited from Handle |
operator= | function | Inherited from Handle |
Type | typedef | Inherited from Handle |
opaque | variable | Inherited from Socket |
Socket | function | Inherited from Socket |
~Socket | function | Inherited from Socket |
Socket | function | Inherited from Socket |
operator= | function | Inherited from Socket |
Socket | function | Inherited from Socket |
operator= | function | Inherited from Socket |
connect | function | Inherited from Socket |
connect | function | Inherited from Socket |
bind | function | Inherited from Socket |
listen | function | Inherited from Socket |
shutdown | function | Inherited from Socket |
sendOwned | function | Inherited from Socket |
sendOwned | function | Inherited from Socket |
close | function | Inherited from Socket |
address | function | Inherited from Socket |
peerAddress | function | Inherited from Socket |
transport | function | Inherited from Socket |
setError | function | Inherited from Socket |
error | function | Inherited from Socket |
closed | function | Inherited from Socket |
loop | function | Inherited from Socket |
_af | variable | Inherited from Socket |
init | function | Inherited from Socket |
reset | function | Inherited from Socket |
Ptr | typedef | Inherited from Socket |
Vec | typedef | Inherited from Socket |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from Handle
| Kind | Name | Description |
|---|---|---|
function | Handle inline | Construct the handle bound to the given event loop. |
function | ~Handle virtual inline | |
function | init inline | Initialize the underlying libuv handle by calling f with the loop, the raw handle pointer, and any additional args. |
function | invoke inline | Invoke a libuv function f with args on the initialized handle. |
function | invokeOrThrow inline | Invoke a libuv function f with args, throwing on failure. |
function | close virtual inline | Close and destroy the handle. |
function | ref inline | Re-reference the handle with the event loop after a previous [unref()](icy-uv-Handle.html#unref). |
function | unref inline | Unreference the handle from the event loop. |
function | initialized const inline | Return true if the handle has been successfully initialized via [init()](icy-uv-Handle.html#init-8). |
function | active virtual const inline | Return true when the handle is active (libuv uv_is_active). |
function | closing virtual const inline | Return true if uv_close has been called and the handle is awaiting its close callback (libuv uv_is_closing). |
function | closed virtual const inline | Return true if the handle has been fully closed (context released). |
function | error const inline | Return the last error set on this handle, or a default-constructed [Error](icy-Error.html#error) if no error has occurred. |
function | setError virtual inline | Set the error state and invoke [onError()](icy-uv-Handle.html#onerror). |
function | setUVError inline | Translate a libuv error code into an [Error](icy-Error.html#error) and call [setError()](icy-uv-Handle.html#seterror-1). |
function | setAndThrowError inline | Set the error state from a libuv error code and throw a std::runtime_error. |
function | throwLastError inline | Throw a std::runtime_error if the handle currently holds an error. |
function | loop const inline | Return the event loop this handle is bound to. |
function | reset inline | Close the current handle (if open) and allocate a fresh [Context](icy-uv-Context.html#context-2), leaving the handle ready to be re-initialized via [init()](icy-uv-Handle.html#init-8). |
function | get const inline | Return the raw libuv handle pointer cast to [Handle](icy-uv-Handle.html#handle-6). |
function | tid const inline | Return the ID of the thread that constructed this handle. |
function | context const inline | Return the raw [Context](icy-uv-Context.html#context-2) that owns the libuv handle memory. |
function | setCloseCleanup inline | |
function | clearCloseCleanup inline | |
function | assertThread const inline | Throw std::logic_error if called from any thread other than the thread that constructed this handle. |
variable | _loop | |
variable | _context | |
variable | _tid | |
variable | _error | |
function | onError virtual inline | Called by [setError()](icy-uv-Handle.html#seterror-1) after the error state has been updated. |
function | onClose virtual inline | Called by [close()](icy-uv-Handle.html#close-18) after the context has been released. |
function | Handle | NonCopyable and NonMovable. |
function | operator= | Deleted assignment operator. |
function | Handle | Deleted constructor. |
function | operator= | Deleted assignment operator. |
typedef | Type | Define the native handle type. |
Inherited from Socket
| Kind | Name | Description |
|---|---|---|
variable | opaque | Optional client data. |
function | Socket | Defaulted constructor. |
function | ~Socket virtual noexcept | Defaulted destructor. |
function | Socket | Deleted constructor. |
function | operator= | Deleted assignment operator. |
function | Socket | Deleted constructor. |
function | operator= | Deleted assignment operator. |
function | connect virtual | Connects to the given peer IP address. |
function | connect virtual | Resolves and connects to the given host address. |
function | bind virtual | Bind a local address to the socket. The address may be IPv4 or IPv6 (if supported). |
function | listen virtual inline | Listens the socket on the given address. |
function | shutdown virtual inline | Sends the shutdown packet which should result is socket closure via callback. |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | close virtual | Closes the underlying socket. |
function | address virtual const | The locally bound address. |
function | peerAddress virtual const | The connected peer address. |
function | transport virtual const | The transport protocol: TCP, UDP or SSLTCP. |
function | setError virtual | Sets the socket error. |
function | error virtual const | Return the socket error if any. |
function | closed virtual const | Returns true if the native socket handle is closed. |
function | loop virtual const | Returns the socket event loop. |
variable | _af | |
function | init virtual | Initializes the underlying socket context. |
function | reset virtual | Resets the socket context for reuse. |
typedef | Ptr | |
typedef | Vec |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | send virtual | Sends the given data buffer to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | sendPacket virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. This method provides delegate compatibility, and unlike other send methods throws an exception if the underlying socket is closed. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | onSocketConnect virtual | Called when the socket establishes a connection. Forwards the event to all registered receivers in priority order. Override to intercept before the application sees the event. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
function | cleanupReceivers virtual |
Public Methods
| Return | Name | Description |
|---|---|---|
UDPSocket | Constructs the UDPSocket and initializes the underlying libuv handle. | |
UDPSocket | Deleted constructor. | |
UDPSocket | Deleted constructor. | |
void | connect virtual override | 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 override | Resolves host via DNS (or maps "localhost"), then calls connect(Address). |
void | close virtual override | Stops receiving and closes the underlying UDP handle. |
void | bind virtual override | Binds the socket to address and starts the receive loop. |
ssize_t | send virtual override | Sends len bytes to the previously connected peer address. Returns -1 if no peer address has been set. |
ssize_t | sendOwned virtual override | Sends an owned payload buffer to the connected peer. |
ssize_t | send virtual override | Sends len bytes to peerAddress. Returns -1 if the socket is uninitialized or the address is not authorized. |
ssize_t | sendOwned virtual override | |
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 override | Returns the locally bound address, or a wildcard address if unbound. |
net::Address | peerAddress virtual const override | Returns the connected peer address set by connect(), or a wildcard address if unconnected. |
net::TransportType | transport virtual const override | Returns the UDP transport protocol. |
void | setError virtual override | Sets the socket error and triggers close. |
const icy::Error & | error virtual const override | Returns the current socket error, if any. |
bool | closed virtual const override | Returns true if the native socket handle is closed. |
uv::Loop * | loop virtual const override | Returns the event loop associated with this socket. |
void | onRecv virtual | Dispatches a received datagram to all socket adapters via onSocketRecv. |
UDPSocket
UDPSocket(uv::Loop * loop = uv::defaultLoop())Defined in src/net/include/icy/net/udpsocket.h:37
Constructs the UDPSocket and initializes the underlying libuv handle.
Parameters
loopEvent loop to use; defaults to the default loop.
UDPSocket
UDPSocket(const UDPSocket &) = deleteDefined in src/net/include/icy/net/udpsocket.h:40
Deleted constructor.
UDPSocket
UDPSocket(UDPSocket &&) = deleteDefined in src/net/include/icy/net/udpsocket.h:42
Deleted constructor.
connect
virtual override
virtual void connect(const net::Address & peerAddress) overrideDefined in src/net/include/icy/net/udpsocket.h:48
Records the peer address and fires the Connect signal to mimic TCP socket behaviour. UDP is connectionless; this call does not send any data.
Parameters
peerAddressThe remote address to associate with this socket.
Reimplements
connect
virtual override
virtual void connect(std::string_view host, uint16_t port) overrideDefined in src/net/include/icy/net/udpsocket.h:53
Resolves host via DNS (or maps "localhost"), then calls connect(Address).
Parameters
hostHostname or IP address string.portDestination port.
Reimplements
close
virtual override
virtual void close() overrideDefined in src/net/include/icy/net/udpsocket.h:56
Stops receiving and closes the underlying UDP handle.
Reimplements
bind
virtual override
virtual void bind(const net::Address & address, unsigned flags = 0) overrideDefined in src/net/include/icy/net/udpsocket.h:61
Binds the socket to address and starts the receive loop.
Parameters
addressLocal address to bind to.flagsOptional bind flags (UV_UDP_IPV6ONLY is added automatically for IPv6).
Reimplements
send
virtual override
virtual ssize_t send(const char * data, size_t len, int flags = 0) overrideDefined in src/net/include/icy/net/udpsocket.h:69
Sends len bytes to the previously connected peer address. Returns -1 if no peer address has been set.
Parameters
dataPointer to the data to send.lenNumber of bytes to send.flagsReserved; currently unused.
Returns
Number of bytes accepted for sending, or -1 on error.
Reimplements
sendOwned
virtual override
virtual ssize_t sendOwned(Buffer && buffer, int flags = 0) overrideDefined in src/net/include/icy/net/udpsocket.h:70
Sends an owned payload buffer to the connected peer.
Reimplements
send
virtual override
virtual ssize_t send(const char * data, size_t len, const net::Address & peerAddress, int flags = 0) overrideDefined in src/net/include/icy/net/udpsocket.h:79
Sends len bytes to peerAddress. Returns -1 if the socket is uninitialized or the address is not authorized.
Parameters
dataPointer to the data to send.lenNumber of bytes to send.peerAddressDestination address; must match the connected peer if one is set.flagsReserved; currently unused.
Returns
Number of bytes accepted for sending, or -1 on error.
Reimplements
sendOwned
virtual override
virtual ssize_t sendOwned(Buffer && buffer, const net::Address & peerAddress, int flags = 0) overrideDefined in src/net/include/icy/net/udpsocket.h:81
Reimplements
setBroadcast
bool setBroadcast(bool flag)Defined in src/net/include/icy/net/udpsocket.h:87
Enables or disables UDP broadcast.
Parameters
flagtrue to enable broadcast.
Returns
true if the option was set successfully.
setMulticastLoop
bool setMulticastLoop(bool flag)Defined in src/net/include/icy/net/udpsocket.h:92
Enables or disables IP multicast loopback.
Parameters
flagtrue to enable multicast loopback.
Returns
true if the option was set successfully.
setMulticastTTL
bool setMulticastTTL(int ttl)Defined in src/net/include/icy/net/udpsocket.h:98
Sets the IP multicast time-to-live (hop limit).
Parameters
ttlValue in the range [1, 255].
Returns
true if the option was set successfully.
Exceptions
std::invalid_argumentifttlis out of range.
address
virtual const override
virtual net::Address address() const overrideDefined in src/net/include/icy/net/udpsocket.h:101
Returns the locally bound address, or a wildcard address if unbound.
Reimplements
peerAddress
virtual const override
virtual net::Address peerAddress() const overrideDefined in src/net/include/icy/net/udpsocket.h:104
Returns the connected peer address set by connect(), or a wildcard address if unconnected.
Reimplements
transport
virtual const override
virtual net::TransportType transport() const overrideDefined in src/net/include/icy/net/udpsocket.h:107
Returns the UDP transport protocol.
Reimplements
setError
virtual override
virtual void setError(const icy::Error & err) overrideDefined in src/net/include/icy/net/udpsocket.h:111
Sets the socket error and triggers close.
Parameters
errThe error to record.
Reimplements
error
virtual const override
virtual const icy::Error & error() const overrideDefined in src/net/include/icy/net/udpsocket.h:114
Returns the current socket error, if any.
Reimplements
closed
virtual const override
virtual bool closed() const overrideDefined in src/net/include/icy/net/udpsocket.h:117
Returns true if the native socket handle is closed.
Reimplements
loop
virtual const override
virtual uv::Loop * loop() const overrideDefined in src/net/include/icy/net/udpsocket.h:120
Returns the event loop associated with this socket.
Reimplements
onRecv
virtual
virtual void onRecv(const MutableBuffer & buf, const net::Address & address)Defined in src/net/include/icy/net/udpsocket.h:125
Dispatches a received datagram to all socket adapters via onSocketRecv.
Parameters
bufBuffer containing the received datagram payload.addressAddress of the sender.
Protected Attributes
_peer
net::Address _peerDefined in src/net/include/icy/net/udpsocket.h:141
_buffer
Buffer _bufferDefined in src/net/include/icy/net/udpsocket.h:142
Protected Methods
| Return | Name | Description |
|---|---|---|
void | init virtual override | Initializes the underlying socket context. |
void | reset virtual override | Resets the socket context for reuse. |
void | onError virtual override | Called by [setError()](#seterror-4) after the error state has been updated. |
void | onClose virtual override | Called by [close()](#close-23) after the context has been released. |
bool | recvStart virtual | |
bool | recvStop virtual |
init
virtual override
virtual void init() overrideDefined in src/net/include/icy/net/udpsocket.h:128
Initializes the underlying socket context.
Reimplements
reset
virtual override
virtual void reset() overrideDefined in src/net/include/icy/net/udpsocket.h:129
Resets the socket context for reuse.
Reimplements
onError
virtual override
virtual void onError(const icy::Error & error) overrideDefined in src/net/include/icy/net/udpsocket.h:131
Called by [setError()](#seterror-4) after the error state has been updated.
Override to react to errors. The default implementation is a no-op.
Parameters
errorThe error that was set.
Reimplements
onClose
virtual override
virtual void onClose() overrideDefined in src/net/include/icy/net/udpsocket.h:132
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.
Reimplements
recvStart
virtual
virtual bool recvStart()Defined in src/net/include/icy/net/udpsocket.h:134
recvStop
virtual
virtual bool recvStop()Defined in src/net/include/icy/net/udpsocket.h:135
Public Types
Ptr
using Ptr = std::shared_ptr< UDPSocket >Defined in src/net/include/icy/net/udpsocket.h:32
Vec
using Vec = std::vector< Ptr >