Async 1.7.0
|
A TCP connection with framed instead of streamed content. More...
#include <AsyncFramedTcpConnection.h>
Public Member Functions | |
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. | |
virtual | ~FramedTcpConnection (void) |
Destructor. | |
virtual TcpConnection & | operator= (TcpConnection &&other_base) override |
Move assignmnt operator. | |
void | setMaxFrameSize (uint32_t frame_size) |
Set the maximum frame size. | |
virtual int | write (const void *buf, int count) override |
Send a frame on the TCP connection. | |
Public Member Functions inherited from Async::TcpConnection | |
TcpConnection (size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
TcpConnection (int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
virtual | ~TcpConnection (void) |
Destructor. | |
void | setRecvBufLen (size_t recv_buf_len) |
Set a new receive buffer size. | |
virtual void | disconnect (void) |
Disconnect from the remote host. | |
const IpAddress & | remoteHost (void) const |
Return the IP-address of the remote host. | |
uint16_t | remotePort (void) const |
Return the remote port used. | |
bool | isConnected (void) const |
Check if the connection is established or not. | |
bool | isIdle (void) const |
Check if the connection is idle. |
Public Attributes | |
sigc::signal< void, FramedTcpConnection *, DisconnectReason > | disconnected |
A signal that is emitted 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. | |
Public Attributes inherited from Async::TcpConnection | |
sigc::signal< void, TcpConnection *, DisconnectReason > | disconnected |
A signal that is emitted when a connection has been terminated. | |
sigc::signal< int, TcpConnection *, void *, int > | dataReceived |
A signal that is emitted when data has been received on the connection. | |
sigc::signal< void, bool > | sendBufferFull |
A signal that is emitted when the send buffer status changes. |
Protected Member Functions | |
FramedTcpConnection & | operator= (const FramedTcpConnection &)=delete |
virtual void | closeConnection (void) override |
Disconnect from the remote peer. | |
virtual void | onDisconnected (DisconnectReason reason) override |
Called when a connection has been terminated. | |
virtual int | onDataReceived (void *buf, int count) override |
Called when data has been received on the connection. | |
virtual void | emitDisconnected (DisconnectReason reason) override |
Emit the disconnected signal. | |
Protected Member Functions inherited from Async::TcpConnection | |
void | setSocket (int sock) |
Setup information about the connection. | |
void | setRemoteAddr (const IpAddress &remote_addr) |
Setup information about the connection. | |
void | setRemotePort (uint16_t remote_port) |
Setup information about the connection. | |
int | socket (void) const |
Return the socket file descriptor. |
Protected Attributes | |
sigc::signal< int, TcpConnection *, void *, int > | dataReceived |
sigc::signal< void, bool > | sendBufferFull |
Additional Inherited Members | |
Public Types inherited from Async::TcpConnection | |
enum | DisconnectReason { DR_HOST_NOT_FOUND , DR_REMOTE_DISCONNECTED , DR_SYSTEM_ERROR , DR_RECV_BUFFER_OVERFLOW , DR_ORDERED_DISCONNECT , DR_PROTOCOL_ERROR , DR_SWITCH_PEER , DR_BAD_STATE } |
Reason code for disconnects. More... | |
Static Public Member Functions inherited from Async::TcpConnection | |
static const char * | disconnectReasonStr (DisconnectReason reason) |
Translate disconnect reason to a string. | |
Static Public Attributes inherited from Async::TcpConnection | |
static const int | DEFAULT_RECV_BUF_LEN = 1024 |
The default length of the reception buffer. |
A TCP connection with framed instead of streamed content.
This class implements a framed TCP connection. It will make sure that the data given to one call to the write function will arrive at the other end in one piece or not at all. This makes it easier to implement message based protocols that only want to see completely transfered messages at the other end.
Definition at line 131 of file AsyncFramedTcpConnection.h.
|
explicit |
Constructor.
recv_buf_len | The length of the receiver buffer to use |
References Async::TcpConnection::DEFAULT_RECV_BUF_LEN.
Referenced by operator=().
Async::FramedTcpConnection::FramedTcpConnection | ( | int | sock, |
const IpAddress & | remote_addr, | ||
uint16_t | remote_port, | ||
size_t | recv_buf_len = DEFAULT_RECV_BUF_LEN ) |
Constructor.
sock | The socket for the connection to handle |
remote_addr | The remote IP-address of the connection |
remote_port | The remote TCP-port of the connection |
recv_buf_len | The length of the receiver buffer to use |
References Async::TcpConnection::DEFAULT_RECV_BUF_LEN.
|
virtual |
Destructor.
|
overrideprotectedvirtual |
Disconnect from the remote peer.
This function is used internally to close the connection to the remote peer.
Reimplemented from Async::TcpConnection.
|
inlineoverrideprotectedvirtual |
Emit the disconnected signal.
reason | The reason for the disconnection |
Reimplemented from Async::TcpConnection.
Definition at line 251 of file AsyncFramedTcpConnection.h.
References disconnected, and Async::TcpConnection::emitDisconnected().
|
overrideprotectedvirtual |
Called when data has been received on the connection.
buf | A buffer containg the read data |
count | The number of bytes in the buffer |
This function is called when data has been received on this connection. The buffer will contain the bytes read from the operating system. The function will return the number of bytes that has been processed. The bytes not processed will be stored in the receive buffer for this class and presented again to the slot when more data arrives. The new data will be appended to the old data. The default action for this function is to emit the dataReceived signal.
Reimplemented from Async::TcpConnection.
|
overrideprotectedvirtual |
Called when a connection has been terminated.
reason | The reason for the disconnect |
This function will be called when the connection has been terminated. The default action for this function is to emit the disconnected signal.
Reimplemented from Async::TcpConnection.
|
protecteddelete |
References FramedTcpConnection().
|
overridevirtual |
Move assignmnt operator.
other_base | The object to move from |
The move operator move the state of a specified TcpFramedConnection object into this object. After the move, the state of the other object will be the same as if it had just been default constructed.
Reimplemented from Async::TcpConnection.
References Async::TcpConnection::TcpConnection().
|
inline |
Set the maximum frame size.
frame_size | The maximum frame size in bytes |
Use this function to set the maximum allowed frame size. If a frame size number larger than this is received a disconnection is immediately issued. The default maximum frame size is DEFAULT_MAX_FRAME_SIZE.
Definition at line 175 of file AsyncFramedTcpConnection.h.
|
overridevirtual |
Send a frame on the TCP connection.
buf | The buffer containing the frame to send |
count | The number of bytes in the frame |
This function will send a frame of data on the TCP connection. The frame will either be completely transmitted or discarded on error. There is no inbetween so this function will always return either the given count or -1 on error.
Reimplemented from Async::TcpConnection.
|
protected |
Definition at line 209 of file AsyncFramedTcpConnection.h.
sigc::signal<void, FramedTcpConnection *, DisconnectReason> Async::FramedTcpConnection::disconnected |
A signal that is emitted when a connection has been terminated.
con | The connection object |
reason | The reason for the disconnect |
Definition at line 195 of file AsyncFramedTcpConnection.h.
Referenced by emitDisconnected().
sigc::signal<void, FramedTcpConnection *, std::vector<uint8_t>&> Async::FramedTcpConnection::frameReceived |
A signal that is emitted when a frame has been received on the connection.
buf | A buffer containg the read data |
count | The number of bytes in the buffer |
This signal is emitted when a frame has been received on this connection.
Definition at line 206 of file AsyncFramedTcpConnection.h.
|
protected |
Definition at line 210 of file AsyncFramedTcpConnection.h.