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

ConnectionManager Class Reference

The primary interface to the low-level networking layer in this package. More...

#include <connectionManager.h>

Inheritance diagram for ConnectionManager:

QueuedConnectionManager List of all members.

Public Member Functions

 ConnectionManager ()
virtual ~ConnectionManager ()
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.


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

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

virtual void connection_reset (const PointerTo< Connection > &connection)=0
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.


Protected Attributes

Connections _connections
Readers _readers
Writers _writers
PRLock * _set_mutex

Friends

class ConnectionReader
class ConnectionWriter
class ConnectionListener
class Connection

Detailed Description

The primary interface to the low-level networking layer in this package.

A ConnectionManager is used to establish and destroy TCP and UDP connections. Communication on these connections, once established, is handled via ConnectionReader, ConnectionWriter, and ConnectionListener.

This is actually an abstract class, since it does not define what to do when a connection is externally reset (i.e. closed on the other end, or dropped because of network errors). See QueuedConnectionManager.

Definition at line 68 of file connectionManager.h.


Member Typedef Documentation

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

Definition at line 94 of file connectionManager.h.

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

Definition at line 95 of file connectionManager.h.

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

Definition at line 96 of file connectionManager.h.


Constructor & Destructor Documentation

ConnectionManager::ConnectionManager  ) 
 

Definition at line 44 of file connectionManager.cxx.

References _readers.

ConnectionManager::~ConnectionManager  )  [virtual]
 

Definition at line 56 of file connectionManager.cxx.

References _writers.


Member Function Documentation

void ConnectionManager::add_reader ConnectionReader reader  )  [protected]
 

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]
 

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  ) 
 

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 _connections, and _set_mutex.

Referenced by HTTPClient::test_connection().

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

Implemented in QueuedConnectionManager.

Referenced by ConnectionReader::process_incoming_data().

string ConnectionManager::get_host_name  )  [static]
 

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 _set_mutex, _writers, and writer().

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

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
 

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

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

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
 

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  ) 
 

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]
 

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]
 

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

Definition at line 437 of file connectionManager.cxx.


Friends And Related Function Documentation

friend class Connection [friend]
 

Definition at line 106 of file connectionManager.h.

friend class ConnectionListener [friend]
 

Definition at line 105 of file connectionManager.h.

friend class ConnectionReader [friend]
 

Definition at line 103 of file connectionManager.h.

friend class ConnectionWriter [friend]
 

Definition at line 104 of file connectionManager.h.


Member Data Documentation

Connections ConnectionManager::_connections [protected]
 

Definition at line 97 of file connectionManager.h.

Referenced by close_connection().

Readers ConnectionManager::_readers [protected]
 

Definition at line 98 of file connectionManager.h.

Referenced by ConnectionManager(), and open_TCP_client_connection().

PRLock* ConnectionManager::_set_mutex [protected]
 

Definition at line 100 of file connectionManager.h.

Referenced by close_connection(), and get_host_name().

Writers ConnectionManager::_writers [protected]
 

Definition at line 99 of file connectionManager.h.

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


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