00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CONNECTIONMANAGER_H
00016 #define CONNECTIONMANAGER_H
00017
00018 #include "pandabase.h"
00019
00020 #include "netDatagram.h"
00021 #include "connection.h"
00022 #include "pointerTo.h"
00023 #include "pset.h"
00024 #include "lightMutex.h"
00025
00026 class NetAddress;
00027 class ConnectionReader;
00028 class ConnectionWriter;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class EXPCL_PANDA_NET ConnectionManager {
00047 PUBLISHED:
00048 ConnectionManager();
00049 virtual ~ConnectionManager();
00050
00051 PT(Connection) open_UDP_connection(int port = 0);
00052
00053 BLOCKING PT(Connection) open_TCP_server_rendezvous(int port, int backlog);
00054 BLOCKING PT(Connection) open_TCP_server_rendezvous(const string &hostname,
00055 int port, int backlog);
00056 BLOCKING PT(Connection) open_TCP_server_rendezvous(const NetAddress &address,
00057 int backlog);
00058 BLOCKING PT(Connection) open_TCP_client_connection(const NetAddress &address,
00059 int timeout_ms);
00060 BLOCKING PT(Connection) open_TCP_client_connection(const string &hostname, int port,
00061 int timeout_ms);
00062
00063 bool close_connection(const PT(Connection) &connection);
00064 BLOCKING bool wait_for_readers(double timeout);
00065
00066 static string get_host_name();
00067
00068 protected:
00069 void new_connection(const PT(Connection) &connection);
00070 virtual void flush_read_connection(Connection *connection);
00071 virtual void connection_reset(const PT(Connection) &connection,
00072 bool okflag);
00073
00074 void add_reader(ConnectionReader *reader);
00075 void remove_reader(ConnectionReader *reader);
00076 void add_writer(ConnectionWriter *writer);
00077 void remove_writer(ConnectionWriter *writer);
00078
00079 typedef phash_set< PT(Connection) > Connections;
00080 typedef phash_set<ConnectionReader *, pointer_hash> Readers;
00081 typedef phash_set<ConnectionWriter *, pointer_hash> Writers;
00082 Connections _connections;
00083 Readers _readers;
00084 Writers _writers;
00085 LightMutex _set_mutex;
00086
00087 private:
00088 friend class ConnectionReader;
00089 friend class ConnectionWriter;
00090 friend class ConnectionListener;
00091 friend class Connection;
00092 };
00093
00094 #endif