Panda3D
|
The overall manager of the network connections. More...
#include "pStatServer.h"
Public Member Functions | |
void | add_reader (Connection *connection, PStatReader *reader) |
Adds the newly-created PStatReader to the list of currently active readers. | |
int | add_user_guide_bar (float height) |
Creates a new user guide bar and returns its index number. | |
bool | close_connection (const PT(Connection)&connection) |
Terminates a UDP or TCP socket previously opened. | |
int | find_user_guide_bar (float from_height, float to_height) const |
Returns the index number of the first user guide bar found whose height is within the indicated range, or -1 if no user guide bars fall within the range. | |
int | get_num_user_guide_bars () const |
Returns the current number of user-defined guide bars. | |
int | get_udp_port () |
Returns a new port number that will probably be free to use as a UDP port. | |
float | get_user_guide_bar_height (int n) const |
Returns the height of the nth user-defined guide bar. | |
virtual bool | is_thread_safe () |
This should be redefined to return true in derived classes that want to deal with multithreaded readers and such. | |
bool | listen (int port=-1) |
Establishes a port number that the manager will listen on for TCP connections. | |
void | main_loop (bool *interrupt_flag=NULL) |
An alternative to repeatedly calling poll(), this function yields control of the program to the PStatServer. | |
virtual PStatMonitor * | make_monitor ()=0 |
void | move_user_guide_bar (int n, float height) |
Adjusts the height of the nth user-defined guide bar. | |
void | poll () |
Checks for any network activity and handles it, if appropriate, and then returns. | |
PT (Connection) open_TCP_server_rendezvous(const NetAddress &address | |
PT (Connection) open_UDP_connection(int port=0) | |
PT (Connection) open_TCP_client_connection(const string &hostname | |
PT (Connection) open_TCP_server_rendezvous(int port | |
PT (Connection) open_TCP_server_rendezvous(const string &hostname | |
PT (Connection) open_TCP_client_connection(const NetAddress &address | |
void | release_udp_port (int port) |
Indicates that the given UDP port is once again free for use. | |
void | remove_reader (Connection *connection, PStatReader *reader) |
Removes the indicated reader. | |
void | remove_user_guide_bar (int n) |
Removes the user guide bar with the indicated index number. | |
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 | timeout_ms |
int int | timeout_ms |
Protected Types | |
typedef phash_set< PT(Connection) > | Connections |
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) |
Called when a lost connection is detected by the net code, this should pass the word on to the interested parties and clean up gracefully. | |
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 |
LightMutex | _set_mutex |
Writers | _writers |
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 41 of file pStatServer.h.
void PStatServer::add_reader | ( | Connection * | connection, |
PStatReader * | reader | ||
) |
Adds the newly-created PStatReader to the list of currently active readers.
Definition at line 156 of file pStatServer.cxx.
Referenced by PStatListener::connection_opened().
void ConnectionManager::add_reader | ( | ConnectionReader * | reader | ) | [protected, inherited] |
This internal function is called by ConnectionReader when it is constructed.
Definition at line 437 of file connectionManager.cxx.
Referenced by ConnectionReader::ConnectionReader().
int PStatServer::add_user_guide_bar | ( | float | height | ) |
Creates a new user guide bar and returns its index number.
Definition at line 247 of file pStatServer.cxx.
void ConnectionManager::add_writer | ( | ConnectionWriter * | writer | ) | [protected, inherited] |
This internal function is called by ConnectionWriter when it is constructed.
Definition at line 461 of file connectionManager.cxx.
Referenced by ConnectionWriter::ConnectionWriter().
bool ConnectionManager::close_connection | ( | const PT(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 300 of file connectionManager.cxx.
References Socket_IP::Close(), Connection::flush(), and Connection::get_socket().
Referenced by connection_reset(), ConnectionManager::connection_reset(), PStatReader::lost_connection(), and MayaToEggServer::poll().
void PStatServer::connection_reset | ( | const PT(Connection)& | connection, |
bool | okflag | ||
) | [protected, virtual] |
Called when a lost connection is detected by the net code, this should pass the word on to the interested parties and clean up gracefully.
Reimplemented from ConnectionManager.
Definition at line 332 of file pStatServer.cxx.
References ConnectionManager::close_connection().
int PStatServer::find_user_guide_bar | ( | float | from_height, |
float | to_height | ||
) | const |
Returns the index number of the first user guide bar found whose height is within the indicated range, or -1 if no user guide bars fall within the range.
Definition at line 277 of file pStatServer.cxx.
void ConnectionManager::flush_read_connection | ( | Connection * | connection | ) | [protected, virtual, inherited] |
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 376 of file connectionManager.cxx.
References Socket_IP::Close(), and Connection::get_socket().
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.
int PStatServer::get_num_user_guide_bars | ( | ) | const |
Returns the current number of user-defined guide bars.
Definition at line 213 of file pStatServer.cxx.
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 186 of file pStatServer.cxx.
Referenced by PStatReader::set_tcp_connection().
float PStatServer::get_user_guide_bar_height | ( | int | n | ) | const |
Returns the height of the nth user-defined guide bar.
Definition at line 223 of file pStatServer.cxx.
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 320 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 59 of file pStatServer.cxx.
References ConnectionReader::add_connection().
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 142 of file pStatServer.cxx.
References poll(), and Thread::sleep().
void PStatServer::move_user_guide_bar | ( | int | n, |
float | height | ||
) |
Adjusts the height of the nth user-defined guide bar.
Definition at line 234 of file pStatServer.cxx.
void ConnectionManager::new_connection | ( | const PT(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 362 of file connectionManager.cxx.
Referenced by ConnectionListener::process_incoming_data().
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 96 of file pStatServer.cxx.
References PStatReader::idle(), PStatReader::lost_connection(), and ConnectionReader::poll().
Referenced by main_loop().
void PStatServer::release_udp_port | ( | int | port | ) |
Indicates that the given UDP port is once again free for use.
Definition at line 202 of file pStatServer.cxx.
void ConnectionManager::remove_reader | ( | ConnectionReader * | reader | ) | [protected, inherited] |
This internal function is called by ConnectionReader when it is destructed.
Definition at line 449 of file connectionManager.cxx.
void PStatServer::remove_reader | ( | Connection * | connection, |
PStatReader * | reader | ||
) |
Removes the indicated reader.
Definition at line 166 of file pStatServer.cxx.
Referenced by PStatReader::close().
void PStatServer::remove_user_guide_bar | ( | int | n | ) |
Removes the user guide bar with the indicated index number.
All subsequent index numbers are adjusted down one.
Definition at line 263 of file pStatServer.cxx.
void ConnectionManager::remove_writer | ( | ConnectionWriter * | writer | ) | [protected, inherited] |
This internal function is called by ConnectionWriter when it is destructed.
Definition at line 473 of file connectionManager.cxx.