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