TCP listener (server) to accept a TcpClient.
More...
#include <tcp_listener.h>
|
| TcpListener (uint16_t port) |
| Constructor to listen on any IP address. More...
|
|
| TcpListener (std::string ipAddress, uint16_t port) |
| Constructor. More...
|
|
int | Connection () const noexcept override |
| Connection descriptor for sending and receiving. More...
|
|
bool | TrySetup () noexcept override |
| Try to setup the communicator. More...
|
|
bool | TryAccept () noexcept |
| Try to accept a client to form a connection. More...
|
|
template<std::size_t N> |
ssize_t | Send (const std::array< uint8_t, N > &buffer) const noexcept |
| Send a byte array to the connected client. More...
|
|
template<std::size_t N> |
ssize_t | Receive (std::array< uint8_t, N > &buffer) const noexcept |
| Receive a byte array from the connected client. More...
|
|
bool | TryMakeConnectionNonblock () noexcept |
| Try to make the current connection (if exists) non-block. More...
|
|
int | Descriptor () const noexcept |
| File descriptor. More...
|
|
virtual bool | TryClose () noexcept |
| Try to close the communicator. More...
|
|
|
| NetworkSocket (std::string ipAddress, uint16_t port) |
| Constructor. More...
|
|
const std::string | IpAddress |
| Listening/Connecting IP address for server/client.
|
|
const uint16_t | Port |
| Listening/Connecting port number for server/client.
|
|
int | FileDescriptor |
| File descriptor.
|
|
TCP listener (server) to accept a TcpClient.
- See also
- TcpClient
◆ TcpListener() [1/2]
AsyncBsdSocketLib::TcpListener::TcpListener |
( |
uint16_t |
port | ) |
|
Constructor to listen on any IP address.
- Parameters
-
◆ TcpListener() [2/2]
AsyncBsdSocketLib::TcpListener::TcpListener |
( |
std::string |
ipAddress, |
|
|
uint16_t |
port |
|
) |
| |
Constructor.
- Parameters
-
ipAddress | Listen IP address |
port | Listen port number |
◆ Connection()
int AsyncBsdSocketLib::TcpListener::Connection |
( |
| ) |
const |
|
overridevirtualnoexcept |
Connection descriptor for sending and receiving.
- Returns
- A non-negative value if there is a valid connection; otherwise -1
Implements AsyncBsdSocketLib::Communicator.
◆ Receive()
template<std::size_t N>
ssize_t AsyncBsdSocketLib::TcpListener::Receive |
( |
std::array< uint8_t, N > & |
buffer | ) |
const |
|
inlinenoexcept |
Receive a byte array from the connected client.
- Template Parameters
-
- Parameters
-
buffer | Receive buffer byte array |
- Returns
- Size of received bytes (-1 in case of receiving failed)
- Warning
- Due to edge-triggered polling, starvation can occur
◆ Send()
template<std::size_t N>
ssize_t AsyncBsdSocketLib::TcpListener::Send |
( |
const std::array< uint8_t, N > & |
buffer | ) |
const |
|
inlinenoexcept |
Send a byte array to the connected client.
- Template Parameters
-
- Parameters
-
buffer | Send buffer byte array |
- Returns
- Size of sent bytes (-1 in case of sending failed)
◆ TryAccept()
bool AsyncBsdSocketLib::TcpListener::TryAccept |
( |
| ) |
|
|
noexcept |
Try to accept a client to form a connection.
- Returns
- True if the client is successfully accepted; otherwise false
◆ TryMakeConnectionNonblock()
bool AsyncBsdSocketLib::TcpListener::TryMakeConnectionNonblock |
( |
| ) |
|
|
noexcept |
Try to make the current connection (if exists) non-block.
- Returns
- True if the non-blocking flag is set successfully; otherwise false
◆ TrySetup()
bool AsyncBsdSocketLib::TcpListener::TrySetup |
( |
| ) |
|
|
overridevirtualnoexcept |