Go to the documentation of this file.
36 #ifndef ASYNC_FRAMED_TCP_CONNECTION_INCLUDED
37 #define ASYNC_FRAMED_TCP_CONNECTION_INCLUDED
131 class FramedTcpConnection :
public TcpConnection
148 uint16_t remote_port,
164 void setMaxFrameSize(uint32_t frame_size) { m_max_frame_size = frame_size; }
186 virtual int write(
const void *buf,
int count);
193 sigc::signal<void, FramedTcpConnection *, DisconnectReason>
disconnected;
207 sigc::signal<int, FramedTcpConnection *, void *, int>
dataReceived;
236 static const uint32_t DEFAULT_MAX_FRAME_SIZE = 1024 * 1024;
244 QueueItem(
const void* buf,
int count)
245 : m_buf(0), m_size(4+count), m_pos(0)
247 m_buf =
new char[4+count];
249 *ptr++ =
static_cast<uint32_t
>(count) >> 24;
250 *ptr++ = (
static_cast<uint32_t
>(count) >> 16) & 0xff;
251 *ptr++ = (
static_cast<uint32_t
>(count) >> 8) & 0xff;
252 *ptr++ = (
static_cast<uint32_t
>(count)) & 0xff;
253 std::memcpy(ptr, buf, count);
255 ~QueueItem(
void) {
delete [] m_buf; }
257 typedef std::deque<QueueItem*> TxQueue;
259 uint32_t m_max_frame_size;
260 bool m_size_received;
261 uint32_t m_frame_size;
262 std::vector<uint8_t> m_frame;
267 void onSendBufferFull(
bool is_full);
268 void disconnectCleanup(
void);
virtual int onDataReceived(void *buf, int count)
Called when data has been received on the connection.
sigc::signal< int, FramedTcpConnection *, void *, int > dataReceived
Contains a class for handling exiting TCP connections.
void setMaxFrameSize(uint32_t frame_size)
Set the maximum frame size.
sigc::signal< void, bool > sendBufferFull
sigc::signal< void, FramedTcpConnection *, DisconnectReason > disconnected
A signal that is emitted when a connection has been terminated.
virtual void onDisconnected(DisconnectReason reason)
Called when a connection has been terminated.
sigc::signal< void, FramedTcpConnection *, std::vector< uint8_t > & > frameReceived
A signal that is emitted when a frame has been received on the connection.
static const int DEFAULT_RECV_BUF_LEN
The default length of the reception buffer.
virtual void disconnect(void)
Disconnect from the remote host.
virtual int write(const void *buf, int count)
Send a frame on the TCP connection.
virtual ~FramedTcpConnection(void)
Destructor.
Namespace for the asynchronous programming classes.
A TCP connection with framed instead of streamed content.
FramedTcpConnection(size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
DisconnectReason
Reason code for disconnects.