Main Page   Namespace List   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Connection Class Reference

#include <connection.h>

List of all members.

Public Methods

 Connection (SOCKET sock)
virtual ~Connection ()
 Connection (const Connection &r_conn)
virtual void HandleInput ()
virtual void HandleOutput ()
virtual bool CanBeDisconnected ()
virtual void Disconnect ()
virtual void SendMsg (const string &r_msg)
virtual string * ReadMsg ()
virtual SOCKET GetSocket ()

Protected Methods

Connection & operator= (const Connection &r_conn)

Protected Attributes

SOCKET mSock
 network socket

bool mDisconnectable
 flag indicating connection wishes to be disconnected

list< string > mInBuffer
 buffered lines waiting to be processed

list< string > mOutBuffer
 buffered lines waiting to be output

char * mpPendingOutput
 pending output on socket

char * mpPendingInput
 pending or not fully formed input on socket


Detailed Description

The Connection class contains the minimum amount of attributes to reasonably maintain a socket connection with a client.

Todo:

Definition at line 23 of file connection.h.


Constructor & Destructor Documentation

Connection::Connection (  SOCKET    sock ) 
 

Constructor for Connection. There is no default constructor as all connections must be constructed with a socket.

Definition at line 18 of file connection.cpp.

Connection::~Connection (    )  [virtual]
 

Destructor for Connection

Definition at line 26 of file connection.cpp.

References mpPendingInput, and mpPendingOutput.

Connection::Connection (  const Connection &    r_conn ) 
 

Copy Constructor for Connection

Definition at line 35 of file connection.cpp.

References mInBuffer, mOutBuffer, mpPendingInput, and mpPendingOutput.


Member Function Documentation

bool Connection::CanBeDisconnected (    )  [virtual]
 

CanBeDisconnected is called to query the Connection in order to see whether it wants to be disconnected. Currently this status is set only when there is an error.

Returns :
a boolean value indicating whether the connection is to be disconnected.

Definition at line 251 of file connection.cpp.

References mDisconnectable.

void Connection::Disconnect (    )  [virtual]
 

Disconnect is called to shutdown a Connection's socket.

Definition at line 205 of file connection.cpp.

References mSock.

SOCKET Connection::GetSocket (    )  [virtual]
 

GetSocket

Returns :
the Connection's SOCKET value.

Definition at line 261 of file connection.cpp.

References mSock.

void Connection::HandleInput (    )  [virtual]
 

HandleInput is called to order a connection to process any input waiting on its socket. Input is parsed into lines based on the occurance of the CRLF terminator and pushed into a buffer which is a list of lines. The buffer expands dynamically as input is processed. Input that has yet to see a CRLF terminator is left in the Connection's pPendingInput array.

Note:
Unix/BSD portability notes:
  • Either read() or recv() may be used.
  • Winsock errors are prepended with WSA modify accordingly.
  • WSAGetLastError() should be replaced with global errno variable.
See also:
Server::Run

Definition at line 87 of file connection.cpp.

References mDisconnectable, mInBuffer, mpPendingInput, and mSock.

void Connection::HandleOutput (    )  [virtual]
 

HandleOutput is called to order a connection to process any output waiting on its socket.

Note:
Unix/BSD portability notes:
  • Either send() or write() may be used.
  • Winsock errors are prepended with WSA modify accordingly.
  • WSAGetLastError() should be replaced with global errno variable.
See also:
Server::Run

Definition at line 154 of file connection.cpp.

References mDisconnectable, mOutBuffer, mpPendingOutput, and mSock.

Connection & Connection::operator= (  const Connection &    r_conn )  [protected]
 

Assignment operator for Connection

Definition at line 54 of file connection.cpp.

References mInBuffer, mOutBuffer, mpPendingInput, and mpPendingOutput.

string * Connection::ReadMsg (    )  [virtual]
 

ReadMsg removes a message from the Connection's input buffer.

Returns :
the message, a new string or NULL if no messages

Definition at line 233 of file connection.cpp.

References mInBuffer.

void Connection::SendMsg (  const string &    r_msg )  [virtual]
 

SendMsg places a message on the Connection's output buffer.

Parameters:
r_msg  the message, a reference to a string

Definition at line 223 of file connection.cpp.

References mOutBuffer.

Referenced by Server::Run().


Member Data Documentation

bool Connection::mDisconnectable [protected]
 

flag indicating connection wishes to be disconnected

Definition at line 51 of file connection.h.

Referenced by CanBeDisconnected(), HandleInput(), and HandleOutput().

list<string> Connection::mInBuffer [protected]
 

buffered lines waiting to be processed

Definition at line 53 of file connection.h.

Referenced by Connection(), HandleInput(), operator=(), and ReadMsg().

list<string> Connection::mOutBuffer [protected]
 

buffered lines waiting to be output

Definition at line 55 of file connection.h.

Referenced by Connection(), HandleOutput(), operator=(), and SendMsg().

char* Connection::mpPendingInput [protected]
 

pending or not fully formed input on socket

Definition at line 59 of file connection.h.

Referenced by Connection(), HandleInput(), operator=(), and ~Connection().

char* Connection::mpPendingOutput [protected]
 

pending output on socket

Definition at line 57 of file connection.h.

Referenced by Connection(), HandleOutput(), operator=(), and ~Connection().

SOCKET Connection::mSock [protected]
 

network socket

Definition at line 49 of file connection.h.

Referenced by Disconnect(), GetSocket(), HandleInput(), and HandleOutput().


The documentation for this class was generated from the following files:
Generated on Mon Mar 29 22:38:42 2004 for Paradigm by doxygen1.2.17