#include <icy/net/socketemitter.h>Inherits:
SocketAdapterSubclassed 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.
| Return | Name | Description |
|---|---|---|
LocalSignal< bool(Socket &)> | Connect | Signals that the socket is connected. |
LocalSignal< bool(Socket &, const MutableBuffer &, const Address &)> | Recv | Signals when data is received by the socket. |
LocalSignal< bool(Socket &, const icy::Error &)> | Error | Signals that the socket is closed in error. This signal will be sent just before the Closed signal. |
LocalSignal< bool(Socket &)> | Close | Signals that the underlying socket is closed. |
Socket::Ptr | impl | Pointer to the underlying socket. Sent data will be proxied to this socket. |
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::Ptr implPointer to the underlying socket. Sent data will be proxied to this socket.
| Return | Name | Description |
|---|---|---|
SocketEmitter | Creates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver. | |
SocketEmitter | Copy constructor; copies all signal connections and attaches to the same socket. | |
~SocketEmitter virtual | Destroys the SocketAdapter. | |
void | addReceiver virtual | Attaches a SocketAdapter as a receiver; wires it to all four socket signals. |
void | removeReceiver virtual | Detaches a SocketAdapter from all four socket signals. |
void | swap virtual | Replaces the underlying socket with socket. |
T * | as inline | Returns the underlying socket cast to type T, or nullptr if the cast fails. |
Socket * | operator-> const inline | Returns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer. |
SocketEmitter(const Socket::Ptr & socket)Creates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver.
socket Optional socket to attach to; pass nullptr to attach later via swap().SocketEmitter(const SocketEmitter & that)Copy constructor; copies all signal connections and attaches to the same socket.
that The SocketEmitter to copy from.virtual
virtual ~SocketEmitter() noexceptDestroys the SocketAdapter.
virtual
virtual void addReceiver(SocketAdapter * adapter)Attaches a SocketAdapter as a receiver; wires it to all four socket signals.
adapter The adapter to attach; its priority determines signal ordering.virtual
virtual void removeReceiver(SocketAdapter * adapter)Detaches a SocketAdapter from all four socket signals.
adapter The adapter to detach.virtual
virtual void swap(const Socket::Ptr & socket)Replaces the underlying socket with socket.
Throws std::logic_error if the emitter already has an attached socket.
socket The new socket to attach.inline
template<class T> inline T * as()Returns the underlying socket cast to type T, or nullptr if the cast fails.
T Derived socket type to cast to.Pointer to the socket as T, or nullptr on type mismatch.
const inline
inline Socket * operator->() constReturns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer.
Raw pointer to the socket (never null if a socket was attached).
| Return | Name | Description |
|---|---|---|
bool | onSocketConnect virtual | Forwards the connect event to chained adapters, then fires the Connect signal. |
bool | onSocketRecv virtual | Forwards the recv event to chained adapters, then fires the Recv signal. |
bool | onSocketError virtual | Forwards the error event to chained adapters, then fires the Error signal. |
bool | onSocketClose virtual | Forwards the close event to chained adapters, then fires the Close signal. |
virtual
virtual bool onSocketConnect(Socket & socket)Forwards the connect event to chained adapters, then fires the Connect signal.
virtual
virtual bool onSocketRecv(Socket & socket, const MutableBuffer & buffer, const Address & peerAddress)Forwards the recv event to chained adapters, then fires the Recv signal.
virtual
virtual bool onSocketError(Socket & socket, const icy::Error & error)Forwards the error event to chained adapters, then fires the Error signal.
virtual
virtual bool onSocketClose(Socket & socket)Forwards the close event to chained adapters, then fires the Close signal.