# net

<a id="net"></a>

# net

[Socket](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#socket-1) transports, adapters, and address helpers.

## Classes

| Name | Description |
|------|-------------|
| [`Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | Represents an IPv4 or IPv6 socket address with host and port. |
| [`PacketSocketEmitter`](https://auscaster.com/icey/docs/api-reference/icy-net-PacketSocketEmitter.md#packetsocketemitter) | [Socket](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#socket-1) adapter that emits received data as packets. |
| [`Socket`](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#socket-1) | Base socket implementation from which all sockets derive. |
| [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) | Abstract adapter interface for socket send/receive chains. |
| [`SocketEmitter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketEmitter.md#socketemitter) | [SocketAdapter](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) that exposes socket events as signals. |
| [`SocketPacket`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketPacket.md#socketpacket) | Default packet type emitted by sockets. |
| [`SSLAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLAdapter.md#ssladapter) | Manages the OpenSSL context and BIO buffers for an SSL socket connection. |
| [`SSLContext`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#sslcontext) | OpenSSL SSL_CTX wrapper for client and server TLS configuration. |
| [`SSLManager`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLManager.md#sslmanager) | [Singleton](https://auscaster.com/icey/docs/api-reference/icy-Singleton.md#singleton) that owns the default client/server TLS contexts and related callbacks. |
| [`SSLSession`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSession.md#sslsession) | Cached SSL/TLS session wrapper used for client-side resumption. |
| [`SSLSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sslsocket) | SSL socket implementation. |
| [`TCPSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#tcpsocket) | TCP socket implementation. |
| [`Transaction`](https://auscaster.com/icey/docs/api-reference/icy-net-Transaction.md#transaction) | Request/response helper for packet types emitted from a socket. |
| [`UDPSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#udpsocket) | UDP socket implementation. |
| [`VerificationErrorDetails`](https://auscaster.com/icey/docs/api-reference/icy-net-VerificationErrorDetails.md#verificationerrordetails) | A utility class for certificate error handling. |
| [`PacketInfo`](https://auscaster.com/icey/docs/api-reference/icy-net-PacketInfo.md#packetinfo) | Provides information about packets emitted from a socket. See [SocketPacket](https://auscaster.com/icey/docs/api-reference/icy-net-SocketPacket.md#socketpacket). |

## Enumerations

| Name | Description |
|------|-------------|
| [`TransportType`](#transporttype)  | Transport protocol identifier used to distinguish socket types at runtime. |
| [`SocketMode`](#socketmode)  | Transport mode for socket adapters and accepted connections. |

---

<a id="transporttype"></a>

### TransportType

```cpp
enum TransportType
```

[Defined in src/net/include/icy/net/net.h:93](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/net.h#L93)

Transport protocol identifier used to distinguish socket types at runtime.

| Value | Description |
|-------|-------------|
| `UDP` | Unreliable datagram protocol. |
| `TCP` | Reliable stream protocol. |
| `SSLTCP` | TLS-encrypted TCP stream. |

---

<a id="socketmode"></a>

### SocketMode

```cpp
enum SocketMode
```

[Defined in src/net/include/icy/net/net.h:102](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/net.h#L102)

Transport mode for socket adapters and accepted connections.

| Value | Description |
|-------|-------------|
| `ServerSide` | Server-side adapter. |
| `ClientSide` | Client-side adapter. |
## Functions

| Return | Name | Description |
|--------|------|-------------|
| `std::shared_ptr< SocketT >` | [`makeSocket`](#makesocket) `inline` | Creates a socket of type SocketT wrapped in a shared_ptr. |
| [`SSLContext::VerificationMode`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#verificationmode-1) | [`convertVerificationMode`](#convertverificationmode) `inline` | Non-case sensitive conversion of a string to a VerificationMode enum. If verMode is illegal an ArgumentException is thrown. |
| `std::string` | [`convertCertificateError`](#convertcertificateerror) `inline` | Converts an SSL certificate handling error code into an error message. |
| `std::string` | [`getLastError`](#getlasterror) `inline` | Returns the last error from the error stack. |
| `void` | [`clearErrorStack`](#clearerrorstack) `inline` | Clears the error stack. |
| `void` | [`getNetworkInterfaces`](#getnetworkinterfaces) `inline` | Populates `hosts` with all local network interface addresses. |
| `int` | [`getServerSocketSendBufSize`](#getserversocketsendbufsize)  | Returns the current send buffer size for a socket handle, in bytes. Passes val=0 to uv_send_buffer_size, which queries rather than sets the value. |
| `int` | [`getServerSocketRecvBufSize`](#getserversocketrecvbufsize)  | Returns the current receive buffer size for a socket handle, in bytes. Passes val=0 to uv_recv_buffer_size, which queries rather than sets the value. |
| `int` | [`setServerSocketSendBufSize`](#setserversocketsendbufsize)  | Sets the send buffer size for a socket handle. |
| `int` | [`setServerSocketRecvBufSize`](#setserversocketrecvbufsize)  | Sets the receive buffer size for a socket handle. |

---

<a id="makesocket"></a>

### makeSocket

`inline`

```cpp
template<class SocketT> inline std::shared_ptr< SocketT > makeSocket(uv::Loop * loop = uv::defaultLoop())
```

[Defined in src/net/include/icy/net/socket.h:41](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/socket.h#L41)

Creates a socket of type SocketT wrapped in a shared_ptr.

The socket is automatically destroyed when the last shared_ptr owner releases it. 
#### Returns
A shared_ptr owning the newly created socket.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `loop` | [`uv::Loop`](https://auscaster.com/icey/docs/api-reference/uv.md#loop-1) * | Event loop to associate with the socket; defaults to the default loop. |

---

<a id="convertverificationmode"></a>

### convertVerificationMode

`inline`

```cpp
inline SSLContext::VerificationMode convertVerificationMode(const std::string & vMode)
```

[Defined in src/net/include/icy/net/sslcontext.h:325](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslcontext.h#L325)

Non-case sensitive conversion of a string to a VerificationMode enum. If verMode is illegal an ArgumentException is thrown.

---

<a id="convertcertificateerror"></a>

### convertCertificateError

`inline`

```cpp
inline std::string convertCertificateError(long errCode)
```

[Defined in src/net/include/icy/net/sslcontext.h:345](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslcontext.h#L345)

Converts an SSL certificate handling error code into an error message.

---

<a id="getlasterror"></a>

### getLastError

`inline`

```cpp
inline std::string getLastError()
```

[Defined in src/net/include/icy/net/sslcontext.h:352](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslcontext.h#L352)

Returns the last error from the error stack.

---

<a id="clearerrorstack"></a>

### clearErrorStack

`inline`

```cpp
inline void clearErrorStack()
```

[Defined in src/net/include/icy/net/sslcontext.h:364](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslcontext.h#L364)

Clears the error stack.

---

<a id="getnetworkinterfaces"></a>

### getNetworkInterfaces

`inline`

```cpp
inline void getNetworkInterfaces(std::vector< net::Address > & hosts)
```

[Defined in src/net/include/icy/net/util.h:36](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/util.h#L36)

Populates `hosts` with all local network interface addresses.

Each entry is an IPv4 address constructed from the interface's address4 field. The results include loopback and any other active interfaces reported by libuv.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `hosts` | std::vector< [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) > & | Vector to append the discovered addresses to. |

---

<a id="getserversocketsendbufsize"></a>

### getServerSocketSendBufSize

```cpp
template<typename T> int getServerSocketSendBufSize(uv::Handle< T > & handle)
```

[Defined in src/net/include/icy/net/util.h:79](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/util.h#L79)

Returns the current send buffer size for a socket handle, in bytes. Passes val=0 to uv_send_buffer_size, which queries rather than sets the value. 
#### Returns
The send buffer size, or a libuv error code on failure.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `handle` | [`uv::Handle`](https://auscaster.com/icey/docs/api-reference/icy-uv-Handle.md#handle-6)< T > & | The socket handle to query. |

---

<a id="getserversocketrecvbufsize"></a>

### getServerSocketRecvBufSize

```cpp
template<typename T> int getServerSocketRecvBufSize(uv::Handle< T > & handle)
```

[Defined in src/net/include/icy/net/util.h:92](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/util.h#L92)

Returns the current receive buffer size for a socket handle, in bytes. Passes val=0 to uv_recv_buffer_size, which queries rather than sets the value. 
#### Returns
The receive buffer size, or a libuv error code on failure.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `handle` | [`uv::Handle`](https://auscaster.com/icey/docs/api-reference/icy-uv-Handle.md#handle-6)< T > & | The socket handle to query. |

---

<a id="setserversocketsendbufsize"></a>

### setServerSocketSendBufSize

```cpp
template<typename T> int setServerSocketSendBufSize(uv::Handle< T > & handle, int size)
```

[Defined in src/net/include/icy/net/util.h:105](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/util.h#L105)

Sets the send buffer size for a socket handle. 
#### Returns
0 on success, or a libuv error code on failure.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `handle` | [`uv::Handle`](https://auscaster.com/icey/docs/api-reference/icy-uv-Handle.md#handle-6)< T > & | The socket handle to configure. |
| `size` | `int` | The desired send buffer size in bytes. |

---

<a id="setserversocketrecvbufsize"></a>

### setServerSocketRecvBufSize

```cpp
template<typename T> int setServerSocketRecvBufSize(uv::Handle< T > & handle, int size)
```

[Defined in src/net/include/icy/net/util.h:117](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/util.h#L117)

Sets the receive buffer size for a socket handle. 
#### Returns
0 on success, or a libuv error code on failure.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `handle` | [`uv::Handle`](https://auscaster.com/icey/docs/api-reference/icy-uv-Handle.md#handle-6)< T > & | The socket handle to configure. |
| `size` | `int` | The desired receive buffer size in bytes. |

## Variables

| Return | Name | Description |
|--------|------|-------------|
| `constexpr int` | [`MAX_TCP_PACKET_SIZE`](#max_tcp_packet_size) `constexpr` | Maximum size of a single TCP receive buffer, in bytes. |
| `constexpr int` | [`MAX_UDP_PACKET_SIZE`](#max_udp_packet_size) `constexpr` | Maximum size of a single UDP datagram payload, in bytes. |

---

<a id="max_tcp_packet_size"></a>

### MAX_TCP_PACKET_SIZE

`constexpr`

```cpp
constexpr int MAX_TCP_PACKET_SIZE = 64 * 1024
```

[Defined in src/net/include/icy/net/net.h:86](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/net.h#L86)

Maximum size of a single TCP receive buffer, in bytes.

---

<a id="max_udp_packet_size"></a>

### MAX_UDP_PACKET_SIZE

`constexpr`

```cpp
constexpr int MAX_UDP_PACKET_SIZE = 1500
```

[Defined in src/net/include/icy/net/net.h:89](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/net.h#L89)

Maximum size of a single UDP datagram payload, in bytes.
