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

Server Class Reference

#include <server.h>

Collaboration diagram for Server:

Collaboration graph
[legend]
List of all members.

Public Methods

 Server (EventQueue &r_inque, EventQueue &r_outque, Log &r_lgfile)
virtual ~Server ()
virtual bool Boot (unsigned short port)
virtual void Run (void *parms)
Log & ServerLog ()

Private Methods

 Server (const Server &)
Server & operator= (const Server &)
void AcceptConnection ()
void InitFDs ()
void ProcessQueue ()
void ShutdownServer ()
bool SetNonBlocking (SOCKET s)

Private Attributes

bool mShutdown
 Flag to indicate that server is shutting down.

fd_set mInputFDs
 Array of input sockets that select will test.

fd_set mOutputFDs
 Array of output sockets that select will test.

SOCKET mAcceptor
 Listening socket for incoming connections.

sockaddr_in mTo
 Network address of the server port.

ConnList mConns
 List of Connections managed by this server.

int mNumFds
Log & mrLog
 Server's log.

EventQueue & mrInQueue
 Incoming events.

EventQueue & mrOutQueue
 Outgoing events.


Detailed Description

The Server class defines a singleton representation of a internet server. It defines the traditional non-blocking select() server.

Note:
No reason why this should be a singleton as long as different ports are served.
Todo:
Make Server an abstract class overriding its Run method to illustrate different network designs as well as different kinds of servers, e.g. httpd, ftpd, and telnetd.

Definition at line 32 of file server.h.


Constructor & Destructor Documentation

Server::Server (  EventQueue &    r_inque,
EventQueue &    r_outque,
Log &    r_lgfile
) 
 

Constructor for Server

Definition at line 16 of file server.cpp.

Server::~Server (    )  [virtual]
 

Destructor for Server

Note:
If we shutdown normally we should not have any connections in our list but we will attempt to delete them anyways. Maybe we should assert this.

Definition at line 28 of file server.cpp.

References mConns.

Server::Server (  const Server &    )  [private]
 


Member Function Documentation

void Server::AcceptConnection (    )  [private]
 

AcceptConnection handles an incoming connection request on the server's listening port by creating a Connection object for the socket.

Remarks:
Dang this code looks dense.

Definition at line 174 of file server.cpp.

References CONNECT_E, Connection::GetSocket(), mAcceptor, mConns, mrOutQueue, EventQueue::Push(), ServerLog(), SetNonBlocking(), and Log::Write().

Referenced by Run().

bool Server::Boot (  unsigned short    port )  [virtual]
 

Boot initializes the Server and gets it ready to accept incoming Connections.

Returns :
true if server boots correctly, false if an error occurs.

Definition at line 41 of file server.cpp.

References mAcceptor, mNumFds, mTo, ServerLog(), SetNonBlocking(), and Log::Write().

Referenced by main().

void Server::InitFDs (    )  [private]
 

InitFDs initializes the server's select queue and then re-registers interest in all the connection's sockets in the server's user list including the server's listening port itself.

Note:
It may well be more efficient to register or unregister interest on a connection by connection basis in the various connection handling routines.
Remarks:
[1] On Windows, setting interest in all connected sockets for output will cause our select loop to spin. So we only set it if we know there is output waiting.

Definition at line 211 of file server.cpp.

References mAcceptor, mConns, mInputFDs, mNumFds, and mOutputFDs.

Referenced by Run().

Server& Server::operator= (  const Server &    )  [private]
 

void Server::ProcessQueue (    )  [private]
 

ProcessQueue attempts to process all the events contained in the eventqueue coming from our chat engine.

Remarks:
The are only two kinds of messages.
  • @shutdown - requests the server to shutdown
  • everything else is interpreted as public conversation
Todo:
Implement a disconnect request coming from driver. Allow specialized Telnet commands to come from driver, and filter them through the connection depending on whether it is capable.

Definition at line 244 of file server.cpp.

