Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

CServerInstance Class Reference

#include <CServerInstance.h>

Inheritance diagram for CServerInstance:

CFileEvent CEvent CRegisteredObject CNamedObject List of all members.

Public Member Functions

 CServerInstance (CSocket *pSocket, bool fDeleteSocket=true)
 CServerInstance (const char *pName, CSocket *pSocket, bool fDeleteSocket=true)
 CServerInstance (const STD(string)&rName, CSocket *pSocket, bool fDeleteSocket=true)
 ~CServerInstance ()
CSocketgetSocket ()
bool getDeleteFlag () const
 STD (string) getPeername() const
unsigned short getPeerPort () const
virtual void OnReadable (istream &rStream)
virtual void OnRequest (CSocket *pConnection)
void Shutdown ()
virtual STD (string) DescribeSelf()

Protected Member Functions

void setSocket (CSocket *sock)
void setDelFlag (bool flag)

Private Member Functions

 CServerInstance (const CServerInstance &rhs)
CServerInstanceoperator= (const CServerInstance &rhs)
int operator== (const CServerInstance &rhs)

Private Attributes

CSocketm_pPeer
 Pointer to peer socket.
bool m_fDeleteSocket
 True if destructor deletes socket.

Detailed Description

Encapsulates the funtionality of a `simple' Tcp/Ip server instance. Simpler tcp/ip server instances are connections with a client over a socket which operate in the simple::

This class is a subclass of the CFileEvent class... OnReadable is overridden by this class, the user, should in turn override this class and override OnRequest(). OnRequest() entered with the application serialization mutex held, and therefore can perform any function which requires global syncrhonization.

Definition at line 321 of file CServerInstance.h.


Constructor & Destructor Documentation

CServerInstance::CServerInstance CSocket pSocket,
bool  fDeleteSocket = true
 

Construct an anonymous server instance:

Parameters:
pSocket - Pointer to the socket open to the client.
fDeleteSocket - true if the destructor should delete the socket.

Definition at line 307 of file CServerInstance.cpp.

CServerInstance::CServerInstance const char *  pName,
CSocket pSocket,
bool  fDeleteSocket = true
 

Construct a server instance whose name comes from a char* string.

Parameters:
pName - Name to give to the instance (const char*) [in]
pSocket - Socket open on peer. (CSocket* ) [in]
fDeleteSocket - true to delete sock on destruct (bool) [in = true]

Definition at line 321 of file CServerInstance.cpp.

CServerInstance::CServerInstance const STD(string)&  rName,
CSocket pSocket,
bool  fDeleteSocket = true
 

CServerInstance::~CServerInstance  ) 
 

The destructor just deletes m_pPeer if m_fDeleteSocket is true.

Definition at line 345 of file CServerInstance.cpp.

References CSocket::getState(), m_pPeer, and CSocket::Shutdown().

CServerInstance::CServerInstance const CServerInstance rhs  )  [private]
 


Member Function Documentation

bool CServerInstance::getDeleteFlag  )  const [inline]
 

Definition at line 349 of file CServerInstance.h.

unsigned short CServerInstance::getPeerPort  )  const
 

Determines the port to which the socket is connected on the peer.

Return values:
int The port number assigned to this socket.
Note:
Can throw any exception thrown by CSocket::getPeer()

Definition at line 387 of file CServerInstance.cpp.

References CSocket::getPeer(), and m_pPeer.

CSocket* CServerInstance::getSocket  )  [inline]
 

Definition at line 346 of file CServerInstance.h.

void CServerInstance::OnReadable istream &  rInput  )  [virtual]
 

Called when the socket becomes readable. We get the socket and pass that to OnRequest which is what the user is supposed to override and embed application functionality in.

Parameters:
rInput - Stream open on the socket (istream& [in-out])
Note:
DO NOT OVERRIDE THIS

Reimplemented from CFileEvent.

Definition at line 409 of file CServerInstance.cpp.

References m_pPeer, OnRequest(), and Shutdown().

void CServerInstance::OnRequest CSocket pConnection  )  [virtual]
 

Called when the client has a request of the server. The application has overridden this member in its derived class.

Parameters:
pConnection - Socket open to the peer (CSocket* [in-out]).

Definition at line 425 of file CServerInstance.cpp.

Referenced by OnReadable().

CServerInstance& CServerInstance::operator= const CServerInstance rhs  )  [private]
 

int CServerInstance::operator== const CServerInstance rhs  )  [private]
 

void CServerInstance::setDelFlag bool  flag  )  [inline, protected]
 

Definition at line 361 of file CServerInstance.h.

References m_fDeleteSocket.

void CServerInstance::setSocket CSocket sock  )  [inline, protected]
 

Definition at line 358 of file CServerInstance.h.

References m_pPeer.

void CServerInstance::Shutdown  ) 
 

Called when we want to shutdown the server we must:

  1. Remove all fd monitoring.
  2. Clear the enable flag.
  3. Shutdown the socket.

It's someone else's responsibility to reap these threads and delete the objects.

Definition at line 441 of file CServerInstance.cpp.

References CSocket::getState(), m_pPeer, CFileEvent::MonitorReadable(), CEvent::setEnable(), and CSocket::Shutdown().

Referenced by OnReadable().

virtual CServerInstance::STD string   )  [virtual]
 

The name of the object

Reimplemented from CFileEvent.

CServerInstance::STD string   )  const
 

Reimplemented from CNamedObject.


Member Data Documentation

bool CServerInstance::m_fDeleteSocket [private]
 

True if destructor deletes socket.

Definition at line 325 of file CServerInstance.h.

Referenced by setDelFlag().

CSocket* CServerInstance::m_pPeer [private]
 

Pointer to peer socket.

Definition at line 324 of file CServerInstance.h.

Referenced by getPeerPort(), OnReadable(), setSocket(), Shutdown(), and ~CServerInstance().


The documentation for this class was generated from the following files:
Generated on Thu Jan 6 16:58:44 2005 for Spectrodaq External Event Framework by  doxygen 1.3.9.1