Panda3D
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends

ConnectionManager Class Reference

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

#include "connectionManager.h"

Inheritance diagram for ConnectionManager:
PStatServer QueuedConnectionManager GtkStatsServer TextStats WinStatsServer

List of all members.

Public Member Functions

bool close_connection (const PT(Connection)&connection)
 Terminates a UDP or TCP socket previously opened.
 PT (Connection) open_TCP_server_rendezvous(int port
 PT (Connection) open_TCP_client_connection(const NetAddress &address
 PT (Connection) open_TCP_server_rendezvous(const NetAddress &address
 PT (Connection) open_TCP_server_rendezvous(const string &hostname
 PT (Connection) open_TCP_client_connection(const string &hostname
 PT (Connection) open_UDP_connection(int port=0)
bool wait_for_readers (double timeout)
 Blocks the process for timeout number of seconds, or until any data is available on any of the non-threaded ConnectionReaders or ConnectionListeners, whichever comes first.

Static Public Member Functions

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

Public Attributes

int backlog
int int backlog
int port
int int timeout_ms
int timeout_ms

Protected Types

typedef phash_set< PT(Connection) > Connections
typedef phash_set
< ConnectionReader
*, pointer_hash
Readers
typedef phash_set
< ConnectionWriter
*, pointer_hash
Writers

Protected Member Functions

void add_reader (ConnectionReader *reader)
 This internal function is called by ConnectionReader when it is constructed.
void add_writer (ConnectionWriter *writer)
 This internal function is called by ConnectionWriter when it is constructed.
virtual void connection_reset (const PT(Connection)&connection, bool okflag)
 An internal function called by the ConnectionReader, ConnectionWriter, or ConnectionListener when a connection has been externally reset.
virtual void flush_read_connection (Connection *connection)
 An internal function called by ConnectionWriter only when a write failure has occurred.
void new_connection (const PT(Connection)&connection)
 This internal function is called whenever a new connection is established.
void remove_reader (ConnectionReader *reader)
 This internal function is called by ConnectionReader when it is destructed.
void remove_writer (ConnectionWriter *writer)
 This internal function is called by ConnectionWriter when it is destructed.

Protected Attributes

Connections _connections
Readers _readers
LightMutex _set_mutex
Writers _writers

Friends

class Connection
class ConnectionListener
class ConnectionReader
class ConnectionWriter

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.

You may use this class directly if you don't care about tracking which connections have been unexpectedly closed; otherwise, you should use QueuedConnectionManager to get reports about these events (or derive your own class to handle these events properly).

Definition at line 46 of file connectionManager.h.


Member Function Documentation

void ConnectionManager::add_reader ( ConnectionReader reader) [protected]

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

Definition at line 540 of file connectionManager.cxx.

Referenced by ConnectionReader::ConnectionReader().

void ConnectionManager::add_writer ( ConnectionWriter writer) [protected]

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

Definition at line 564 of file connectionManager.cxx.

Referenced by ConnectionWriter::ConnectionWriter().

bool ConnectionManager::close_connection ( const PT(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 308 of file connectionManager.cxx.

References Socket_IP::Close(), Connection::flush(), and Connection::get_socket().

Referenced by PStatServer::connection_reset(), connection_reset(), PStatReader::lost_connection(), and MayaToEggServer::poll().

void ConnectionManager::connection_reset ( const PT(Connection)&  connection,
bool  okflag 
) [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.

Reimplemented in QueuedConnectionManager, and PStatServer.

Definition at line 512 of file connectionManager.cxx.

References close_connection().

void ConnectionManager::flush_read_connection ( Connection connection) [protected, virtual]

An internal function called by ConnectionWriter only when a write failure has occurred.

This method ensures that all of the read data has been flushed from the pipe before the connection is fully removed.

Definition at line 479 of file connectionManager.cxx.

References Socket_IP::Close(), and Connection::get_socket().

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 446 of file connectionManager.cxx.

void ConnectionManager::new_connection ( const PT(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 465 of file connectionManager.cxx.

Referenced by ConnectionListener::process_incoming_data().

void ConnectionManager::remove_reader ( ConnectionReader reader) [protected]

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

Definition at line 552 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 576 of file connectionManager.cxx.

bool ConnectionManager::wait_for_readers ( double  timeout)

Blocks the process for timeout number of seconds, or until any data is available on any of the non-threaded ConnectionReaders or ConnectionListeners, whichever comes first.

The return value is true if there is data available (but you have to iterate through all readers to find it), or false if the timeout occurred without any data.

If the timeout value is negative, this will block forever or until data is available.

This only works if all ConnectionReaders and ConnectionListeners are non-threaded. If any threaded ConnectionReaders are part of the ConnectionManager, the timeout value is implicitly treated as 0.

Definition at line 365 of file connectionManager.cxx.

References Socket_fdset::clear(), Thread::force_yield(), TrueClock::get_global_ptr(), and ConnectionReader::is_polling().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations