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

PStatServer Class Reference

The overall manager of the network connections. More...

#include <pStatServer.h>

Inheritance diagram for PStatServer:

ConnectionManager GtkStatsServer TextStats List of all members.

Public Member Functions

 PStatServer ()
 ~PStatServer ()
bool listen (int port=-1)
 Establishes a port number that the manager will listen on for TCP connections.

void poll ()
 Checks for any network activity and handles it, if appropriate, and then returns.

void main_loop (bool *interrupt_flag=NULL)
 An alternative to repeatedly calling poll(), this function yields control of the program to the PStatServer.

virtual PStatMonitormake_monitor ()=0
void add_reader (Connection *connection, PStatReader *reader)
 Adds the newly-created PStatReader to the list of currently active readers.

void remove_reader (Connection *connection, PStatReader *reader)
 Removes the indicated reader.

int get_udp_port ()
 Returns a new port number that will probably be free to use as a UDP port.

void release_udp_port (int port)
 Indicates that the given UDP port is once again free for use.

virtual bool is_thread_safe ()
 This should be redefined to return true in derived classes that want to deal with multithreaded readers and such.

PointerTo< Connectionopen_UDP_connection (int port=0)
PointerTo< Connectionopen_TCP_server_rendezvous (int port, int backlog)
PointerTo< Connectionopen_TCP_client_connection (const NetAddress &address, int timeout_ms)
PointerTo< Connectionopen_TCP_client_connection (const string &hostname, int port, int timeout_ms)
bool close_connection (const PointerTo< Connection > &connection)
void new_connection (const PointerTo< Connection > &connection)
virtual void connection_reset (const PointerTo< Connection > &connection)=0
void add_reader (ConnectionReader *reader)
void remove_reader (ConnectionReader *reader)
void add_writer (ConnectionWriter *writer)
void remove_writer (ConnectionWriter *writer)

Static Public Member Functions

string get_host_name ()

Public Attributes

pset< PointerTo< Connection > > Connections
pset< ConnectionWriter * > Writers
Connections _connections
Writers _writers
PRLock * _set_mutex

Private Types

typedef pmap< PT(Connection),
PStatReader
Readers )
typedef pvector< PStatReader * > LostReaders
typedef pdeque< intPorts

Private Member Functions

virtual void connection_reset (const PT(Connection)&connection)

Private Attributes

PStatListener_listener
Readers _readers
LostReaders _lost_readers
LostReaders _removed_readers
Ports _available_udp_ports
int _next_udp_port

Friends

class ConnectionReader
class ConnectionWriter
class ConnectionListener
class Connection

Detailed Description

The overall manager of the network connections.

This class gets the ball rolling; to use this package, you need to derive from this and define make_monitor() to allocate and return a PStatMonitor of the suitable type.

Then create just one PStatServer object and call listen() with the port(s) you would like to listen on. It will automatically create PStatMonitors as connections are established and mark the connections closed as they are lost.

Definition at line 63 of file pStatServer.h.


Member Typedef Documentation

typedef pvector<PStatReader *> PStatServer::LostReaders [private]
 

Definition at line 89 of file pStatServer.h.

typedef pdeque<int> PStatServer::Ports [private]
 

Definition at line 93 of file pStatServer.h.

typedef pmap<PT(Connection), PStatReader * PStatServer::Readers) [private]
 

Reimplemented from ConnectionManager.

Definition at line 87 of file pStatServer.h.


Constructor & Destructor Documentation

PStatServer::PStatServer  ) 
 

Definition at line 35 of file pStatServer.cxx.

References _listener.

PStatServer::~PStatServer  ) 
 

Definition at line 48 of file pStatServer.cxx.

References _listener, _next_udp_port, ConnectionListener::add_connection(), ConnectionManager::open_TCP_server_rendezvous(), pstats_port, and PT.


Member Function Documentation

void PStatServer::add_reader Connection connection,
PStatReader reader
 

Adds the newly-created PStatReader to the list of currently active readers.

