#include <tcp_socket.hpp>
template<IPEndpoint EndpointType>
class fly::net::TcpSocket< EndpointType >
Class to represent a connection-oriented streaming network socket.
- Author
- Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
- Version
- February 13, 2021
◆ TcpSocket() [1/3]
template<IPEndpoint EndpointType>
Constructor. Open the socket in a synchronous IO processing mode.
- Parameters
-
config | Reference to network configuration. |
◆ TcpSocket() [2/3]
template<IPEndpoint EndpointType>
Constructor. Open the socket in the provided IO processing mode.
- Parameters
-
config | Reference to network configuration. |
mode | IO processing mode to apply to the socket. |
◆ TcpSocket() [3/3]
template<IPEndpoint EndpointType>
Move constructor. The provided socket is left in a disconnected, invalid state.
- Parameters
-
socket | The socket instance to move. |
◆ close()
template<IPEndpoint EndpointType>
If this socket is valid, close this socket.
◆ connect() [1/2]
template<IPEndpoint EndpointType>
Connect to a remote socket. If this socket was opened in an asynchronous IO processing mode, the connection may not complete immediately. In that case, the connection must be completed via finish_connect() after the socket becomes writable.
- Parameters
-
endpoint | The remote endpoint to connect to. |
- Returns
- The connection state (disconnected, connecting, or connected).
◆ connect() [2/2]
template<IPEndpoint EndpointType>
ConnectedState fly::net::TcpSocket< EndpointType >::connect |
( |
std::string_view |
hostname, |
|
|
port_type |
port |
|
) |
| |
Connect to a remote socket. If this socket was opened in an asynchronous IO processing mode, the connection may not complete immediately. In that case, the connection must be completed via finish_connect() after the socket becomes writable.
- Parameters
-
hostname | The hostname or IP address string to connect to. |
port | The port to connect to. |
- Returns
- The connection state (disconnected, connecting, or connected).
◆ connect_async() [1/2]
template<IPEndpoint EndpointType>
ConnectedState fly::net::TcpSocket< EndpointType >::connect_async |
( |
const EndpointType & |
endpoint, |
|
|
ConnectCompletion && |
callback |
|
) |
| |
Asynchronously connect to a remote socket. May only be used if this socket was created through a socket service.
A connection attempt will be made immediately. If successful, the provided callback will not invoked; rather, the appropriate connection state will be returned.
If the immediate attempt fails because the operation would have blocked, the attempt will be completed asynchronously later. The provided callback will be invoked upon completion with the new connection state.
- Parameters
-
endpoint | The remote endpoint to connect to. |
callback | The callback to invoke if the operation completes asynchronously. |
- Returns
- The connection state (disconnected, connecting, or connected).
◆ connect_async() [2/2]
template<IPEndpoint EndpointType>
ConnectedState fly::net::TcpSocket< EndpointType >::connect_async |
( |
std::string_view |
hostname, |
|
|
port_type |
port, |
|
|
ConnectCompletion && |
callback |
|
) |
| |
Asynchronously connect to a remote socket. May only be used if this socket was created through a socket service.
A connection attempt will be made immediately. If successful, the provided callback will not invoked; rather, the appropriate connection state will be returned.
If the immediate attempt fails because the operation would have blocked, the attempt will be completed asynchronously later. The provided callback will be invoked upon completion with the new connection state.
- Parameters
-
hostname | The hostname or IP address string to connect to. |
port | The port to connect to. |
callback | The callback to invoke if the operation completes asynchronously. |
- Returns
- The connection state (disconnected, connecting, or connected).
◆ finish_connect()
template<IPEndpoint EndpointType>
After an asynchronous socket in a connecting state becomes available for writing, verify the socket is healthy and update its state as connected.
- Returns
- The connection state (disconnected or connected).
◆ handle()
template<IPEndpoint EndpointType>
- Returns
- This socket's native handle.
◆ hostname_to_address()
template<IPEndpoint EndpointType>
Convert a hostname or IP address string to an IP address.
- Parameters
-
hostname | The hostname or IP address string to convert. |
- Returns
- If successful, the created IP address. Otherwise, an uninitialized value.
◆ is_connected()
template<IPEndpoint EndpointType>
- Returns
- True if this socket is connected to a remote endpoint.
◆ is_connecting()
template<IPEndpoint EndpointType>
- Returns
- True if this socket is connecting to a remote endpoint.
◆ is_open()
template<IPEndpoint EndpointType>
- Returns
- True if the socket handle is opened.
◆ operator=()
template<IPEndpoint EndpointType>
Move assignment operator. The provided socket is left in a disconnected, invalid state.
- Parameters
-
socket | The socket instance to move. |
- Returns
- A reference to this socket.
◆ receive()
template<IPEndpoint EndpointType>
Receive a message from the connected remote socket. If an error occurs on the socket, the socket will be closed.
- Returns
- The message received.
◆ receive_async()
template<IPEndpoint EndpointType>
Asynchronously receive a message from the connected remote socket. May only be used if this socket was created through a socket service.
Upon completion, the provided callback will be invoked with the message received. If an error occurs on the socket, the callback will still be invoked with any message partially received, but the socket will also be closed before the invocation.
- Parameters
-
callback | The callback to invoke when the operation has completed. |
- Returns
- True if the socket service and the provided callback are valid.
◆ remote_endpoint()
template<IPEndpoint EndpointType>
Retrieve the remote endpoint to which this socket is connected.
- Returns
- If successful, the connected endpoint. Otherwise, an uninitialized value.
◆ send()
template<IPEndpoint EndpointType>
Transmit a message to the connected remote socket. If an error occurs on the socket, the socket will be closed.
- Parameters
-
message | The message to transmit. |
- Returns
- The number of bytes transmitted.
◆ send_async()
template<IPEndpoint EndpointType>
bool fly::net::TcpSocket< EndpointType >::send_async |
( |
std::string_view |
message, |
|
|
SendCompletion && |
callback |
|
) |
| |
Asynchronously transmit a message to the connected remote socket. May only be used if this socket was created through a socket service.
Upon completion, the provided callback will be invoked with the number of bytes that were transmitted. If an error occurs on the socket, the callback will still be invoked with the number of bytes successfully transmitted, but the socket will also be closed before the invocation.
- Parameters
-
message | The message to transmit. |
callback | The callback to invoke when the operation has completed. |
- Returns
- True if the socket service and the provided callback are valid.
The documentation for this class was generated from the following files: