# Socket

<a id="socket-1"></a>

# Socket

```cpp
#include <icy/net/socket.h>

class Socket
```

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

> **Inherits:** [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter)
> **Subclassed by:** [`TCPSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#tcpsocket), [`UDPSocket`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#udpsocket)

Base socket implementation from which all sockets derive.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`opaque`](#opaque-2) | `variable` | Declared here |
| [`Socket`](#socket-2) | `function` | Declared here |
| [`~Socket`](#socket-3) | `function` | Declared here |
| [`Socket`](#socket-4) | `function` | Declared here |
| [`operator=`](#operator-178) | `function` | Declared here |
| [`Socket`](#socket-5) | `function` | Declared here |
| [`operator=`](#operator-179) | `function` | Declared here |
| [`connect`](#connect-2) | `function` | Declared here |
| [`connect`](#connect-3) | `function` | Declared here |
| [`bind`](#bind) | `function` | Declared here |
| [`listen`](#listen) | `function` | Declared here |
| [`shutdown`](#shutdown-3) | `function` | Declared here |
| [`sendOwned`](#sendowned) | `function` | Declared here |
| [`sendOwned`](#sendowned-1) | `function` | Declared here |
| [`close`](#close-19) | `function` | Declared here |
| [`address`](#address-8) | `function` | Declared here |
| [`peerAddress`](#peeraddress-1) | `function` | Declared here |
| [`transport`](#transport) | `function` | Declared here |
| [`setError`](#seterror-2) | `function` | Declared here |
| [`error`](#error-12) | `function` | Declared here |
| [`closed`](#closed-3) | `function` | Declared here |
| [`loop`](#loop-4) | `function` | Declared here |
| [`_af`](#_af) | `variable` | Declared here |
| [`init`](#init-10) | `function` | Declared here |
| [`reset`](#reset-13) | `function` | Declared here |
| [`Ptr`](#ptr-9) | `typedef` | Declared here |
| [`Vec`](#vec) | `typedef` | Declared here |
| [`priority`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#priority-3) | `variable` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter-1) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`~SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter-2) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`send`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#send-1) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`send`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#send-2) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendowned-2) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendowned-3) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`sendPacket`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendpacket) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`sendPacket`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendpacket-1) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`sendPacket`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendpacket-2) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`setSender`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#setsender) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`sender`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sender) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`addReceiver`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#addreceiver) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`removeReceiver`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#removereceiver) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`hasReceiver`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#hasreceiver) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`receivers`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#receivers) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`onSocketConnect`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketconnect) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`onSocketRecv`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketrecv-1) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`onSocketError`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketerror) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`onSocketClose`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketclose) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`_sender`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_sender) | `variable` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`_receivers`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_receivers) | `variable` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`_dirty`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_dirty) | `variable` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`_dispatchDepth`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_dispatchdepth) | `variable` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |
| [`cleanupReceivers`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#cleanupreceivers) | `function` | Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) |

## Inherited from [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter)

| Kind | Name | Description |
|------|------|-------------|
| `variable` | [`priority`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#priority-3)  | The priority of this adapter for STL sort operations. |
| `function` | [`SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter-1)  | Creates the [SocketAdapter](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter). |
| `function` | [`~SocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter-2) `virtual` `noexcept` | Destroys the [SocketAdapter](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter). |
| `function` | [`send`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#send-1) `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`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#send-2) `virtual` |  |
| `function` | [`sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendowned-2) `virtual` | Sends an owned payload buffer to the connected peer. |
| `function` | [`sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendowned-3) `virtual` |  |
| `function` | [`sendPacket`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#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`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendpacket-1) `virtual` |  |
| `function` | [`sendPacket`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendpacket-2) `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`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#setsender) `virtual` | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
| `function` | [`sender`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sender)  | Returns the output [SocketAdapter](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) pointer. |
| `function` | [`addReceiver`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#addreceiver) `virtual` | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
| `function` | [`removeReceiver`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#removereceiver) `virtual` | Remove the given receiver. |
| `function` | [`hasReceiver`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#hasreceiver) `virtual` | Returns true if the given receiver is connected. |
| `function` | [`receivers`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#receivers)  | Returns all currently registered input [SocketAdapter](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#socketadapter) pointers. Dead (removed) entries are excluded from the returned list. |
| `function` | [`onSocketConnect`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#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`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketrecv-1) `virtual` | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
| `function` | [`onSocketError`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketerror) `virtual` | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
| `function` | [`onSocketClose`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#onsocketclose) `virtual` | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
| `variable` | [`_sender`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_sender)  |  |
| `variable` | [`_receivers`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_receivers)  |  |
| `variable` | [`_dirty`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_dirty)  |  |
| `variable` | [`_dispatchDepth`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#_dispatchdepth)  |  |
| `function` | [`cleanupReceivers`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#cleanupreceivers) `virtual` |  |

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::any` | [`opaque`](#opaque-2)  | Optional client data. |

---

<a id="opaque-2"></a>

### opaque

```cpp
std::any opaque
```

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

Optional client data.

The value is empty on initialization.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Socket`](#socket-2)  | Defaulted constructor. |
|  | [`~Socket`](#socket-3) `virtual` `noexcept` | Defaulted destructor. |
|  | [`Socket`](#socket-4)  | Deleted constructor. |
| [`Socket`](#socket-1) & | [`operator=`](#operator-178)  | Deleted assignment operator. |
|  | [`Socket`](#socket-5)  | Deleted constructor. |
| [`Socket`](#socket-1) & | [`operator=`](#operator-179)  | Deleted assignment operator. |
| `void` | [`connect`](#connect-2) `virtual` | Connects to the given peer IP address. |
| `void` | [`connect`](#connect-3) `virtual` | Resolves and connects to the given host address. |
| `void` | [`bind`](#bind) `virtual` | Bind a local address to the socket. The address may be IPv4 or IPv6 (if supported). |
| `void` | [`listen`](#listen) `virtual` `inline` | Listens the socket on the given address. |
| `bool` | [`shutdown`](#shutdown-3) `virtual` `inline` | Sends the shutdown packet which should result is socket closure via callback. |
| `ssize_t` | [`sendOwned`](#sendowned) `virtual` | Sends an owned payload buffer to the connected peer. |
| `ssize_t` | [`sendOwned`](#sendowned-1) `virtual` |  |
| `void` | [`close`](#close-19) `virtual` | Closes the underlying socket. |
| [`Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | [`address`](#address-8) `virtual` `const` | The locally bound address. |
| [`Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | [`peerAddress`](#peeraddress-1) `virtual` `const` | The connected peer address. |
| [`net::TransportType`](https://auscaster.com/icey/docs/api-reference/icy-net.md#transporttype) | [`transport`](#transport) `virtual` `const` | The transport protocol: TCP, UDP or SSLTCP. |
| `void` | [`setError`](#seterror-2) `virtual` | Sets the socket error. |
| const [`icy::Error`](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error) & | [`error`](#error-12) `virtual` `const` | Return the socket error if any. |
| `bool` | [`closed`](#closed-3) `virtual` `const` | Returns true if the native socket handle is closed. |
| [`uv::Loop`](https://auscaster.com/icey/docs/api-reference/uv.md#loop-1) * | [`loop`](#loop-4) `virtual` `const` | Returns the socket event loop. |

---

<a id="socket-2"></a>

### Socket

```cpp
Socket() = default
```

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

Defaulted constructor.

---

<a id="socket-3"></a>

### ~Socket

`virtual` `noexcept`

```cpp
virtual ~Socket() noexcept = default
```

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

Defaulted destructor.

---

<a id="socket-4"></a>

### Socket

```cpp
Socket(const Socket &) = delete
```

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

Deleted constructor.

---

<a id="operator-178"></a>

### operator=

```cpp
Socket & operator=(const Socket &) = delete
```

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

Deleted assignment operator.

---

<a id="socket-5"></a>

### Socket

```cpp
Socket(Socket &&) = delete
```

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

Deleted constructor.

---

<a id="operator-179"></a>

### operator=

```cpp
Socket & operator=(Socket &&) = delete
```

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

Deleted assignment operator.

---

<a id="connect-2"></a>

### connect

`virtual`

```cpp
virtual void connect(const Address & address)
```

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

Connects to the given peer IP address.

Throws an exception if the address is malformed. Connection errors can be handled via the [Error](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error) signal.

#### Reimplemented by

- [`SSLSocket::connect`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#connect-5)
- [`TCPSocket::connect`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#connect-7)
- [`UDPSocket::connect`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#connect-9)

---

<a id="connect-3"></a>

### connect

`virtual`

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

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

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](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error) signal for handling connection errors.

#### Reimplemented by

- [`SSLSocket::connect`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#connect-6)
- [`TCPSocket::connect`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#connect-8)
- [`UDPSocket::connect`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#connect-10)

---

<a id="bind"></a>

### bind

`virtual`

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

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

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

Throws an Exception on error.

#### Reimplemented by

- [`SSLSocket::bind`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#bind-1)
- [`TCPSocket::bind`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#bind-2)
- [`UDPSocket::bind`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#bind-3)

---

<a id="listen"></a>

### listen

`virtual` `inline`

```cpp
virtual inline void listen(int backlog = 64)
```

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

Listens the socket on the given address.

Throws an Exception on error.

#### Reimplemented by

- [`SSLSocket::listen`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#listen-1)
- [`TCPSocket::listen`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#listen-2)

---

<a id="shutdown-3"></a>

### shutdown

`virtual` `inline`

```cpp
virtual inline bool shutdown()
```

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

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

#### Reimplemented by

- [`SSLSocket::shutdown`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#shutdown-6)
- [`TCPSocket::shutdown`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#shutdown-7)

---

<a id="sendowned"></a>

### sendOwned

`virtual`

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

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

Sends an owned payload buffer to the connected peer.

#### Reimplements

- [`SocketAdapter::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendowned-2)

#### Reimplemented by

- [`SSLSocket::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sendowned-4)
- [`TCPSocket::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#sendowned-6)
- [`UDPSocket::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#sendowned-8)

---

<a id="sendowned-1"></a>

### sendOwned

`virtual`

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

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

#### Reimplements

- [`SocketAdapter::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketAdapter.md#sendowned-3)

#### Reimplemented by

- [`SSLSocket::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#sendowned-5)
- [`TCPSocket::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#sendowned-7)
- [`UDPSocket::sendOwned`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#sendowned-9)

---

<a id="close-19"></a>

### close

`virtual`

```cpp
virtual void close()
```

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

Closes the underlying socket.

#### Reimplemented by

- [`SSLSocket::close`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#close-21)
- [`TCPSocket::close`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#close-22)
- [`UDPSocket::close`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#close-23)

---

<a id="address-8"></a>

### address

`virtual` `const`

```cpp
virtual Address address() const
```

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

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

- [`TCPSocket::address`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#address-9)
- [`UDPSocket::address`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#address-10)

---

<a id="peeraddress-1"></a>

### peerAddress

`virtual` `const`

```cpp
virtual Address peerAddress() const
```

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

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

- [`TCPSocket::peerAddress`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#peeraddress-2)
- [`UDPSocket::peerAddress`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#peeraddress-4)

---

<a id="transport"></a>

### transport

`virtual` `const`

```cpp
virtual net::TransportType transport() const
```

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

The transport protocol: TCP, UDP or SSLTCP.

#### Reimplemented by

- [`SSLSocket::transport`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLSocket.md#transport-1)
- [`TCPSocket::transport`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#transport-2)
- [`UDPSocket::transport`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#transport-3)

---

<a id="seterror-2"></a>

### setError

`virtual`

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

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

Sets the socket error.

Setting the error will result in socket closure.

#### Reimplemented by

- [`TCPSocket::setError`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#seterror-3)
- [`UDPSocket::setError`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#seterror-4)

---

<a id="error-12"></a>

### error

`virtual` `const`

```cpp
virtual const icy::Error & error() const
```

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

Return the socket error if any.

#### Reimplemented by

- [`TCPSocket::error`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#error-14)
- [`UDPSocket::error`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#error-15)

---

<a id="closed-3"></a>

### closed

`virtual` `const`

```cpp
virtual bool closed() const
```

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

Returns true if the native socket handle is closed.

#### Reimplemented by

- [`TCPSocket::closed`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#closed-4)
- [`UDPSocket::closed`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#closed-5)

---

<a id="loop-4"></a>

### loop

`virtual` `const`

```cpp
virtual uv::Loop * loop() const
```

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

Returns the socket event loop.

#### Reimplemented by

- [`TCPSocket::loop`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#loop-5)
- [`UDPSocket::loop`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#loop-6)

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `int` | [`_af`](#_af)  |  |

---

<a id="_af"></a>

### _af

```cpp
int _af {AF_UNSPEC}
```

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

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`init`](#init-10) `virtual` | Initializes the underlying socket context. |
| `void` | [`reset`](#reset-13) `virtual` | Resets the socket context for reuse. |

---

<a id="init-10"></a>

### init

`virtual`

```cpp
virtual void init()
```

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

Initializes the underlying socket context.

#### Reimplemented by

- [`TCPSocket::init`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#init-11)
- [`UDPSocket::init`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#init-12)

---

<a id="reset-13"></a>

### reset

`virtual`

```cpp
virtual void reset()
```

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

Resets the socket context for reuse.

#### Reimplemented by

- [`TCPSocket::reset`](https://auscaster.com/icey/docs/api-reference/icy-net-TCPSocket.md#reset-14)
- [`UDPSocket::reset`](https://auscaster.com/icey/docs/api-reference/icy-net-UDPSocket.md#reset-15)

## Public Types

| Name | Description |
|------|-------------|
| [`Ptr`](#ptr-9)  |  |
| [`Vec`](#vec)  |  |

---

<a id="ptr-9"></a>

### Ptr

```cpp
using Ptr = std::shared_ptr< Socket >
```

Type: std::shared_ptr< [`Socket`](#socket-1) >

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

---

<a id="vec"></a>

### Vec

```cpp
using Vec = std::vector< Ptr >
```

Type: std::vector< [`Ptr`](#ptr-9) >

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