15 #ifndef CONNECTIONMANAGER_H
16 #define CONNECTIONMANAGER_H
18 #include "pandabase.h"
20 #include "netDatagram.h"
21 #include "connection.h"
22 #include "pointerTo.h"
25 #include "lightMutex.h"
52 PT(
Connection) open_UDP_connection(
int port = 0);
53 PT(
Connection) open_UDP_connection(
const string &hostname,
int port,
bool for_broadcast =
false);
55 BLOCKING PT(
Connection) open_TCP_server_rendezvous(
int port,
int backlog);
56 BLOCKING PT(
Connection) open_TCP_server_rendezvous(
const string &hostname,
57 int port,
int backlog);
62 BLOCKING PT(
Connection) open_TCP_client_connection(
const string &hostname,
int port,
65 bool close_connection(
const PT(
Connection) &connection);
66 BLOCKING
bool wait_for_readers(
double timeout);
68 static string get_host_name();
72 const string &get_name()
const {
return _name; }
73 const string &get_mac_address()
const {
return _mac_address; }
74 bool has_ip()
const {
return (_flags & F_has_ip) != 0; }
75 const NetAddress &get_ip()
const {
return _ip; }
76 bool has_netmask()
const {
return (_flags & F_has_netmask) != 0; }
77 const NetAddress &get_netmask()
const {
return _netmask; }
78 bool has_broadcast()
const {
return (_flags & F_has_broadcast) != 0; }
79 const NetAddress &get_broadcast()
const {
return _broadcast; }
80 bool has_p2p()
const {
return (_flags & F_has_p2p) != 0; }
81 const NetAddress &get_p2p()
const {
return _p2p; }
83 void output(ostream &out)
const;
87 void set_name(
const string &name) { _name = name; }
88 void set_mac_address(
const string &mac_address) { _mac_address = mac_address; }
89 void set_ip(
const NetAddress &ip) { _ip = ip; _flags |= F_has_ip; }
90 void set_netmask(
const NetAddress &ip) { _netmask = ip; _flags |= F_has_netmask; }
91 void set_broadcast(
const NetAddress &ip) { _broadcast = ip; _flags |= F_has_broadcast; }
92 void set_p2p(
const NetAddress &ip) { _p2p = ip; _flags |= F_has_p2p; }
106 F_has_netmask = 0x002,
107 F_has_broadcast = 0x004,
112 void scan_interfaces();
113 int get_num_interfaces();
115 MAKE_SEQ(get_interfaces, get_num_interfaces, get_interface);
118 void new_connection(
const PT(
Connection) &connection);
119 virtual void flush_read_connection(
Connection *connection);
120 virtual void connection_reset(
const PT(
Connection) &connection,
128 string format_mac_address(
const unsigned char *data,
int data_size);
130 typedef phash_set< PT(Connection) > Connections;
131 typedef phash_set<ConnectionReader *, pointer_hash> Readers;
132 typedef phash_set<ConnectionWriter *, pointer_hash> Writers;
133 Connections _connections;
140 bool _interfaces_scanned;
The primary interface to the low-level networking layer in this package.
This is an abstract base class for a family of classes that listen for activity on a socket and respo...
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Represents a single TCP or UDP socket for input or output.
This is a special kind of ConnectionReader that waits for activity on a rendezvous port and accepts a...
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...