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

QueuedConnectionManager Class Reference

This flavor of ConnectionManager will queue up all of the reset-connection messages from the ConnectionReaders and ConnectionWriters and report them to the client on demand. More...

#include <queuedConnectionManager.h>

Inheritance diagram for QueuedConnectionManager:

ConnectionManager QueuedReturn< PointerTo< Connection > > List of all members.

Public Member Functions

 QueuedConnectionManager ()
 ~QueuedConnectionManager ()
bool reset_connection_available () const
 Returns true if one of the readers/writers/listeners reported a connection reset recently.

bool get_reset_connection (PointerTo< Connection > &connection)
 If a previous call to reset_connection_available() returned true, this function will return information about the newly reset connection.

PointerTo< Connectionopen_UDP_connection (int port=0)
 Opens a socket for sending and/or receiving UDP packets.

PointerTo< Connectionopen_TCP_server_rendezvous (int port, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.

PointerTo< Connectionopen_TCP_client_connection (const NetAddress &address, int timeout_ms)
 Attempts to establish a TCP client connection to a server at the indicated address.

PointerTo< Connectionopen_TCP_client_connection (const string &hostname, int port, int timeout_ms)
 This is a shorthand version of the function to directly establish communcations to a named host and port.

bool close_connection (const PointerTo< Connection > &connection)
 Terminates a UDP or TCP socket previously opened.

void set_max_queue_size (int max_size)
int get_max_queue_size () const
int get_current_queue_size () const

Static Public Member Functions

string get_host_name ()
 Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.


Protected Types

typedef pset< PointerTo< Connection > > Connections
typedef pset< ConnectionReader * > Readers
typedef pset< ConnectionWriter * > Writers

Protected Member Functions

virtual void connection_reset (const PointerTo< Connection > &connection)
 An internal function called by the ConnectionReader, ConnectionWriter, or ConnectionListener when a connection has been externally reset.

void new_connection (const PointerTo< Connection > &connection)
 This internal function is called whenever a new connection is established.

void add_reader (ConnectionReader *reader)
 This internal function is called by ConnectionReader when it is constructed.

void remove_reader (ConnectionReader *reader)
 This internal function is called by ConnectionReader when it is destructed.

void add_writer (ConnectionWriter *writer)
 This internal function is called by ConnectionWriter when it is constructed.

void remove_writer (ConnectionWriter *writer)
 This internal function is called by ConnectionWriter when it is destructed.

bool thing_available () const
bool get_thing (PointerTo< Connection > &thing)
bool enqueue_thing (const PointerTo< Connection > &thing)
bool enqueue_unique_thing (const PointerTo< Connection > &thing)

Protected Attributes

Connections _connections
Readers _readers
Writers _writers
PRLock * _set_mutex

Detailed Description

This flavor of ConnectionManager will queue up all of the reset-connection messages from the ConnectionReaders and ConnectionWriters and report them to the client on demand.

When a reset connection has been discovered via reset_connection_available()/get_reset_connection(), it is still the responsibility of the client to call close_connection() on that connection to free up its resources.

Definition at line 60 of file queuedConnectionManager.h.


Member Typedef Documentation

typedef pset< PointerTo< Connection > > ConnectionManager::Connections [protected, inherited]
 

Definition at line 94 of file connectionManager.h.

typedef pset<ConnectionReader *> ConnectionManager::Readers [protected, inherited]
 

Definition at line 95 of file connectionManager.h.

typedef pset<ConnectionWriter *> ConnectionManager::Writers [protected, inherited]
 

Definition at line 96 of file connectionManager.h.


Constructor & Destructor Documentation

QueuedConnectionManager::QueuedConnectionManager  ) 
 

Definition at line 34 of file queuedConnectionManager.cxx.

QueuedConnectionManager::~QueuedConnectionManager  ) 
 

Definition at line 45 of file queuedConnectionManager.cxx.

References QueuedReturn< PointerTo< Connection > >::thing_available().


Member Function Documentation