References CONNECT_E, DISCONNECT_E, Event::mClientId, mConns, Event::mDataLen, MESSAGE_E, Event::mEventType, mOutputFDs, Event::mpData, mrInQueue, mShutdown, NONE_E, EventQueue::Pop(), and SHUTDOWN_E.

Referenced by Run().

void Server::Run (  void *    parms )  [virtual]
 

Run starts the Server running to process incoming connection, input and output requests. It also executes commands from input requests.

/param parms Not used.

/note This should be where we begin threading. Not in Boot.

/todo Polling time should runtime reconfigurable.

Definition at line 103 of file server.cpp.

References AcceptConnection(), DISCONNECT_E, InitFDs(), mAcceptor, mConns, MESSAGE_E, mInputFDs, mNumFds, mOutputFDs, mrOutQueue, mShutdown, ProcessQueue(), EventQueue::Push(), ServerLog(), ShutdownServer(), and Log::Write().

Referenced by StartServer().

Log & Server::ServerLog (    ) 
 

ServerLog returns a reference to this server's logging utility so that messages can be written to it by its associates and aggregates.

Returns :
a reference to this server's Log

Definition at line 314 of file server.cpp.

References mrLog.

Referenced by AcceptConnection(), Boot(), Connection::Disconnect(), Connection::HandleInput(), Connection::HandleOutput(), Run(), SetNonBlocking(), and ShutdownServer().

bool Server::SetNonBlocking (  SOCKET    s )  [private]
 

ServerLog returns a reference to this server's logging utility so that messages can be written to it by its associates and aggregates.

Parameters:
s  The socket to be set non-blocking.
Returns :
true if successful, false if unsuccessful.

Definition at line 325 of file server.cpp.

References ServerLog(), and Log::Write().

Referenced by AcceptConnection(), and Boot().

void Server::ShutdownServer (    )  [private]
 

ShutdownServer requests each of the connections to disconnect in the server's user list, deletes the connections, and erases them from the user list. It then closes its own listening port.

Definition at line 291 of file server.cpp.

References DISCONNECT_E, mAcceptor, mConns, mrOutQueue, EventQueue::Push(), ServerLog(), SHUTDOWN_E, and Log::Write().

Referenced by Run().


Member Data Documentation

SOCKET Server::mAcceptor [private]
 

Listening socket for incoming connections.

Definition at line 47 of file server.h.

Referenced by AcceptConnection(), Boot(), InitFDs(), Run(), and ShutdownServer().

ConnList Server::mConns [private]
 

List of Connections managed by this server.

Definition at line 49 of file server.h.

Referenced by AcceptConnection(), InitFDs(), ProcessQueue(), Run(), ShutdownServer(), and ~Server().

fd_set Server::mInputFDs [private]
 

Array of input sockets that select will test.

Definition at line 45 of file server.h.

Referenced by InitFDs(), and Run().

int Server::mNumFds [private]
 

Definition at line 50 of file server.h.

Referenced by Boot(), InitFDs(), and Run().

fd_set Server::mOutputFDs [private]
 

Array of output sockets that select will test.

Definition at line 46 of file server.h.

Referenced by InitFDs(), ProcessQueue(), and Run().

EventQueue& Server::mrInQueue [private]
 

Incoming events.

Definition at line 53 of file server.h.

Referenced by ProcessQueue().

Log& Server::mrLog [private]
 

Server's log.

Definition at line 52 of file server.h.

Referenced by ServerLog().

EventQueue& Server::mrOutQueue [private]
 

Outgoing events.

Definition at line 54 of file server.h.

Referenced by AcceptConnection(), Run(), and ShutdownServer().

bool Server::mShutdown [private]
 

Flag to indicate that server is shutting down.

Definition at line 44 of file server.h.

Referenced by ProcessQueue(), and Run().

struct sockaddr_in Server::mTo [private]
 

Network address of the server port.

Definition at line 48 of file server.h.

Referenced by Boot().


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