ConnectionBase Class Reference

An abstract base class for a connection. More...

#include <connectionbase.h>

Inheritance diagram for ConnectionBase:

Inheritance graph
[legend]
Collaboration diagram for ConnectionBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ConnectionBase (ConnectionDataHandler *cdh)
virtual ~ConnectionBase ()
virtual ConnectionError connect ()=0
virtual ConnectionError recv (int timeout=-1)=0
virtual bool send (const std::string &data)=0
virtual ConnectionError receive ()=0
virtual void disconnect ()=0
virtual void cleanup ()
ConnectionState state () const
void registerConnectionDataHandler (ConnectionDataHandler *cdh)
void setServer (const std::string &server, int port=-1)
const std::string & server () const
virtual void getStatistics (int &totalIn, int &totalOut)=0
virtual ConnectionBasenewInstance () const =0


Detailed Description

An abstract base class for a connection.

You should not need to use this class directly.

Author:
Jakob Schröter <js@camaya.net>
Since:
0.9

Definition at line 34 of file connectionbase.h.


Constructor & Destructor Documentation

ConnectionBase ( ConnectionDataHandler cdh  )  [inline]

Constructor.

Parameters:
cdh An object derived from ConnectionDataHandler that will receive received data.

Definition at line 42 of file connectionbase.h.

virtual ~ConnectionBase (  )  [inline, virtual]

Virtual destructor.

Definition at line 49 of file connectionbase.h.


Member Function Documentation

virtual ConnectionError connect (  )  [pure virtual]

Used to initiate the connection.

Returns:
Returns the connection state.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, ConnectionTCPClient, and ConnectionTCPServer.

virtual ConnectionError recv ( int  timeout = -1  )  [pure virtual]

Use this periodically to receive data from the socket and to feed the parser.

Parameters:
timeout The timeout to use for select in microseconds. Default of -1 means blocking.
Returns:
The state of the connection.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, ConnectionTCPClient, and ConnectionTCPServer.

virtual bool send ( const std::string &  data  )  [pure virtual]

Use this function to send a string of data over the wire. The function returns only after all data has been sent.

Parameters:
data The data to send.
Returns:
True if the data has been sent (no guarantee of receipt), false in case of an error.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, and ConnectionTCPBase.

virtual ConnectionError receive (  )  [pure virtual]

Use this function to put the connection into 'receive mode', i.e. this function returns only when the connection is terminated.

Returns:
Returns a value indicating the disconnection reason.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, and ConnectionTCPBase.

virtual void disconnect (  )  [pure virtual]

Disconnects an established connection. NOOP if no active connection exists.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, and ConnectionTCPBase.

virtual void cleanup (  )  [inline, virtual]

This function is called after a disconnect to clean up internal state. It is also called by ConnectionBase's destructor.

Reimplemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, and ConnectionTCPBase.

Definition at line 89 of file connectionbase.h.

ConnectionState state (  )  const [inline]

Returns the current connection state.

Returns:
The state of the connection.

Definition at line 95 of file connectionbase.h.

void registerConnectionDataHandler ( ConnectionDataHandler cdh  )  [inline]

Use this function to register a new ConnectionDataHandler. There can be only one ConnectionDataHandler at any one time.

Parameters:
cdh The new ConnectionDataHandler.

Definition at line 102 of file connectionbase.h.

void setServer ( const std::string &  server,
int  port = -1 
) [inline]

Sets the server to connect to.

Parameters:
server The server to connect to. Either IP or fully qualified domain name.
port The port to connect to.

Reimplemented in ConnectionHTTPProxy.

Definition at line 109 of file connectionbase.h.

const std::string& server (  )  const [inline]

Returns the currently set server/IP.

Returns:
The server host/IP.

Definition at line 115 of file connectionbase.h.

virtual void getStatistics ( int &  totalIn,
int &  totalOut 
) [pure virtual]

Returns current connection statistics.

Parameters:
totalIn The total number of bytes received.
totalOut The total number of bytes sent.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, and ConnectionTCPBase.

virtual ConnectionBase* newInstance (  )  const [pure virtual]

This function returns a new instance of the current ConnectionBase-derived object. The idea is to be able to 'clone' ConnectionBase-derived objects without knowing of what type they are exactly.

Returns:
A new Connection* instance.

Implemented in ConnectionHTTPProxy, ConnectionSOCKS5Proxy, ConnectionTCPClient, and ConnectionTCPServer.


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

Generated on Fri Oct 10 15:26:15 2008 for gloox by  doxygen 1.5.6