Socket
Socket
#include <icy/net/socket.h>class SocketDefined in src/net/include/icy/net/socket.h:49
Inherits:
SocketAdapterSubclassed by:TCPSocket,UDPSocket
Base socket implementation from which all sockets derive.
List of all members
| Name | Kind | Owner |
|---|---|---|
opaque | variable | Declared here |
Socket | function | Declared here |
~Socket | function | Declared here |
Socket | function | Declared here |
operator= | function | Declared here |
Socket | function | Declared here |
operator= | function | Declared here |
connect | function | Declared here |
connect | function | Declared here |
bind | function | Declared here |
listen | function | Declared here |
shutdown | function | Declared here |
sendOwned | function | Declared here |
sendOwned | function | Declared here |
close | 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 |
_af | variable | Declared here |
init | function | Declared here |
reset | function | Declared here |
Ptr | typedef | Declared here |
Vec | typedef | Declared here |
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 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 Attributes
| Return | Name | Description |
|---|---|---|
std::any | opaque | Optional client data. |
opaque
std::any opaqueDefined in src/net/include/icy/net/socket.h:135
Optional client data.
The value is empty on initialization.
Public Methods
| Return | Name | Description |
|---|---|---|
Socket | Defaulted constructor. | |
Socket | Deleted constructor. | |
Socket | Deleted constructor. | |
void | connect virtual | Connects to the given peer IP address. |
void | connect virtual | Resolves and connects to the given host address. |
void | bind virtual | Bind a local address to the socket. The address may be IPv4 or IPv6 (if supported). |
void | listen virtual inline | Listens the socket on the given address. |
bool | shutdown virtual inline | Sends the shutdown packet which should result is socket closure via callback. |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
ssize_t | sendOwned virtual | |
void | close virtual | Closes the underlying socket. |
Address | address virtual const | The locally bound address. |
Address | peerAddress virtual const | The connected peer address. |
net::TransportType | transport virtual const | The transport protocol: TCP, UDP or SSLTCP. |
void | setError virtual | Sets the socket error. |
const icy::Error & | error virtual const | Return the socket error if any. |
bool | closed virtual const | Returns true if the native socket handle is closed. |
uv::Loop * | loop virtual const | Returns the socket event loop. |
Socket
Socket() = defaultDefined in src/net/include/icy/net/socket.h:55
Defaulted constructor.
Socket
Socket(const Socket &) = deleteDefined in src/net/include/icy/net/socket.h:58
Deleted constructor.
Socket
Socket(Socket &&) = deleteDefined in src/net/include/icy/net/socket.h:60
Deleted constructor.
connect
virtual
virtual void connect(const Address & address)Defined in src/net/include/icy/net/socket.h:67
Connects to the given peer IP address.
Throws an exception if the address is malformed. Connection errors can be handled via the Error signal.
Reimplemented by
connect
virtual
virtual void connect(std::string_view host, uint16_t port)Defined in src/net/include/icy/net/socket.h:74
Resolves and connects to the given host address.
Throws an Exception if the host is malformed. Since the DNS callback is asynchronous implementations need to listen for the Error signal for handling connection errors.
Reimplemented by
bind
virtual
virtual void bind(const Address & address, unsigned flags = 0)Defined in src/net/include/icy/net/socket.h:80
Bind a local address to the socket. The address may be IPv4 or IPv6 (if supported).
Throws an Exception on error.
Reimplemented by
listen
virtual inline
virtual inline void listen(int backlog = 64)Defined in src/net/include/icy/net/socket.h:85
Listens the socket on the given address.
Throws an Exception on error.
Reimplemented by
shutdown
virtual inline
virtual inline bool shutdown()Defined in src/net/include/icy/net/socket.h:89
Sends the shutdown packet which should result is socket closure via callback.
Reimplemented by
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags = 0)Defined in src/net/include/icy/net/socket.h:95
Sends an owned payload buffer to the connected peer.
Reimplements
Reimplemented by
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, const Address & peerAddress, int flags = 0)Defined in src/net/include/icy/net/socket.h:96
Reimplements
Reimplemented by
close
virtual
virtual void close()Defined in src/net/include/icy/net/socket.h:99
Closes the underlying socket.
Reimplemented by
address
virtual const
virtual Address address() constDefined in src/net/include/icy/net/socket.h:106
The locally bound address.
This function will not throw. A Wildcard 0.0.0.0:0 address is returned if the socket is closed or invalid.
Reimplemented by
peerAddress
virtual const
virtual Address peerAddress() constDefined in src/net/include/icy/net/socket.h:113
The connected peer address.
This function will not throw. A Wildcard 0.0.0.0:0 address is returned if the socket is closed or invalid.
Reimplemented by
transport
virtual const
virtual net::TransportType transport() constDefined in src/net/include/icy/net/socket.h:116
The transport protocol: TCP, UDP or SSLTCP.
Reimplemented by
setError
virtual
virtual void setError(const icy::Error & err)Defined in src/net/include/icy/net/socket.h:121
Sets the socket error.
Setting the error will result in socket closure.
Reimplemented by
error
virtual const
virtual const icy::Error & error() constDefined in src/net/include/icy/net/socket.h:124
Return the socket error if any.
Reimplemented by
closed
virtual const
virtual bool closed() constDefined in src/net/include/icy/net/socket.h:127
Returns true if the native socket handle is closed.
Reimplemented by
loop
virtual const
virtual uv::Loop * loop() constDefined in src/net/include/icy/net/socket.h:130
Returns the socket event loop.
Reimplemented by
Protected Attributes
| Return | Name | Description |
|---|---|---|
int | _af |
_af
int _af {AF_UNSPEC}Defined in src/net/include/icy/net/socket.h:144
Protected Methods
| Return | Name | Description |
|---|---|---|
void | init virtual | Initializes the underlying socket context. |
void | reset virtual | Resets the socket context for reuse. |
init
virtual
virtual void init()Defined in src/net/include/icy/net/socket.h:139
Initializes the underlying socket context.
Reimplemented by
reset
virtual
virtual void reset()Defined in src/net/include/icy/net/socket.h:142
Resets the socket context for reuse.
Reimplemented by
Public Types
Ptr
using Ptr = std::shared_ptr< Socket >Defined in src/net/include/icy/net/socket.h:52
Vec
using Vec = std::vector< Ptr >