Home
Net module

SocketEmitter

SocketAdapter that exposes socket events as signals.

SocketEmitter

#include <icy/net/socketemitter.h>
class SocketEmitter

Defined in src/net/include/icy/net/socketemitter.h:32

Inherits: SocketAdapter Subclassed by: WebSocketAdapter, PacketSocketEmitter

SocketAdapter that exposes socket events as signals.

Aside from adding a signal interface, the class wraps the underlying socket instance and is designed to be used much like a std::unique_ptr by overriding the -> operator.

List of all members

NameKindOwner
ConnectvariableDeclared here
RecvvariableDeclared here
ErrorvariableDeclared here
ClosevariableDeclared here
implvariableDeclared here
SocketEmitterfunctionDeclared here
SocketEmitterfunctionDeclared here
~SocketEmitterfunctionDeclared here
addReceiverfunctionDeclared here
removeReceiverfunctionDeclared here
swapfunctionDeclared here
asfunctionDeclared here
operator->functionDeclared here
onSocketConnectfunctionDeclared here
onSocketRecvfunctionDeclared here
onSocketErrorfunctionDeclared here
onSocketClosefunctionDeclared here
priorityvariableInherited from SocketAdapter
SocketAdapterfunctionInherited from SocketAdapter
~SocketAdapterfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
setSenderfunctionInherited from SocketAdapter
senderfunctionInherited from SocketAdapter
addReceiverfunctionInherited from SocketAdapter
removeReceiverfunctionInherited from SocketAdapter
hasReceiverfunctionInherited from SocketAdapter
receiversfunctionInherited from SocketAdapter
onSocketConnectfunctionInherited from SocketAdapter
onSocketRecvfunctionInherited from SocketAdapter
onSocketErrorfunctionInherited from SocketAdapter
onSocketClosefunctionInherited from SocketAdapter
_sendervariableInherited from SocketAdapter
_receiversvariableInherited from SocketAdapter
_dirtyvariableInherited from SocketAdapter
cleanupReceiversfunctionInherited from SocketAdapter

Inherited from SocketAdapter

KindNameDescription
variablepriorityThe priority of this adapter for STL sort operations.
functionSocketAdapterCreates the SocketAdapter.
function~SocketAdapter virtual noexceptDestroys the SocketAdapter.
functionsend 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.
functionsend virtual
functionsendOwned virtualSends an owned payload buffer to the connected peer.
functionsendOwned virtual
functionsendPacket 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.
functionsendPacket virtual
functionsendPacket 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.
functionsetSender virtualSets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
functionsenderReturns the output SocketAdapter pointer.
functionaddReceiver virtualSets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
functionremoveReceiver virtualRemove the given receiver.
functionhasReceiver virtualReturns true if the given receiver is connected.
functionreceiversReturns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list.
functiononSocketConnect 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.
functiononSocketRecv virtualCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
functiononSocketError virtualCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
functiononSocketClose virtualCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
variable_sender
variable_receivers
variable_dirty
functioncleanupReceivers virtual

Public Attributes

ReturnNameDescription
LocalSignal< bool(Socket &)>ConnectSignals that the socket is connected.
LocalSignal< bool(Socket &, const MutableBuffer &, const Address &)>RecvSignals when data is received by the socket.
LocalSignal< bool(Socket &, const icy::Error &)>ErrorSignals that the socket is closed in error. This signal will be sent just before the Closed signal.
LocalSignal< bool(Socket &)>CloseSignals that the underlying socket is closed.
Socket::PtrimplPointer to the underlying socket. Sent data will be proxied to this socket.

Connect

LocalSignal< bool(Socket &)> Connect

Defined in src/net/include/icy/net/socketemitter.h:48

Signals that the socket is connected.


Recv

LocalSignal< bool(Socket &, const MutableBuffer &, const Address &)> Recv

Defined in src/net/include/icy/net/socketemitter.h:51

Signals when data is received by the socket.


Error

LocalSignal< bool(Socket &, const icy::Error &)> Error

Defined in src/net/include/icy/net/socketemitter.h:56

Signals that the socket is closed in error. This signal will be sent just before the Closed signal.


Close

LocalSignal< bool(Socket &)> Close

Defined in src/net/include/icy/net/socketemitter.h:59

Signals that the underlying socket is closed.


