SocketAdapter
#include <icy/net/socketadapter.h>
class SocketAdapterDefined in src/net/include/icy/net/socketadapter.h:41
- Subclassed by
Connection,ConnectionAdapter,ConnectionStream,Server,Socket,SocketEmitter
SocketAdapter is the abstract interface for all socket classes. A SocketAdapter can also be attached to a Socket in order to override default Socket callbacks and behaviour, while still maintaining the default Socket interface (see Socket::setAdapter).
This class can also be extended to implement custom processing for received socket data before it is dispatched to the application (see PacketSocketEmitter and Transaction classes).
Public Attributes
| Return | Name | Description |
|---|---|---|
int | priority | The priority of this adapter for STL sort operations. |
priority
int priority = 0Defined in src/net/include/icy/net/socketadapter.h:132
The priority of this adapter for STL sort operations.
Public Methods
| Return | Name | Description |
|---|---|---|
SocketAdapter | Creates the SocketAdapter. | |
~SocketAdapter virtual noexcept | Destroys the SocketAdapter. | |
ssize_t | 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. |
ssize_t | send virtual | |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
ssize_t | sendOwned virtual | |
ssize_t | 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. |
ssize_t | sendPacket virtual | |
void | 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. |
void | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
SocketAdapter * | sender | Returns the output SocketAdapter pointer. |
void | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
void | removeReceiver virtual | Remove the given receiver. |
bool | hasReceiver virtual | Returns true if the given receiver is connected. |
std::vector< SocketAdapter * > | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
bool | 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. |
bool | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
bool | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
bool | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
SocketAdapter
SocketAdapter(SocketAdapter * sender = nullptr)Defined in src/net/include/icy/net/socketadapter.h:45
Creates the SocketAdapter.
~SocketAdapter
virtual noexcept
virtual ~SocketAdapter() noexceptDefined in src/net/include/icy/net/socketadapter.h:48
Destroys the SocketAdapter.
send
virtual
virtual ssize_t send(const char * data, size_t len, int flags = 0)Defined in src/net/include/icy/net/socketadapter.h:55
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.
Reimplemented by
ClientConnection::sendConnection::sendConnectionAdapter::sendConnectionStream::sendWebSocketAdapter::sendSSLSocket::sendTCPSocket::sendUDPSocket::send
send
virtual
virtual ssize_t send(const char * data, size_t len, const Address & peerAddress, int flags = 0)Defined in src/net/include/icy/net/socketadapter.h:56
Reimplemented by
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags = 0)Defined in src/net/include/icy/net/socketadapter.h:62
Sends an owned payload buffer to the connected peer.
The buffer is moved through the adapter chain and retained by the transport layer until async write completion.
Reimplemented by
Connection::sendOwnedConnectionAdapter::sendOwnedWebSocketAdapter::sendOwnedSSLSocket::sendOwnedTCPSocket::sendOwnedUDPSocket::sendOwnedSocket::sendOwned
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, const Address & peerAddress, int flags = 0)Defined in src/net/include/icy/net/socketadapter.h:63
Reimplemented by
Socket::sendOwnedWebSocketAdapter::sendOwnedSSLSocket::sendOwnedTCPSocket::sendOwnedUDPSocket::sendOwned
sendPacket
virtual
virtual ssize_t sendPacket(const IPacket & packet, int flags = 0)Defined in src/net/include/icy/net/socketadapter.h:70
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.
sendPacket
virtual
virtual ssize_t sendPacket(const IPacket & packet, const Address & peerAddress, int flags = 0)Defined in src/net/include/icy/net/socketadapter.h:71
sendPacket
virtual
virtual void sendPacket(IPacket & packet)Defined in src/net/include/icy/net/socketadapter.h:77
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.
setSender
virtual
virtual void setSender(SocketAdapter * adapter)Defined in src/net/include/icy/net/socketadapter.h:81
Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
sender
SocketAdapter * sender()Defined in src/net/include/icy/net/socketadapter.h:84
Returns the output SocketAdapter pointer.
addReceiver
virtual
virtual void addReceiver(SocketAdapter * adapter)Defined in src/net/include/icy/net/socketadapter.h:88
Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
Reimplemented by
removeReceiver
virtual
virtual void removeReceiver(SocketAdapter * adapter)Defined in src/net/include/icy/net/socketadapter.h:94
Remove the given receiver.
By default this function does nothing unless the given receiver matches the current receiver.
Reimplemented by
hasReceiver
virtual
virtual bool hasReceiver(SocketAdapter * adapter)Defined in src/net/include/icy/net/socketadapter.h:97
Returns true if the given receiver is connected.
receivers
std::vector< SocketAdapter * > receivers()Defined in src/net/include/icy/net/socketadapter.h:101
Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list.
onSocketConnect
virtual
virtual bool onSocketConnect(Socket & socket)Defined in src/net/include/icy/net/socketadapter.h:108
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.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
ClientConnection::onSocketConnectConnection::onSocketConnectWebSocketAdapter::onSocketConnectSocketEmitter::onSocketConnect
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | Socket & | The connected socket. |
onSocketRecv
virtual
virtual bool onSocketRecv(Socket & socket, const MutableBuffer & buffer, const Address & peerAddress)Defined in src/net/include/icy/net/socketadapter.h:116
Called when data is received from the socket. Forwards the event to all registered receivers in priority order.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
Connection::onSocketRecvConnectionAdapter::onSocketRecvConnectionStream::onSocketRecvWebSocketAdapter::onSocketRecvPacketSocketEmitter::onSocketRecvSocketEmitter::onSocketRecv
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | Socket & | The socket that received data. |
buffer | const MutableBuffer & | The received data buffer. |
peerAddress | const Address & | Address of the sender. |
onSocketError
virtual
virtual bool onSocketError(Socket & socket, const Error & error)Defined in src/net/include/icy/net/socketadapter.h:123
Called when the socket encounters an error. Forwards the event to all registered receivers in priority order.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | Socket & | The socket that encountered the error. |
error | const Error & | Error details. |
onSocketClose
virtual
virtual bool onSocketClose(Socket & socket)Defined in src/net/include/icy/net/socketadapter.h:129
Called when the socket is closed. Forwards the event to all registered receivers in priority order.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
Server::onSocketCloseConnection::onSocketCloseWebSocketAdapter::onSocketCloseSocketEmitter::onSocketClose
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | Socket & | The socket that was closed. |
Protected Attributes
| Return | Name | Description |
|---|---|---|
SocketAdapter * | _sender | |
std::vector< Ref > | _receivers | |
bool | _dirty | |
int | _dispatchDepth |
_sender
SocketAdapter * _senderType: SocketAdapter *
Defined in src/net/include/icy/net/socketadapter.h:156
_receivers
std::vector< Ref > _receiversType: std::vector< Ref >
Defined in src/net/include/icy/net/socketadapter.h:157
_dirty
bool _dirty = falseDefined in src/net/include/icy/net/socketadapter.h:158
_dispatchDepth
int _dispatchDepth = 0Defined in src/net/include/icy/net/socketadapter.h:159
Protected Methods
| Return | Name | Description |
|---|---|---|
void | cleanupReceivers virtual |
cleanupReceivers
virtual
virtual void cleanupReceivers()