SocketEmitter
#include <icy/net/socketemitter.h>
class SocketEmitterDefined in src/net/include/icy/net/socketemitter.h:32
- Inherits
SocketAdapter- Subclassed by
WebSocketAdapter,PacketSocketEmitter
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
| Name | Kind | Owner |
|---|---|---|
Connect | variable | Declared here |
Recv | variable | Declared here |
Error | variable | Declared here |
Close | variable | Declared here |
impl | variable | Declared here |
SocketEmitter | function | Declared here |
SocketEmitter | function | Declared here |
~SocketEmitter | function | Declared here |
addReceiver | function | Declared here |
removeReceiver | function | Declared here |
swap | function | Declared here |
as | function | Declared here |
operator-> | function | Declared here |
onSocketConnect | function | Declared here |
onSocketRecv | function | Declared here |
onSocketError | function | Declared here |
onSocketClose | function | Declared here |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
_dispatchDepth | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | 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. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | 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. |
function | sendPacket virtual | |
function | 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. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | 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. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
variable | _dispatchDepth | |
function | cleanupReceivers virtual |
Public Attributes
| 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. |
Connect
LocalSignal< bool(Socket &)> ConnectType: LocalSignal< bool(Socket &)>
Defined in src/net/include/icy/net/socketemitter.h:48
Signals that the socket is connected.
Recv
LocalSignal< bool(Socket &, const MutableBuffer &, const Address &)> RecvType: LocalSignal< bool(Socket &, const MutableBuffer &, const Address &)>
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 &)> ErrorType: LocalSignal< bool(Socket &, const icy::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 &)> CloseType: LocalSignal< bool(Socket &)>
Defined in src/net/include/icy/net/socketemitter.h:59
Signals that the underlying socket is closed.
impl
Socket::Ptr implType: Socket::Ptr
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
| 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 noexcept | Destroys the SocketAdapter. | |
void | addReceiver virtual override | Attaches a SocketAdapter as a receiver; wires it to all four socket signals. |
void | removeReceiver virtual override | 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
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
| Parameter | Type | Description |
|---|---|---|
socket | const Socket::Ptr & | 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
| Parameter | Type | Description |
|---|---|---|
that | const SocketEmitter & | The SocketEmitter to copy from. |
~SocketEmitter
virtual noexcept
virtual ~SocketEmitter() noexceptDefined in src/net/include/icy/net/socketemitter.h:45
Destroys the SocketAdapter.
addReceiver
virtual override
virtual void addReceiver(SocketAdapter * adapter) overrideDefined in src/net/include/icy/net/socketemitter.h:63
Attaches a SocketAdapter as a receiver; wires it to all four socket signals.
Reimplements
Parameters
| Parameter | Type | Description |
|---|---|---|
adapter | SocketAdapter * | The adapter to attach; its priority determines signal ordering. |
removeReceiver
virtual override
virtual void removeReceiver(SocketAdapter * adapter) overrideDefined in src/net/include/icy/net/socketemitter.h:67
Detaches a SocketAdapter from all four socket signals.
Reimplements
Parameters
| Parameter | Type | Description |
|---|---|---|
adapter | SocketAdapter * | The adapter to detach. |
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
| Parameter | Type | Description |
|---|---|---|
socket | const Socket::Ptr & | 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.
Returns
Pointer to the socket as T, or nullptr on type mismatch.
operator->
const inline
inline Socket * operator->() constDefined 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
| Return | Name | Description |
|---|---|---|
bool | onSocketConnect virtual override | Forwards the connect event to chained adapters, then fires the Connect signal. |
bool | onSocketRecv virtual override | Forwards the recv event to chained adapters, then fires the Recv signal. |
bool | onSocketError virtual override | Forwards the error event to chained adapters, then fires the Error signal. |
bool | onSocketClose virtual override | Forwards the close event to chained adapters, then fires the Close signal. |
onSocketConnect
virtual override
virtual bool onSocketConnect(Socket & socket) overrideDefined 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) overrideDefined 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) overrideDefined 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) overrideDefined in src/net/include/icy/net/socketemitter.h:104
Forwards the close event to chained adapters, then fires the Close signal.