void ConnectionManager::add_reader ConnectionReader reader  )  [protected, inherited]
 

This internal function is called by ConnectionReader when it is constructed.

Definition at line 386 of file connectionManager.cxx.

void ConnectionManager::add_writer ConnectionWriter writer  )  [protected, inherited]
 

This internal function is called by ConnectionWriter when it is constructed.

Definition at line 420 of file connectionManager.cxx.

bool ConnectionManager::close_connection const PointerTo< Connection > &  connection  )  [inherited]
 

Terminates a UDP or TCP socket previously opened.

This also removes it from any associated ConnectionReader or ConnectionListeners.

The socket itself may not be immediately closed--it will not be closed until all outstanding pointers to it are cleared, including any pointers remaining in NetDatagrams recently received from the socket.

The return value is true if the connection was marked to be closed, or false if close_connection() had already been called (or the connection did not belong to this ConnectionManager). In neither case can you infer anything about whether the connection has actually* been closed yet based on the return value.

Definition at line 294 of file connectionManager.cxx.

References ConnectionManager::_connections, and ConnectionManager::_set_mutex.

Referenced by HTTPClient::test_connection().

void QueuedConnectionManager::connection_reset const PointerTo< Connection > &  connection  )  [protected, virtual]
 

An internal function called by the ConnectionReader, ConnectionWriter, or ConnectionListener when a connection has been externally reset.

This adds the connection to the queue of those which have recently been reset.

Implements ConnectionManager.

Definition at line 150 of file queuedConnectionManager.cxx.

bool QueuedReturn< PointerTo< Connection > >::enqueue_thing const PointerTo< Connection > &  thing  )  [protected, inherited]
 

Adds a new thing to the queue for later retrieval.

Returns true if successful, false if the queue is full (i.e. has reached _max_queue_size).

bool QueuedReturn< PointerTo< Connection > >::enqueue_unique_thing const PointerTo< Connection > &  thing  )  [protected, inherited]
 

The same as enqueue_thing(), except the queue is first checked that it doesn't already have something like thing.

The return value is true if the enqueue operation was successful, false if the queue was full or the thing was already on the queue.

int QueuedReturn< PointerTo< Connection > >::get_current_queue_size  )  const [inherited]
 

Returns the current number of things in the queue.

string ConnectionManager::get_host_name  )  [static, inherited]
 

Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.

Definition at line 343 of file connectionManager.cxx.

References ConnectionManager::_set_mutex, ConnectionManager::_writers, and writer().

int QueuedReturn< PointerTo< Connection > >::get_max_queue_size  )  const [inherited]
 

Returns the maximum size the queue is allowed to grow to.

See set_max_queue_size().

bool QueuedConnectionManager::get_reset_connection PointerTo< Connection > &  connection  ) 
 

If a previous call to reset_connection_available() returned true, this function will return information about the newly reset connection.

Only connections which were externally reset are certain to appear in this list. Those which were explicitly closed via a call to close_connection() may or may not be reported. Furthermore, it is the responsibility of the caller to subsequently call close_connection() with any connection reported reset by this call. (There is no harm in calling close_connection() more than once on a given socket.)

The return value is true if a connection was successfully returned, or false if there was, in fact, no reset connection. (This may happen if there are multiple threads accessing the QueuedConnectionManager).

Definition at line 128 of file queuedConnectionManager.cxx.

bool QueuedReturn< PointerTo< Connection > >::get_thing PointerTo< Connection > &  thing  )  [protected, inherited]
 

If a previous call to thing_available() returned true, this function will return the thing that has become available.

The return value is true if a thing was successfully returned, or false if there was, in fact, no thing available. (This may happen if there are multiple threads accessing the QueuedReturn).

Referenced by reset_connection_available().

void ConnectionManager::new_connection const PointerTo< Connection > &  connection  )  [protected, inherited]
 

This internal function is called whenever a new connection is established.

It allows the ConnectionManager to save all of the pointers to open connections so they can't be inadvertently deleted until close_connection() is called.

