#include <icy/net/socketadapter.h>Subclassed by:
Connection,ConnectionAdapter,ConnectionStream,Server,Socket,SocketEmitter
Abstract adapter interface for socket send/receive chains.
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).
| Return | Name | Description |
|---|---|---|
int | priority | The priority of this adapter for STL sort operations. |
int priority = 0The priority of this adapter for STL sort operations.
| Return | Name | Description |
|---|---|---|
SocketAdapter | Creates the SocketAdapter. | |
~SocketAdapter virtual | 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 * sender)Creates the SocketAdapter.
virtual
virtual ~SocketAdapter() noexceptDestroys the SocketAdapter.
virtual
virtual ssize_t send(const char * data, size_t len, int flags)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.
virtual
virtual ssize_t send(const char * data, size_t len, const Address & peerAddress, int flags)virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)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.
virtual
virtual ssize_t sendOwned(Buffer && buffer, const Address & peerAddress, int flags)virtual
virtual ssize_t sendPacket(const IPacket & packet, int flags)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.
virtual
virtual ssize_t sendPacket(const IPacket & packet, const Address & peerAddress, int flags)virtual
virtual void sendPacket(IPacket & packet)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.
virtual
virtual void setSender(SocketAdapter * adapter)Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
SocketAdapter * sender()Returns the output SocketAdapter pointer.
virtual
virtual void addReceiver(SocketAdapter * adapter)Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
virtual
virtual void removeReceiver(SocketAdapter * adapter)Remove the given receiver.
By default this function does nothing unless the given receiver matches the current receiver.
virtual
virtual bool hasReceiver(SocketAdapter * adapter)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.
virtual
virtual bool onSocketConnect(Socket & socket)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.
socket The connected socket.true to stop propagation to subsequent receivers.
virtual
virtual bool onSocketRecv(Socket & socket, const MutableBuffer & buffer, const Address & peerAddress)Called when data is received from the socket. Forwards the event to all registered receivers in priority order.
socket The socket that received data.
buffer The received data buffer.
peerAddress Address of the sender.
true to stop propagation to subsequent receivers.
virtual
virtual bool onSocketError(Socket & socket, const Error & error)Called when the socket encounters an error. Forwards the event to all registered receivers in priority order.
socket The socket that encountered the error.
error Error details.
true to stop propagation to subsequent receivers.
virtual
virtual bool onSocketClose(Socket & socket)Called when the socket is closed. Forwards the event to all registered receivers in priority order.
socket The socket that was closed.true to stop propagation to subsequent receivers.
| Return | Name | Description |
|---|---|---|
SocketAdapter * | _sender | |
std::vector< Ref > | _receivers | |
bool | _dirty |
SocketAdapter * _senderstd::vector< Ref > _receiversbool _dirty = false| Return | Name | Description |
|---|---|---|
void | cleanupReceivers virtual |
virtual
virtual void cleanupReceivers()