impl

Socket::Ptr impl

Defined in src/net/include/icy/net/socketemitter.h:94

Pointer to the underlying socket. Sent data will be proxied to this socket.

Public Methods

ReturnNameDescription
SocketEmitterCreates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver.
SocketEmitterCopy constructor; copies all signal connections and attaches to the same socket.
~SocketEmitter virtual noexceptDestroys the SocketAdapter.
voidaddReceiver virtual overrideAttaches a SocketAdapter as a receiver; wires it to all four socket signals.
voidremoveReceiver virtual overrideDetaches a SocketAdapter from all four socket signals.
voidswap virtualReplaces the underlying socket with socket.
T *as inlineReturns the underlying socket cast to type T, or nullptr if the cast fails.
Socket *operator-> const inlineReturns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer.

SocketEmitter

SocketEmitter(const Socket::Ptr & socket = nullptr)

Defined in src/net/include/icy/net/socketemitter.h:38

Creates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver.

Parameters

  • socket Optional socket to attach to; pass nullptr to attach later via swap().

SocketEmitter

SocketEmitter(const SocketEmitter & that)

Defined in src/net/include/icy/net/socketemitter.h:42

Copy constructor; copies all signal connections and attaches to the same socket.

Parameters


~SocketEmitter

virtual noexcept

virtual ~SocketEmitter() noexcept

Defined in src/net/include/icy/net/socketemitter.h:45

Destroys the SocketAdapter.


addReceiver

virtual override

virtual void addReceiver(SocketAdapter * adapter) override

Defined in src/net/include/icy/net/socketemitter.h:63

Attaches a SocketAdapter as a receiver; wires it to all four socket signals.

Parameters

  • adapter The adapter to attach; its priority determines signal ordering.
Reimplements

removeReceiver

virtual override

virtual void removeReceiver(SocketAdapter * adapter) override

Defined in src/net/include/icy/net/socketemitter.h:67

Detaches a SocketAdapter from all four socket signals.

Parameters

  • adapter The adapter to detach.
Reimplements

swap

virtual

virtual void swap(const Socket::Ptr & socket)

Defined in src/net/include/icy/net/socketemitter.h:73

Replaces the underlying socket with socket.

Throws std::logic_error if the emitter already has an attached socket.

Parameters

  • socket The new socket to attach.

as

inline

template<class T> inline T * as()

Defined in src/net/include/icy/net/socketemitter.h:79

Returns the underlying socket cast to type T, or nullptr if the cast fails.

Parameters

  • T Derived socket type to cast to.

Returns

Pointer to the socket as T, or nullptr on type mismatch.


operator->

const inline

inline Socket * operator->() const

Defined in src/net/include/icy/net/socketemitter.h:87

Returns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer.

Returns

Raw pointer to the socket (never null if a socket was attached).

Protected Methods

ReturnNameDescription
boolonSocketConnect virtual overrideForwards the connect event to chained adapters, then fires the Connect signal.
boolonSocketRecv virtual overrideForwards the recv event to chained adapters, then fires the Recv signal.
boolonSocketError virtual overrideForwards the error event to chained adapters, then fires the Error signal.
boolonSocketClose virtual overrideForwards the close event to chained adapters, then fires the Close signal.

onSocketConnect

virtual override

virtual bool onSocketConnect(Socket & socket) override

Defined in src/net/include/icy/net/socketemitter.h:98

Forwards the connect event to chained adapters, then fires the Connect signal.

Reimplements
Reimplemented by

onSocketRecv

virtual override

virtual bool onSocketRecv(Socket & socket, const MutableBuffer & buffer, const Address & peerAddress) override

Defined in src/net/include/icy/net/socketemitter.h:100

Forwards the recv event to chained adapters, then fires the Recv signal.

Reimplements
Reimplemented by

onSocketError

virtual override

virtual bool onSocketError(Socket & socket, const icy::Error & error) override

Defined in src/net/include/icy/net/socketemitter.h:102

Forwards the error event to chained adapters, then fires the Error signal.

Reimplements

onSocketClose

virtual override

virtual bool onSocketClose(Socket & socket) override

Defined in src/net/include/icy/net/socketemitter.h:104

Forwards the close event to chained adapters, then fires the Close signal.

Reimplements
Reimplemented by