Home
Net module

Socket

Base socket implementation from which all sockets derive.

Socket

#include <icy/net/socket.h>
class Socket

Defined in src/net/include/icy/net/socket.h:49

Inherits: SocketAdapter Subclassed by: TCPSocket, UDPSocket

Base socket implementation from which all sockets derive.

List of all members

NameKindOwner
opaquevariableDeclared here
SocketfunctionDeclared here
~SocketfunctionDeclared here
SocketfunctionDeclared here
operator=functionDeclared here
SocketfunctionDeclared here
operator=functionDeclared here
connectfunctionDeclared here
connectfunctionDeclared here
bindfunctionDeclared here
listenfunctionDeclared here
shutdownfunctionDeclared here
sendOwnedfunctionDeclared here
sendOwnedfunctionDeclared here
closefunctionDeclared here
addressfunctionDeclared here
peerAddressfunctionDeclared here
transportfunctionDeclared here
setErrorfunctionDeclared here
errorfunctionDeclared here
closedfunctionDeclared here
loopfunctionDeclared here
_afvariableDeclared here
initfunctionDeclared here
resetfunctionDeclared here
PtrtypedefDeclared here
VectypedefDeclared 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
std::anyopaqueOptional client data.

opaque

std::any opaque

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

Optional client data.

The value is empty on initialization.

Public Methods

ReturnNameDescription
SocketDefaulted constructor.
SocketDeleted constructor.
SocketDeleted constructor.
voidconnect virtualConnects to the given peer IP address.
voidconnect virtualResolves and connects to the given host address.
voidbind virtualBind a local address to the socket. The address may be IPv4 or IPv6 (if supported).
voidlisten virtual inlineListens the socket on the given address.
boolshutdown virtual inlineSends the shutdown packet which should result is socket closure via callback.
ssize_tsendOwned virtualSends an owned payload buffer to the connected peer.
ssize_tsendOwned virtual
voidclose virtualCloses the underlying socket.
Addressaddress virtual constThe locally bound address.
AddresspeerAddress virtual constThe connected peer address.
net::TransportTypetransport virtual constThe transport protocol: TCP, UDP or SSLTCP.
voidsetError virtualSets the socket error.
const icy::Error &error virtual constReturn the socket error if any.
boolclosed virtual constReturns true if the native socket handle is closed.
uv::Loop *loop virtual constReturns the socket event loop.

Socket

Socket() = default

Defined in src/net/include/icy/net/socket.h:55

Defaulted constructor.


Socket

Socket(const Socket &) = delete

Defined in src/net/include/icy/net/socket.h:58

Deleted constructor.


Socket

Socket(Socket &&) = delete

Defined in src/net/include/icy/net/socket.h:60

Deleted constructor.


connect

virtual

virtual void connect(const Address & address)

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

Connects to the given peer IP address.

Throws an exception if the address is malformed. Connection errors can be handled via the Error signal.

Reimplemented by

connect

virtual

virtual void connect(std::string_view host, uint16_t port)

Defined in src/net/include/icy/net/socket.h:74

Resolves and connects to the given host address.

Throws an Exception if the host is malformed. Since the DNS callback is asynchronous implementations need to listen for the Error signal for handling connection errors.

Reimplemented by

bind

virtual

virtual void bind(const Address & address, unsigned flags = 0)

Defined in src/net/include/icy/net/socket.h:80

Bind a local address to the socket. The address may be IPv4 or IPv6 (if supported).

Throws an Exception on error.

Reimplemented by

listen

virtual inline

virtual inline void listen(int backlog = 64)

Defined in src/net/include/icy/net/socket.h:85

Listens the socket on the given address.

Throws an Exception on error.

Reimplemented by

shutdown

virtual inline

virtual inline bool shutdown()

Defined in src/net/include/icy/net/socket.h:89

Sends the shutdown packet which should result is socket closure via callback.

Reimplemented by

sendOwned

virtual

virtual ssize_t sendOwned(Buffer && buffer, int flags = 0)

Defined in src/net/include/icy/net/socket.h:95

Sends an owned payload buffer to the connected peer.

Reimplements
Reimplemented by

sendOwned

virtual

virtual ssize_t sendOwned(Buffer && buffer, const Address & peerAddress, int flags = 0)

Defined in src/net/include/icy/net/socket.h:96

Reimplements
Reimplemented by

close

virtual

virtual void close()

Defined in src/net/include/icy/net/socket.h:99

Closes the underlying socket.

Reimplemented by

address

virtual const

virtual Address address() const

Defined in src/net/include/icy/net/socket.h:106

The locally bound address.

This function will not throw. A Wildcard 0.0.0.0:0 address is returned if the socket is closed or invalid.

Reimplemented by

peerAddress

virtual const

virtual Address peerAddress() const

Defined in src/net/include/icy/net/socket.h:113

The connected peer address.

This function will not throw. A Wildcard 0.0.0.0:0 address is returned if the socket is closed or invalid.

Reimplemented by

transport

virtual const

virtual net::TransportType transport() const

Defined in src/net/include/icy/net/socket.h:116

The transport protocol: TCP, UDP or SSLTCP.

Reimplemented by

setError

virtual

virtual void setError(const icy::Error & err)

Defined in src/net/include/icy/net/socket.h:121

Sets the socket error.

Setting the error will result in socket closure.

Reimplemented by

error

virtual const

virtual const icy::Error & error() const

Defined in src/net/include/icy/net/socket.h:124

Return the socket error if any.

Reimplemented by

closed

virtual const

virtual bool closed() const

Defined in src/net/include/icy/net/socket.h:127

Returns true if the native socket handle is closed.

Reimplemented by

loop

virtual const

virtual uv::Loop * loop() const

Defined in src/net/include/icy/net/socket.h:130

Returns the socket event loop.

Reimplemented by

Protected Attributes

ReturnNameDescription
int_af

_af

int _af {AF_UNSPEC}

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

Protected Methods

ReturnNameDescription
voidinit virtualInitializes the underlying socket context.
voidreset virtualResets the socket context for reuse.

init

virtual

virtual void init()

Defined in src/net/include/icy/net/socket.h:139

Initializes the underlying socket context.

Reimplemented by

reset

virtual

virtual void reset()

Defined in src/net/include/icy/net/socket.h:142

Resets the socket context for reuse.

Reimplemented by

Public Types

NameDescription
Ptr
Vec

Ptr

using Ptr = std::shared_ptr< Socket >

Defined in src/net/include/icy/net/socket.h:52


Vec

using Vec = std::vector< Ptr >

Defined in src/net/include/icy/net/socket.h:53