Panda3D
|
The primary interface to the low-level networking layer in this package. More...
#include "connectionManager.h"
Classes | |
class | Interface |
Public Member Functions | |
bool | close_connection (const PT(Connection) &connection) |
Terminates a UDP or TCP socket previously opened. More... | |
const Interface & | get_interface (int n) |
Returns the nth usable network interface detected on this machine. More... | |
int | get_num_interfaces () |
This returns the number of usable network interfaces detected on this machine. More... | |
MAKE_SEQ (get_interfaces, get_num_interfaces, get_interface) | |
PT (Connection) open_UDP_connection(int port=0) | |
PT (Connection) open_UDP_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_server_rendezvous(const NetAddress &address | |
PT (Connection) open_TCP_client_connection(const NetAddress &address | |
PT (Connection) open_TCP_client_connection(const string &hostname | |
void | scan_interfaces () |
Repopulates the list reported by get_num_interface()/get_interface(). More... | |
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. More... | |
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. More... | |
Public Attributes | |
int | backlog |
int int | backlog |
int bool | for_broadcast = false) |
int | port |
int | timeout_ms |
int int | timeout_ms |
Friends | |
class | Connection |
class | ConnectionListener |
class | ConnectionReader |
class | ConnectionWriter |
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 47 of file connectionManager.h.
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 369 of file connectionManager.cxx.
References Socket_IP::Close(), Connection::flush(), Connection::get_socket(), and wait_for_readers().
Referenced by PStatServer::is_thread_safe(), and MayaToEggServer::poll().
|
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 507 of file connectionManager.cxx.
References scan_interfaces().
Referenced by PStatReader::get_monitor(), and wait_for_readers().
const ConnectionManager::Interface & ConnectionManager::get_interface | ( | int | n | ) |
Returns the nth usable network interface detected on this machine.
(Currently, only IPv4 interfaces are reported.) See scan_interfaces() to repopulate this list.
Definition at line 656 of file connectionManager.cxx.
References Socket_IP::Close(), and Connection::get_socket().
Referenced by get_num_interfaces().
int ConnectionManager::get_num_interfaces | ( | ) |
This returns the number of usable network interfaces detected on this machine.
(Currently, only IPv4 interfaces are reported.) See scan_interfaces() to repopulate this list.
Definition at line 639 of file connectionManager.cxx.
References get_interface().
Referenced by scan_interfaces().
void ConnectionManager::scan_interfaces | ( | ) |
Repopulates the list reported by get_num_interface()/get_interface().
It is not necessary to call this explicitly, unless you want to re-determine the connected interfaces (for instance, if you suspect the hardware has recently changed).
Definition at line 526 of file connectionManager.cxx.
References NetAddress::get_ip(), get_num_interfaces(), TextEncoder::get_text(), Socket_Address::set_host(), and TextEncoder::set_wtext().
Referenced by get_host_name().
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 426 of file connectionManager.cxx.
References Socket_fdset::clear(), Thread::force_yield(), TrueClock::get_global_ptr(), get_host_name(), and ConnectionReader::is_polling().
Referenced by close_connection().