omegalib
13.1
|
A TCP Connection. More...
#include <Tcp.h>
Public Types | |
enum | ConnectionState { ConnectionListening, ConnectionOpen, ConnectionClosed } |
Public Member Functions | |
TcpConnection (const ConnectionInfo &ci) | |
virtual | ~TcpConnection () |
void | handle_connect (const asio::error_code &error) |
tcp::socket & | getSocket () |
Connection properties. More... | |
ConnectionState | getState () |
Gets the connection state. More... | |
const ConnectionInfo & | getConnectionInfo () |
Gets the connection info object. More... | |
bool | poll () |
Connection management. More... | |
void | close () |
Forces a connection close. More... | |
void | waitClose () |
Waits for the other end to close the connection. More... | |
void | open (const String &host, int port) |
Opens a connection to a server. More... | |
void | write (const String &data) |
Data IO Note: all the write methods are blocking: they return only when the data has been fully written to the internal buffers. More... | |
void | write (void *data, size_t size) |
Writes a buffer to the connection stream. More... | |
size_t | readUntil (void *buffer, size_t size, char delimiter= '\0') |
Synchronously read byte data until the specified delimiter is found or the buffer fills up. More... | |
size_t | read (void *buffer, size_t size) |
Synchronously read thre specified number of bytes from the stream. More... | |
size_t | availableBytes () |
Returns the number of bytes available to be read. More... | |
virtual void | handleConnected () |
Connection events. More... | |
virtual void | handleClosed () |
virtual void | handleError (const ConnectionError &err) |
virtual void | handleData () |
Public Member Functions inherited from omicron::ReferenceType | |
ReferenceType () | |
virtual | ~ReferenceType () |
void | ref () |
void | unref () |
long | refCount () |
Protected Member Functions | |
void | doHandleConnected () |
Protected Attributes | |
String | myHost |
int | myPort |
ConnectionInfo | myConnectionInfo |
ConnectionState | myState |
tcp::socket | mySocket |
asio::streambuf | myInputBuffer |
Friends | |
class | TcpServer |
Additional Inherited Members | |
Static Public Member Functions inherited from omicron::ReferenceType | |
static void | printObjCounts () |
Static Protected Attributes inherited from omicron::ReferenceType | |
static List< ReferenceType * > | mysObjList |
A TCP Connection.
Can be used to establish a connection to a TCP server (using the open method). It is also used by the TcpSerer class to represent each client connection. User code can derive this class and reimplement the handleConnected, handleData, handleClose and handleError methods.
omicron::TcpConnection::TcpConnection | ( | const ConnectionInfo & | ci | ) |
|
inlinevirtual |
|
inline |
Returns the number of bytes available to be read.
void omicron::TcpConnection::close | ( | ) |
Forces a connection close.
To gracefully close connections, one side should call waitClose (usually the client), while the other calls close. waitClose will return once the connection has been closed correctly. It is the user's responsibility to signal each end when a connection should be closed, and call close and waitClose appropriately.
|
protected |
|
inline |
Gets the connection info object.
|
inline |
Connection properties.
Gets the internal ASIO socket object.
|
inline |
Gets the connection state.
void omicron::TcpConnection::handle_connect | ( | const asio::error_code & | error | ) |
|
virtual |
Reimplemented in omega::MissionControlConnection, and omicron::AssetCacheConnection.
|
virtual |
Connection events.
Reimplemented in omega::MissionControlConnection, and omicron::AssetCacheConnection.
|
virtual |
Reimplemented in omega::MissionControlConnection, and omicron::AssetCacheConnection.
|
virtual |
Reimplemented in omega::MissionControlConnection.
void omicron::TcpConnection::open | ( | const String & | host, |
int | port | ||
) |
Opens a connection to a server.
bool omicron::TcpConnection::poll | ( | ) |
Connection management.
Polls the connection. Calls handleData when new data is available. Calls handleClosed when the connection has been closed from the other end.
size_t omicron::TcpConnection::read | ( | void * | buffer, |
size_t | size | ||
) |
Synchronously read thre specified number of bytes from the stream.
size_t omicron::TcpConnection::readUntil | ( | void * | buffer, |
size_t | size, | ||
char | delimiter = '\0' |
||
) |
Synchronously read byte data until the specified delimiter is found or the buffer fills up.
void omicron::TcpConnection::waitClose | ( | ) |
Waits for the other end to close the connection.
void omicron::TcpConnection::write | ( | const String & | data | ) |
Data IO Note: all the write methods are blocking: they return only when the data has been fully written to the internal buffers.
Therefore, buffers passed to write methods can be safely modified to after a write call. Writes a string to the connection stream. The string will NOT be NULL terminated.
void omicron::TcpConnection::write | ( | void * | data, |
size_t | size | ||
) |
Writes a buffer to the connection stream.
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |