36#ifndef ASYNC_FRAMED_TCP_CONNECTION_INCLUDED
37#define ASYNC_FRAMED_TCP_CONNECTION_INCLUDED
148 uint16_t remote_port,
178 m_max_rx_frame_size = frame_size;
192 m_max_tx_frame_size = frame_size;
220 virtual int write(
const void *buf,
int count)
override;
227 sigc::signal<void, FramedTcpConnection *, DisconnectReason>
disconnected;
290 static const uint32_t DEFAULT_MAX_FRAME_SIZE = 1024 * 1024;
298 QueueItem(
const void* buf,
int count)
299 : m_buf(0), m_size(4+count), m_pos(0)
301 m_buf =
new char[4+count];
303 *ptr++ =
static_cast<uint32_t
>(count) >> 24;
304 *ptr++ = (
static_cast<uint32_t
>(count) >> 16) & 0xff;
305 *ptr++ = (
static_cast<uint32_t
>(count) >> 8) & 0xff;
306 *ptr++ = (
static_cast<uint32_t
>(count)) & 0xff;
307 std::memcpy(ptr, buf, count);
309 ~QueueItem(
void) {
delete [] m_buf; }
311 typedef std::deque<QueueItem*> TxQueue;
313 uint32_t m_max_rx_frame_size;
314 uint32_t m_max_tx_frame_size;
315 bool m_size_received;
316 uint32_t m_frame_size;
317 std::vector<uint8_t> m_frame;
322 void disconnectCleanup(
void);
Contains a class for handling exiting TCP connections.
A TCP connection with framed instead of streamed content.
virtual void onDisconnected(DisconnectReason reason) override
Called when a connection has been terminated.
virtual ~FramedTcpConnection(void)
Destructor.
virtual int write(const void *buf, int count) override
Send a frame on the TCP connection.
void setMaxRxFrameSize(uint32_t frame_size)
Set the maximum RX frame size.
FramedTcpConnection & operator=(const FramedTcpConnection &)=delete
virtual TcpConnection & operator=(TcpConnection &&other_base) override
Move assignmnt operator.
virtual void closeConnection(void) override
Disconnect from the remote peer.
void setMaxTxFrameSize(uint32_t frame_size)
Set the maximum TX frame size.
void setMaxFrameSize(uint32_t frame_size)
Set the maximum frame size.
sigc::signal< void, FramedTcpConnection *, std::vector< uint8_t > & > frameReceived
A signal that is emitted when a frame has been received on the connection.
virtual int onDataReceived(void *buf, int count) override
Called when data has been received on the connection.
sigc::signal< void, bool > sendBufferFull
virtual void emitDisconnected(DisconnectReason reason) override
Emit the disconnected signal.
sigc::signal< void, FramedTcpConnection *, DisconnectReason > disconnected
A signal that is emitted when a connection has been terminated.
sigc::signal< int, TcpConnection *, void *, int > dataReceived
FramedTcpConnection(size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
FramedTcpConnection(int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
A class for representing an IP address in an OS independent way.
A class for handling exiting TCP connections.
static const int DEFAULT_RECV_BUF_LEN
The default size of the reception buffer.
DisconnectReason
Reason code for disconnects.
virtual void emitDisconnected(DisconnectReason reason)
Emit the disconnected signal.
Namespace for the asynchronous programming classes.