Panda3D
|
The primary interface to the low-level networking layer in this package. More...
#include "connectionManager.h"
Classes | |
class | Interface |
Public Member Functions | |
PT(Connection) open_TCP_client_connection(const std bool | close_connection (const PT(Connection) &connection) |
Terminates a UDP or TCP socket previously opened. | |
const Interface & | get_interface (size_t n) |
size_t | get_num_interfaces () |
PT (Connection) open_TCP_client_connection(const NetAddress &address | |
PT(Connection) open_TCP_server_rendezvous(const std | PT (Connection) open_TCP_server_rendezvous(const NetAddress &address |
PT(Connection) open_UDP_connection(const std | PT (Connection) open_TCP_server_rendezvous(uint16_t port |
PT (Connection) open_UDP_connection(uint16_t port=0) | |
void | scan_interfaces () |
Repopulates the list reported by get_num_interface()/get_interface(). | |
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 std::string | get_host_name () |
Public Attributes | |
PT(Connection) open_UDP_connection(const std int | backlog |
PT(Connection) open_TCP_server_rendezvous(const std int | backlog |
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. | |
get_interface | |
Returns the nth usable network interface detected on this machine. | |
get_num_interfaces | |
This returns the number of usable network interfaces detected on this machine. | |
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 41 of file connectionManager.h.
ConnectionManager::ConnectionManager | ( | ) |
Definition at line 42 of file connectionManager.cxx.
|
virtual |
Definition at line 51 of file connectionManager.cxx.
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 332 of file connectionManager.cxx.
References Socket_IP::Close(), Connection::flush(), and Connection::get_socket().
Referenced by DirectD::disconnect_from(), PStatReader::lost_connection(), and MayaToEggServer::poll().
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 475 of file connectionManager.cxx.
References NetAddress::get_ip(), TextEncoder::get_text, Socket_Address::set_host(), and TextEncoder::set_wtext().
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 382 of file connectionManager.cxx.
References Socket_fdset::clear(), Thread::force_yield(), TrueClock::get_global_ptr(), and ConnectionReader::is_polling().
|
friend |
Definition at line 143 of file connectionManager.h.
|
friend |
Definition at line 142 of file connectionManager.h.
|
friend |
Definition at line 140 of file connectionManager.h.
|
friend |
Definition at line 141 of file connectionManager.h.
PT(Connection) open_UDP_connection(const std int ConnectionManager::backlog |
Definition at line 49 of file connectionManager.h.
PT(Connection) open_TCP_server_rendezvous(const std int ConnectionManager::backlog |
Definition at line 53 of file connectionManager.h.
string ConnectionManager::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.
Definition at line 111 of file connectionManager.h.
const ConnectionManager::Interface & ConnectionManager::get_interface |
Returns the nth usable network interface detected on this machine.
See scan_interfaces() to repopulate this list.
Definition at line 109 of file connectionManager.h.
size_t ConnectionManager::get_num_interfaces |
This returns the number of usable network interfaces detected on this machine.
See scan_interfaces() to repopulate this list.
Definition at line 109 of file connectionManager.h.
int ConnectionManager::timeout_ms |
Definition at line 55 of file connectionManager.h.