Home
Net module

SocketAdapter

Abstract adapter interface for socket send/receive chains.

SocketAdapter

#include <icy/net/socketadapter.h>
class SocketAdapter

Defined 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

NameKindOwner
priorityvariableDeclared here
SocketAdapterfunctionDeclared here
~SocketAdapterfunctionDeclared here
sendfunctionDeclared here
sendfunctionDeclared here
sendOwnedfunctionDeclared here
sendOwnedfunctionDeclared here
sendPacketfunctionDeclared here
sendPacketfunctionDeclared here
sendPacketfunctionDeclared here
setSenderfunctionDeclared here
senderfunctionDeclared here
addReceiverfunctionDeclared here
removeReceiverfunctionDeclared here
hasReceiverfunctionDeclared here
receiversfunctionDeclared here
onSocketConnectfunctionDeclared here
onSocketRecvfunctionDeclared here
onSocketErrorfunctionDeclared here
onSocketClosefunctionDeclared here
_sendervariableDeclared here
_receiversvariableDeclared here
_dirtyvariableDeclared here
cleanupReceiversfunctionDeclared here

Public Attributes

ReturnNameDescription
intpriorityThe priority of this adapter for STL sort operations.

priority

int priority = 0

Defined in src/net/include/icy/net/socketadapter.h:132

The priority of this adapter for STL sort operations.

Public Methods

ReturnNameDescription
SocketAdapterCreates the SocketAdapter.
~SocketAdapter virtual noexceptDestroys the SocketAdapter.
ssize_tsend virtualSends 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_tsend virtual
ssize_tsendOwned virtualSends an owned payload buffer to the connected peer.
ssize_tsendOwned virtual
ssize_tsendPacket virtualSends 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_tsendPacket virtual
voidsendPacket virtualSends 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.
voidsetSender virtualSets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
SocketAdapter *senderReturns the output SocketAdapter pointer.
voidaddReceiver virtualSets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
voidremoveReceiver virtualRemove the given receiver.
boolhasReceiver virtualReturns true if the given receiver is connected.
std::vector< SocketAdapter * >receiversReturns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list.
boolonSocketConnect virtualCalled 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.
boolonSocketRecv virtualCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
boolonSocketError virtualCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
boolonSocketClose virtualCalled 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() noexcept

Defined 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

  • socket The 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

  • socket The socket that received data.

  • buffer The received data buffer.

  • peerAddress Address 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

  • socket The socket that encountered the error.

  • error Error 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

  • socket The socket that was closed.

Returns

true to stop propagation to subsequent receivers.

Reimplemented by

Protected Attributes

ReturnNameDescription
SocketAdapter *_sender
std::vector< Ref >_receivers
bool_dirty

_sender

SocketAdapter * _sender

Defined in src/net/include/icy/net/socketadapter.h:144


_receivers

std::vector< Ref > _receivers

Defined in src/net/include/icy/net/socketadapter.h:145


_dirty

bool _dirty = false

Defined in src/net/include/icy/net/socketadapter.h:146

Protected Methods

ReturnNameDescription
voidcleanupReceivers virtual

cleanupReceivers

virtual

virtual void cleanupReceivers()

Defined in src/net/include/icy/net/socketadapter.h:135