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

Connection Class Reference

#include <connection.h>

Collaboration diagram for Connection:

Collaboration graph
[legend]
List of all members.

Public Methods

 Connection (SOCKET sock, Server *server)
virtual ~Connection ()
 Connection (const Connection &r_conn)
bool operator== (const Connection &r_conn) const
virtual void HandleInput ()
virtual void HandleOutput ()
virtual bool CanBeDisconnected ()
virtual bool HasOutput ()
virtual void Disconnect ()
virtual void SendMsg (const string &r_msg)
virtual string * ReadMsg ()
virtual SOCKET GetSocket () const

Protected Methods

Connection & operator= (const Connection &r_conn)

Protected Attributes

Server * mServer
 Server serving this connection.

Socket * mSock
 Network Socket stream.

bool mDisconnectable
 Indicates connection is to be disconnected.

list< string > mInBuffer
 Buffered input waiting to be processed.

list< string > mOutBuffer
 Buffered output waiting to be sent.

string mPendingInput
 Partially processed or formed input.


Constructor & Destructor Documentation

Connection::Connection (  SOCKET    sock,
Server *    server
) 
 

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.

References mSock.

Connection::~Connection (    )  [virtual]
 

Destructor for Connection

Definition at line 26 of file connection.cpp.

References mSock.

Connection::Connection (  const Connection &    r_conn ) 
 

Copy Constructor for Connection

Definition at line 33 of file connection.cpp.

References mSock.


Member Function Documentation

bool Connection::CanBeDisconnected (    )  [virtual]
 

CanBeDisconnected is called to query the Connection in order to check whether it has been scheduled for disconnection. 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 202 of file connection.cpp.

References mDisconnectable.

void Connection::Disconnect (    )  [virtual]
 

Disconnect is called to shutdown a Connection's socket.

Definition at line 162 of file connection.cpp.

References Socket::Close(), GetSocket(), mServer, mSock, Server::ServerLog(), and Log::Write().

SOCKET Connection::GetSocket (    )  const [virtual]
 

GetSocket

Returns :
the Connection's SOCKET value.

Definition at line 211 of file connection.cpp.

References Socket::GetSocket(), and mSock.

Referenced by Server::AcceptConnection(), Disconnect(), HandleInput(), HandleOutput(), and operator==().

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, which is stripped 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.

See also:
Server::Run

Definition at line 73 of file connection.cpp.

References GetSocket(), mDisconnectable, mInBuffer, mPendingInput, mServer, mSock, Socket::Read(), Server::ServerLog(), and Log::Write().

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 135 of file connection.cpp.

References Socket::Flush(), GetSocket(), mDisconnectable, mOutBuffer, mServer, mSock, Server::ServerLog(), Log::Write(), and Socket::Write().

bool Connection::HasOutput (    )  [virtual]
 

HasOutput is called to query whether the Connection has output ready to send.

Returns :
a boolean value indicating whether output is pending.

Definition at line 221 of file connection.cpp.

References mOutBuffer.

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

Assignment operator for Connection

Definition at line 43 of file connection.cpp.

References mInBuffer, mOutBuffer, mPendingInput, mServer, and mSock.

bool Connection::operator== (  const Connection &    r_conn )  const
 

Equality operator for Connection. If the SOCKET is the same they are equal.

Definition at line 59 of file connection.cpp.

References GetSocket().

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
Warning:
The caller is responsible for deleting this string! This can return an empty string, which indicates a CRLF only was sent.

Definition at line 185 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 173 of file connection.cpp.

References mOutBuffer.


Member Data Documentation

bool Connection::mDisconnectable [protected]
 

Indicates connection is to be disconnected.

Definition at line 42 of file connection.h.

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

list<string> Connection::mInBuffer [protected]
 

Buffered input waiting to be processed.

Definition at line 43 of file connection.h.

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

list<string> Connection::mOutBuffer [protected]
 

Buffered output waiting to be sent.

Definition at line 44 of file connection.h.

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

string Connection::mPendingInput [protected]
 

Partially processed or formed input.

Definition at line 45 of file connection.h.

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

Server* Connection::mServer [protected]
 

Server serving this connection.

Definition at line 40 of file connection.h.

Referenced by Disconnect(), HandleInput(), HandleOutput(), and operator=().

Socket* Connection::mSock [protected]
 

Network Socket stream.

Definition at line 41 of file connection.h.

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


The documentation for this class was generated from the following files:
Generated on Mon Mar 29 23:12:57 2004 for Paradigm by doxygen1.2.17