Async
0.18.0
|
A class for handling exiting TCP connections. More...
#include <AsyncTcpConnection.h>
Public Types | |
enum | DisconnectReason { DR_HOST_NOT_FOUND, DR_REMOTE_DISCONNECTED, DR_SYSTEM_ERROR, DR_RECV_BUFFER_OVERFLOW, DR_ORDERED_DISCONNECT } |
Reason code for disconnects. More... | |
Public Member Functions | |
TcpConnection (size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
TcpConnection (int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
~TcpConnection (void) | |
Destructor. | |
void | disconnect (void) |
Disconnect from the remote host. | |
int | write (const void *buf, int count) |
Write data to the TCP connection. | |
const IpAddress & | remoteHost (void) const |
Return the IP-address of the remote host. | |
uint16_t | remotePort (void) const |
Return the remote port used. | |
bool | isConnected (void) const |
Check if the connection is established or not. | |
Static Public Member Functions | |
static const char * | disconnectReasonStr (DisconnectReason reason) |
Translate disconnect reason to a string. | |
Public Attributes | |
SigC::Signal2< void, TcpConnection *, DisconnectReason > | disconnected |
A signal that is emitted when a connection has been terminated. | |
SigC::Signal3< int, TcpConnection *, void *, int > | dataReceived |
A signal that is emitted when data has been received on the connection. | |
SigC::Signal1< void, bool > | sendBufferFull |
A signal that is emitted when the send buffer status changes. | |
Static Public Attributes | |
static const int | DEFAULT_RECV_BUF_LEN = 1024 |
The default length of the reception buffer. | |
Protected Member Functions | |
void | setSocket (int sock) |
Setup information about the connection. | |
void | setRemoteAddr (const IpAddress &remote_addr) |
Setup information about the connection. | |
void | setRemotePort (uint16_t remote_port) |
Setup information about the connection. | |
int | socket (void) const |
Return the socket file descriptor. | |
A class for handling exiting TCP connections.
This class is used to handle an existing TCP connection. It is not meant to be used directly but could be. It it mainly created to handle connections for Async::TcpClient and Async::TcpServer.
Definition at line 123 of file AsyncTcpConnection.h.
Reason code for disconnects.
Definition at line 129 of file AsyncTcpConnection.h.
|
explicit |
Constructor.
recv_buf_len | The length of the receiver buffer to use |
Async::TcpConnection::TcpConnection | ( | int | sock, |
const IpAddress & | remote_addr, | ||
uint16_t | remote_port, | ||
size_t | recv_buf_len = DEFAULT_RECV_BUF_LEN |
||
) |
Constructor.
sock | The socket for the connection to handle |
remote_addr | The remote IP-address of the connection |
remote_port | The remote TCP-port of the connection |
recv_buf_len | The length of the receiver buffer to use |
Async::TcpConnection::~TcpConnection | ( | void | ) |
Destructor.
void Async::TcpConnection::disconnect | ( | void | ) |
Disconnect from the remote host.
Call this function to disconnect from the remote host. If already disconnected, nothing will be done. The disconnected signal is not emitted when this function is called
|
static |
Translate disconnect reason to a string.
|
inline |
Check if the connection is established or not.
Definition at line 206 of file AsyncTcpConnection.h.
|
inline |
Return the IP-address of the remote host.
This function returns the IP-address of the remote host.
Definition at line 193 of file AsyncTcpConnection.h.
|
inline |
Return the remote port used.
Definition at line 199 of file AsyncTcpConnection.h.
|
protected |
Setup information about the connection.
remote_addr | The remote IP-address of the connection |
Use this function to set up the remote IP-address for the connection.
|
protected |
Setup information about the connection.
remote_port | The remote TCP-port of the connection |
Use this function to set up the remote port for the connection.
|
protected |
Setup information about the connection.
sock | The socket for the connection to handle |
Use this function to set up the socket for the connection.
|
inlineprotected |
Return the socket file descriptor.
Use this function to get the socket file descriptor that is currently in use. If it is -1 it has not been set.
Definition at line 271 of file AsyncTcpConnection.h.
int Async::TcpConnection::write | ( | const void * | buf, |
int | count | ||
) |
Write data to the TCP connection.
buf | The buffer containing the data to send |
count | The number of bytes to send from the buffer |
SigC::Signal3<int, TcpConnection *, void *, int> Async::TcpConnection::dataReceived |
A signal that is emitted when data has been received on the connection.
buf | A buffer containg the read data |
count | The number of bytes in the buffer |
This signal is emitted when data has been received on this connection. The buffer will contain the bytes read from the operating system. The slot must return the number of bytes that has been processed. The bytes not processed will be stored in the receive buffer for this class and presented again to the slot when more data arrives. The new data will be appended to the old data.
Definition at line 229 of file AsyncTcpConnection.h.
|
static |
The default length of the reception buffer.
Definition at line 141 of file AsyncTcpConnection.h.
SigC::Signal2<void, TcpConnection *, DisconnectReason> Async::TcpConnection::disconnected |
A signal that is emitted when a connection has been terminated.
con | The connection object |
reason | The reason for the disconnect |
Definition at line 213 of file AsyncTcpConnection.h.
SigC::Signal1<void, bool> Async::TcpConnection::sendBufferFull |
A signal that is emitted when the send buffer status changes.
is_full | Set to true if the buffer is full or false if a buffer full condition has been cleared |
Definition at line 236 of file AsyncTcpConnection.h.