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

bool Boot (unsigned short port)
void Run ()

Static Public Methods

Server * Instance ()
void Destroy ()

Private Methods

 Server ()
 ~Server ()
 Server (const Server &)
Server & operator= (const Server &)
Connection * AcceptConnection ()
void InitFDs ()
void Execute ()
void ShutdownServer ()

Private Attributes

bool mShutdown
 flag indicating whether the 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
 socket that the Server listens to for incoming connections

sockaddr_in mTo
 network address of the server listening port

ConnList mUsers
 the list of Connections managed by the Server


Static Private Attributes

Server * sInstance = 0
 pointer to the singleton Server instance


Detailed Description

The Server class defines a singleton representation of a virtual network server.

Note:
No reason why this should be a singleton as long as different ports are served.

Todo:

Definition at line 35 of file server.h.


Constructor & Destructor Documentation

Server::Server (    )  [private]
 

Constructor for Server

Definition at line 22 of file server.cpp.

Server::~Server (    )  [private]
 

Destructor for Server

Definition at line 28 of file server.cpp.

References mUsers.

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


Member Function Documentation

Connection * Server::AcceptConnection (    )  [private]
 

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

Returns :
A pointer to the new connection

Definition at line 149 of file server.cpp.

References mAcceptor.

Referenced by Run().

bool Server::Boot (  unsigned short    port ) 
 

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 62 of file server.cpp.

References mAcceptor, and mTo.

Referenced by main().

void Server::Destroy (    )  [static]
 

Destroys the singleton instance of Server

Definition at line 51 of file server.cpp.

References sInstance.

Referenced by main().

void Server::Execute (    )  [private]
 

Execute processes the messages contained in all the input queues of all the connections in the server's user list.

Remarks:
The are only two kinds of messages.
  • @shutdown - requests the server to shutdown
  • everything else is interpreted as public conversation

Definition at line 195 of file server.cpp.

References mShutdown, and mUsers.

Referenced by Run().

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.

Definition at line 175 of file server.cpp.

References mAcceptor, mInputFDs, mOutputFDs, and mUsers.

Referenced by Run().

Server * Server::Instance (    )  [static]
 

Instance retrieves the singleton instance of Server

Returns :
A pointer to the singleton instance of Server

Definition at line 41 of file server.cpp.

References sInstance.

Referenced by main().

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

void Server::Run (    ) 
 

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

Definition at line 104 of file server.cpp.

References AcceptConnection(), Execute(), InitFDs(), mAcceptor, mInputFDs, mOutputFDs, mShutdown, mUsers, Connection::SendMsg(), and ShutdownServer().

Referenced by main().

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 224 of file server.cpp.

References mAcceptor, and mUsers.

Referenced by Run().


Member Data Documentation

SOCKET Server::mAcceptor [private]
 

socket that the Server listens to for incoming connections

Definition at line 64 of file server.h.

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

fd_set Server::mInputFDs [private]
 

array of input sockets that select will test

Definition at line 60 of file server.h.

Referenced by InitFDs(), and Run().

fd_set Server::mOutputFDs [private]
 

array of output sockets that select will test

Definition at line 62 of file server.h.

Referenced by InitFDs(), and Run().

bool Server::mShutdown [private]
 

flag indicating whether the server is shutting down

Definition at line 58 of file server.h.

Referenced by Execute(), and Run().

struct sockaddr_in Server::mTo [private]
 

network address of the server listening port

Definition at line 66 of file server.h.

Referenced by Boot().

ConnList Server::mUsers [private]
 

the list of Connections managed by the Server

Definition at line 68 of file server.h.

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

Server * Server::sInstance = 0 [static, private]
 

pointer to the singleton Server instance

Definition at line 14 of file server.cpp.

Referenced by Destroy(), and Instance().


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