32#ifndef ASYNC_TCP_CONNECTION_INCLUDED
33#define ASYNC_TCP_CONNECTION_INCLUDED
42#include <sigc++/sigc++.h>
163 uint16_t remote_port,
197 virtual int write(
const void *buf,
int count);
227 bool isIdle(
void)
const {
return sock == -1; }
329 uint16_t remote_port;
337 void recvHandler(
FdWatch *watch);
338 void writeHandler(
FdWatch *watch);
Platform independent representation of an IP address.
A class for watching file descriptors.
A class for representing an IP address in an OS independent way.
A base class for creating a TCP client connection.
A class for handling exiting TCP connections.
static const char * disconnectReasonStr(DisconnectReason reason)
Translate disconnect reason to a string.
virtual void disconnect(void)
Disconnect from the remote host.
bool isIdle(void) const
Check if the connection is idle.
const IpAddress & remoteHost(void) const
Return the IP-address of the remote host.
uint16_t remotePort(void) const
Return the remote port used.
static const int DEFAULT_RECV_BUF_LEN
The default length of the reception buffer.
DisconnectReason
Reason code for disconnects.
@ DR_HOST_NOT_FOUND
The specified host was not found in the DNS.
@ DR_SYSTEM_ERROR
A system error occured (check errno)
@ DR_PROTOCOL_ERROR
Protocol error.
@ DR_REMOTE_DISCONNECTED
The remote host disconnected.
@ DR_RECV_BUFFER_OVERFLOW
Receiver buffer overflow.
@ DR_ORDERED_DISCONNECT
Disconnect ordered locally.
virtual ~TcpConnection(void)
Destructor.
virtual void onDisconnected(DisconnectReason reason)
Called when a connection has been terminated.
void setSocket(int sock)
Setup information about the connection.
int socket(void) const
Return the socket file descriptor.
virtual int onDataReceived(void *buf, int count)
Called when data has been received on the connection.
sigc::signal< int, TcpConnection *, void *, int > dataReceived
A signal that is emitted when data has been received on the connection.
void setRecvBufLen(size_t recv_buf_len)
Set a new receive buffer size.
TcpConnection(int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
sigc::signal< void, bool > sendBufferFull
A signal that is emitted when the send buffer status changes.
void setRemotePort(uint16_t remote_port)
Setup information about the connection.
virtual int write(const void *buf, int count)
Write data to the TCP connection.
bool isConnected(void) const
Check if the connection is established or not.
TcpConnection(size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
sigc::signal< void, TcpConnection *, DisconnectReason > disconnected
A signal that is emitted when a connection has been terminated.
void setRemoteAddr(const IpAddress &remote_addr)
Setup information about the connection.
Namespace for the asynchronous programming classes.