Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

BasicTcpServer Class Reference

Inheritance diagram for BasicTcpServer:

CmdServer DumpServer List of all members.

Detailed Description

Definition at line 36 of file server.h.

Public Member Functions

 BasicTcpServer (int portNum, int maxClients=5, const char *intro=NULL)
void blockOn ()
 A method to block the calling thread as long as the BasicTcpServer exists.
void init ()
 A method to initialise and start the server.
void setDebug (bool onOff)
void setID (const char *id)
 A method to enable/disable printing of debug statements for the class.
virtual ~BasicTcpServer ()

Static Public Member Functions

static void setDebugAll (bool onOff)
 A method to enable/disable printing of debug statements for a single object.

Protected Member Functions

virtual int doServerOp (ClientInfo *ci)=0
virtual void onConnect (ClientInfo *curr)
virtual void onDisconnect (ClientInfo *curr)
int readLine (int fd, char *buf, int maxBytes)
int readn (int fd, char *buf, int nBytes, int timeOut)

Protected Attributes

std::list< ClientInfo * > clientList
 List of connected clients.
pthread_mutex_t clientListMutex
 List access mutex.
char errMsg [120]
const char * id
 Identifier for debug output.
std::list< ClientInfo
* >::const_iterator 
pos
 List iterator.
pthread_attr_t threadAttr
sched_param threadParam

Static Protected Attributes

static const int SCHED_POLICY = SCHED_RR

Classes

struct  Arg
struct  ClientInfo
 A structure to hold client identification data. More...


Constructor & Destructor Documentation

BasicTcpServer::BasicTcpServer int  portNum,
int  maxClients = 5,
const char *  intro = NULL
 

Constructor.

Parameters:
portNum The port number of the socket;
maxClients The maximum number of simultaneous client connections allowed.
intro A string that will be sent to the client when it first connects to the server.

Definition at line 41 of file server.cc.

References clientListMutex.


Member Function Documentation

virtual int BasicTcpServer::doServerOp ClientInfo ci  )  [protected, pure virtual]
 

This method is the operation that the server repeatedly performs for each client e.g. send and/or receive data. This method must be implemented in the derived class.

Returns:
A negative number for serious errors and to terminate the connection to the client. This method must be implemented in the derived class.

int BasicTcpServer::readLine int  fd,
char *  buf,
int  maxBytes
[protected]
 

A method to read a line of text from a socket. The method returns when either a newline character is encountered or the specified maximum number of bytes have been read.

Parameters:
fd The open file descriptor for the socket.
buf A pointer to a buffer large enough to hold the number of bytes to be read.
maxBytes The maximum number of bytes to be read.
Returns:
The (positive) number of bytes read on success, 0 if client has closed the socket connection or a negative number from error codes above.

Definition at line 221 of file server.cc.

int BasicTcpServer::readn int  fd,
char *  buf,
int  nBytes,
int  timeOut
[protected]
 

A method to read a specified number of bytes from a socket.

Parameters:
fd The open file descriptor for the socket.
buf A pointer to a buffer large enough to hold the number of bytes to be read.
nBytes The number of bytes to be read.
timeout The total allowable time in microseconds to complete the read. Minimum value of timeout is 1 microsec per byte.
Returns:
The (positive) number of bytes read on success, zero if client has closed the socket connection or a negative number from error codes above.

Definition at line 157 of file server.cc.


The documentation for this class was generated from the following files:
Generated on Mon Apr 30 13:32:41 2007 for Parkes M & C - PKMC C++ library API by  doxygen 1.4.4