Definition at line 202 of file pStatServer.cxx.

References _available_udp_ports.

Referenced by PStatListener::PStatListener().

virtual void PStatServer::connection_reset const PT(Connection)&  connection  )  [private, virtual]
 

int PStatServer::get_udp_port  ) 
 

Returns a new port number that will probably be free to use as a UDP port.

The caller should be prepared to accept the possibility that it will be already in use by another process, however.

Definition at line 241 of file pStatServer.cxx.

References _lost_readers, _readers, and reader().

Referenced by PStatReader::close().

bool PStatServer::is_thread_safe  )  [virtual]
 

This should be redefined to return true in derived classes that want to deal with multithreaded readers and such.

If this returns true, the manager will create the listener in its own thread, and thus the PStatReader constructors at least will run in a different thread.

This is not related to the question of whether the reader can handle multiple different PStatThreadDatas; it's strictly a question of whether the readers themselves can run in a separate thread.

Definition at line 294 of file pStatServer.cxx.

bool PStatServer::listen int  port = -1  ) 
 

Establishes a port number that the manager will listen on for TCP connections.

This may be called more than once to listen simulataneously on multiple connections, as if that were at all useful.

The default parameter, -1, indicates the use of whatever port number has been indicated in the Config file.

This function returns true if the port was successfully opened, or false if it could not open the port.

Definition at line 84 of file pStatServer.cxx.

References _listener, _lost_readers, _readers, _removed_readers, ConnectionListener::poll(), and reader().

Referenced by TextStats::make_monitor().

void PStatServer::main_loop bool *  interrupt_flag = NULL  ) 
 

An alternative to repeatedly calling poll(), this function yields control of the program to the PStatServer.

It does not return until the program is done.

If interrupt_flag is non-NULL, it is the address of a bool variable that is initially false, and may be asynchronously set true to indicate the loop should terminate.

Definition at line 181 of file pStatServer.cxx.

References _available_udp_ports, and _next_udp_port.

virtual PStatMonitor* PStatServer::make_monitor  )  [pure virtual]
 

Implemented in GtkStatsServer, and TextStats.

Referenced by PStatListener::PStatListener().

void PStatServer::poll  ) 
 

Checks for any network activity and handles it, if appropriate, and then returns.

This must be called periodically unless is_thread_safe() is redefined to return true on this class and also on all PStatMonitors in use.

Alternatively, a program may call main_loop() and yield control of the program entirely to the PStatServer.

Definition at line 132 of file pStatServer.cxx.

References NULL.

void PStatServer::release_udp_port int  port  ) 
 

Indicates that the given UDP port is once again free for use.

Definition at line 261 of file pStatServer.cxx.

void PStatServer::remove_reader Connection connection,
PStatReader reader
 

Removes the indicated reader.

Definition at line 215 of file pStatServer.cxx.

Referenced by PStatReader::~PStatReader().


Member Data Documentation

Ports PStatServer::_available_udp_ports [private]
 

Definition at line 94 of file pStatServer.h.

Referenced by add_reader(), and main_loop().

PStatListener* PStatServer::_listener [private]
 

Definition at line 85 of file pStatServer.h.

Referenced by listen(), PStatServer(), and ~PStatServer().

LostReaders PStatServer::_lost_readers [private]
 

Definition at line 90 of file pStatServer.h.

Referenced by get_udp_port(), and listen().

int PStatServer::_next_udp_port [private]
 

Definition at line 95 of file pStatServer.h.

Referenced by main_loop(), and ~PStatServer().

Readers PStatServer::_readers [private]
 

Reimplemented from ConnectionManager.

Definition at line 88 of file pStatServer.h.

Referenced by get_udp_port(), and listen().

LostReaders PStatServer::_removed_readers [private]
 

Definition at line 91 of file pStatServer.h.

Referenced by listen().


The documentation for this class was generated from the following files:
Generated on Fri May 2 03:27:52 2003 for Panda-Tool by doxygen1.3