36#ifndef ASYNC_FRAMED_TCP_CONNECTION_INCLUDED
37#define ASYNC_FRAMED_TCP_CONNECTION_INCLUDED
148 uint16_t remote_port,
188 virtual int write(
const void *buf,
int count)
override;
195 sigc::signal<void, FramedTcpConnection *, DisconnectReason>
disconnected;
258 static const uint32_t DEFAULT_MAX_FRAME_SIZE = 1024 * 1024;
266 QueueItem(
const void* buf,
int count)
267 : m_buf(0), m_size(4+count), m_pos(0)
269 m_buf =
new char[4+count];
271 *ptr++ =
static_cast<uint32_t
>(count) >> 24;
272 *ptr++ = (
static_cast<uint32_t
>(count) >> 16) & 0xff;
273 *ptr++ = (
static_cast<uint32_t
>(count) >> 8) & 0xff;
274 *ptr++ = (
static_cast<uint32_t
>(count)) & 0xff;
275 std::memcpy(ptr, buf, count);
277 ~QueueItem(
void) {
delete [] m_buf; }
279 typedef std::deque<QueueItem*> TxQueue;
281 uint32_t m_max_frame_size;
282 bool m_size_received;
283 uint32_t m_frame_size;
284 std::vector<uint8_t> m_frame;
288 void onSendBufferFull(
bool is_full);
289 void disconnectCleanup(
void);
Contains a class for handling exiting TCP connections.
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.
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 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.
static const int DEFAULT_RECV_BUF_LEN
The default length of the reception buffer.
DisconnectReason
Reason code for disconnects.
virtual void emitDisconnected(DisconnectReason reason)
Emit the disconnected signal.
TcpConnection(size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
Namespace for the asynchronous programming classes.