paradigm_3/html/
/*! \file server.h
  This is the Server class definition.
  It defines the traditional non-blocking select() server.

  \author Jon A. Lambert
  \date 05/02/2003
  \version 0.30
 */
#ifndef	SERVER_H
#define	SERVER_H

#include "connection.h"
#include "log.h"
#include "eventqueue.h"

//! ConnList is typedef'd here for ease of changing it later
typedef list<Connection*> ConnList;

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

  \notes
  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.
 */
class Server {
public:
  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:
  Server(const Server&);
  Server& operator=(const Server&);

  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.
  struct   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

  void AcceptConnection();
  void InitFDs ();
  void ProcessQueue();
  void ShutdownServer();
  bool SetNonBlocking(SOCKET s);
};

#endif // SERVER_H