Serial-TCP/IPbridge  1.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
TCPIPConnection Class Reference

TCP/IP connection. More...

#include <tcpip_connection.h>

Inheritance diagram for TCPIPConnection:
Connection

Public Member Functions

virtual ~TCPIPConnection ()
 Destructor. More...
 
std::string getAddress () const
 Returns IPv4 address of the connected node. More...
 
unsigned getPort () const
 Returns port number through which the connected node is connected. More...
 
virtual void close ()
 Closes an established TCP connection. More...
 
- Public Member Functions inherited from Connection
 Connection (const Config &config, time_t timeout)
 Constructor. More...
 
virtual ~Connection ()
 Destructor. More...
 
std::string tryReceiveMessage ()
 Tries to receive a message from a client. More...
 
size_t trySendMessage (const std::string &message)
 Tries to send a message to the client. More...
 

Private Member Functions

 TCPIPConnection (int socket, sockaddr_in socketInfo, const TCPIPConfig &config)
 Constructor. More...
 
virtual std::string doReceiveMessage (Config::LengthFieldMessageLength messageLength)
 Receives a message. More...
 
virtual size_t doSendMessage (const std::string &message)
 Sends the selected message. More...
 
 TCPIPConnection (const TCPIPConnection &)
 
TCPIPConnectionoperator= (const TCPIPConnection &)
 

Private Attributes

int _socket
 Connection socket. More...
 
sockaddr_in _socketInfo
 Socket information. More...
 

Static Private Attributes

static const size_t DEFAULT_LENGTH_FIELD_BUFFER_SIZE = 4096
 Default buffer size used when receiving a message via length_field. More...
 

Friends

class TCPIPServer
 

Detailed Description

TCP/IP connection.

Objects of this class can be created only by a TCPIPServer.

It provides reference semantics (objects copying and comparison is NOT allowed).

Constructor & Destructor Documentation

virtual TCPIPConnection::~TCPIPConnection ( )
virtual

Destructor.

TCPIPConnection::TCPIPConnection ( int  socket,
sockaddr_in  socketInfo,
const TCPIPConfig config 
)
private

Constructor.

Parameters
socketCreated and connected socket.
socketInfoInitialized sockaddr_in structure.
configConnection configuration.
TCPIPConnection::TCPIPConnection ( const TCPIPConnection )
private

Member Function Documentation

virtual void TCPIPConnection::close ( )
virtual

Closes an established TCP connection.

If the connection is not established, nothing will happen.

Implements Connection.

virtual std::string TCPIPConnection::doReceiveMessage ( Config::LengthFieldMessageLength  messageLength)
privatevirtual

Receives a message.

Parameters
messageLengthLength of the message.
Returns
Received message.

This operation should be nonblocking.

If there is some error, ConnectionError will be thrown. If the connection is closed, ConnectionClosed will be thrown.

Implements Connection.

virtual size_t TCPIPConnection::doSendMessage ( const std::string &  message)
privatevirtual

Sends the selected message.

Parameters
messageMessage to be sent.
Returns
Number of sent bytes.

This operation should be nonblocking.

If there is some error, ConnectionError will be thrown. If the connection is closed, ConnectionClosed will be thrown.

Implements Connection.

std::string TCPIPConnection::getAddress ( ) const

Returns IPv4 address of the connected node.

unsigned TCPIPConnection::getPort ( ) const

Returns port number through which the connected node is connected.

TCPIPConnection& TCPIPConnection::operator= ( const TCPIPConnection )
private

Friends And Related Function Documentation

friend class TCPIPServer
friend

Member Data Documentation

int TCPIPConnection::_socket
private

Connection socket.

sockaddr_in TCPIPConnection::_socketInfo
private

Socket information.

const size_t TCPIPConnection::DEFAULT_LENGTH_FIELD_BUFFER_SIZE = 4096
staticprivate

Default buffer size used when receiving a message via length_field.


The documentation for this class was generated from the following file: