SocketAdapter
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
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).
List of all members
| Name | Kind | Owner |
|---|---|---|
priority | variable | Declared here |
SocketAdapter | function | Declared here |
~SocketAdapter | function | Declared here |
send | function | Declared here |
send | function | Declared here |
sendOwned | function | Declared here |
sendOwned | function | Declared here |
sendPacket | function | Declared here |
sendPacket | function | Declared here |
sendPacket | function | Declared here |
setSender | function | Declared here |
sender | function | Declared here |
addReceiver | function | Declared here |
removeReceiver | function | Declared here |
hasReceiver | function | Declared here |
receivers | function | Declared here |
onSocketConnect | function | Declared here |
onSocketRecv | function | Declared here |
onSocketError | function | Declared here |
onSocketClose | function | Declared here |
_sender | variable | Declared here |
_receivers | variable | Declared here |
_dirty | variable | Declared here |
cleanupReceivers | function | Declared here |
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
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
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
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.
Parameters
socketThe connected socket.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
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.
Parameters
socketThe socket that received data.bufferThe received data buffer.peerAddressAddress of the sender.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
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.
Parameters
socketThe socket that encountered the error.errorError details.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
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.
Parameters
socketThe socket that was closed.
Returns
true to stop propagation to subsequent receivers.
Reimplemented by
Protected Attributes
| Return | Name | Description |
|---|---|---|
SocketAdapter * | _sender | |
std::vector< Ref > | _receivers | |
bool | _dirty |
_sender
SocketAdapter * _senderDefined in src/net/include/icy/net/socketadapter.h:144
_receivers
std::vector< Ref > _receiversDefined in src/net/include/icy/net/socketadapter.h:145
_dirty
bool _dirty = falseDefined in src/net/include/icy/net/socketadapter.h:146
Protected Methods
| Return | Name | Description |
|---|---|---|
void | cleanupReceivers virtual |
cleanupReceivers
virtual
virtual void cleanupReceivers()