Definition at line 369 of file connectionManager.cxx.

PointerTo< Connection > ConnectionManager::open_TCP_client_connection const string &  hostname,
int  port,
int  timeout_ms
[inherited]
 

This is a shorthand version of the function to directly establish communcations to a named host and port.

Definition at line 247 of file connectionManager.cxx.

References ConnectionManager::_readers.

PointerTo< Connection > ConnectionManager::open_TCP_client_connection const NetAddress address,
int  timeout_ms
[inherited]
 

Attempts to establish a TCP client connection to a server at the indicated address.

If the connection is not established within timeout_ms milliseconds, a null connection is returned.

Definition at line 205 of file connectionManager.cxx.

References PT, and NetAddress::set_host().

PointerTo< Connection > ConnectionManager::open_TCP_server_rendezvous int  port,
int  backlog
[inherited]
 

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.

The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

backlog is the maximum length of the queue of pending connections.

Definition at line 154 of file connectionManager.cxx.

PointerTo< Connection > ConnectionManager::open_UDP_connection int  port = 0  )  [inherited]
 

Opens a socket for sending and/or receiving UDP packets.

If the port number is negative, it will not be bound to a socket; this is generally a pointless thing to do. If the port number is zero, a random socket will be chosen. Otherwise, the specified port number is used. Normally, you don't care what port a UDP connection is opened on, so you should use the default value of zero.

Use a ConnectionReader and ConnectionWriter to handle the actual communication.

Definition at line 100 of file connectionManager.cxx.

void ConnectionManager::remove_reader ConnectionReader reader  )  [protected, inherited]
 

This internal function is called by ConnectionReader when it is destructed.

Definition at line 403 of file connectionManager.cxx.

void ConnectionManager::remove_writer ConnectionWriter writer  )  [protected, inherited]
 

This internal function is called by ConnectionWriter when it is destructed.

Definition at line 437 of file connectionManager.cxx.

bool QueuedConnectionManager::reset_connection_available  )  const
 

Returns true if one of the readers/writers/listeners reported a connection reset recently.

If so, the particular connection that has been reset can be extracted via get_reset_connection().

Only connections which were externally reset are certain to appear in this list. Those which were explicitly closed via a call to close_connection() may or may not be reported. Furthermore, it is the responsibility of the caller to subsequently call close_connection() with any connection reported reset by this call. (There is no harm in calling close_connection() more than once on a given socket.)

Definition at line 81 of file queuedConnectionManager.cxx.

References QueuedReturn< PointerTo< Connection > >::get_thing().

void QueuedReturn< PointerTo< Connection > >::set_max_queue_size int  max_size  )  [inherited]
 

Sets the maximum size the queue is allowed to grow to.

This is primarily for a sanity check; this is a limit beyond which we can assume something bad has happened.

It's also a crude check against unfortunate seg faults due to the queue filling up and quietly consuming all available memory.

bool QueuedReturn< PointerTo< Connection > >::thing_available  )  const [inline, protected, inherited]
 

Returns true if a thing is available on the queue; call get_thing() to extract the thing.

Referenced by ~QueuedConnectionManager().


Member Data Documentation

Connections ConnectionManager::_connections [protected, inherited]
 

Definition at line 97 of file connectionManager.h.

Referenced by ConnectionManager::close_connection().

Readers ConnectionManager::_readers [protected, inherited]
 

Definition at line 98 of file connectionManager.h.

Referenced by ConnectionManager::ConnectionManager(), and ConnectionManager::open_TCP_client_connection().

PRLock* ConnectionManager::_set_mutex [protected, inherited]
 

Definition at line 100 of file connectionManager.h.

Referenced by ConnectionManager::close_connection(), and ConnectionManager::get_host_name().

Writers ConnectionManager::_writers [protected, inherited]
 

Definition at line 99 of file connectionManager.h.

Referenced by ConnectionManager::get_host_name(), and ConnectionManager::~ConnectionManager().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:54:33 2003 for Panda by doxygen1.3