Net module

Socket

Base socket implementation from which all sockets derive.

Socket

#include <icy/net/socket.h>

Inherits: SocketAdapter Subclassed by: TCPSocket, UDPSocket

Base socket implementation from which all sockets derive.

Public Attributes

ReturnNameDescription
std::anyopaqueOptional client data.

opaque

std::any opaque

Optional client data.

The value is empty on initialization.

Public Methods

ReturnNameDescription
SocketDefaulted constructor.
SocketDeleted constructor.
SocketDeleted constructor.
voidconnectConnects to the given peer IP address.
voidconnectResolves and connects to the given host address.
voidbindBind 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_tsendOwnedSends an owned payload buffer to the connected peer.
ssize_tsendOwned
voidcloseCloses the underlying socket.
Addressaddress constThe locally bound address.
AddresspeerAddress constThe connected peer address.
net::TransportTypetransport constThe transport protocol: TCP, UDP or SSLTCP.
voidsetErrorSets the socket error.
const icy::Error &error constReturn the socket error if any.
boolclosed constReturns true if the native socket handle is closed.
uv::Loop *loop constReturns the socket event loop.

Socket

Socket() = default

Defaulted constructor.


Socket

Socket(const Socket &) = delete

Deleted constructor.


Socket

Socket(Socket &&) = delete

Deleted constructor.


connect

void connect(const Address & address)

Connects to the given peer IP address.

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


connect

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

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.


bind

void bind(const Address & address, unsigned flags)

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

Throws an Exception on error.


listen

virtual inline

virtual inline void listen(int backlog)

Listens the socket on the given address.

Throws an Exception on error.


shutdown

virtual inline

virtual inline bool shutdown()

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


sendOwned

ssize_t sendOwned(Buffer && buffer, int flags)

Sends an owned payload buffer to the connected peer.


sendOwned

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

close

void close()

Closes the underlying socket.


address

const

Address address() const

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.


peerAddress

const

Address peerAddress() const

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.


transport

const

net::TransportType transport() const

The transport protocol: TCP, UDP or SSLTCP.


setError

void setError(const icy::Error & err)

Sets the socket error.

Setting the error will result in socket closure.


error

const

const icy::Error & error() const

Return the socket error if any.


closed

const

bool closed() const

Returns true if the native socket handle is closed.


loop

const

uv::Loop * loop() const

Returns the socket event loop.

Protected Attributes

ReturnNameDescription
int_af

_af

int _af {AF_UNSPEC}

Protected Methods

ReturnNameDescription
voidinitInitializes the underlying socket context.
voidresetResets the socket context for reuse.

init

void init()

Initializes the underlying socket context.


reset

void reset()

Resets the socket context for reuse.

Public Types

NameDescription
Ptr
Vec

Ptr

std::shared_ptr< Socket > Ptr()

Vec

std::vector< Ptr > Vec()