1 #if !defined(_NETWORKMANAGER_H_) 2 #define _NETWORKMANAGER_H_ 6 #include "NetworkConnections.h" 7 #include "NetworkProtocols.h" 50 static bool UnitTest();
51 static bool UnitTestDelayedConnect();
52 static bool UnitTestHTTP();
53 static bool TestHTTP(
const char* host, uint32 port, std::vector<std::string> &urls);
55 THREAD_RET THREAD_FUNCTION_CALL NetworkManagerRun(THREAD_ARG arg);
60 bool setSSLCertificate(
const char* sslCertPath,
const char* sslKeyPath);
62 NetworkChannel* createListener(uint16 port, uint8 encryption, uint8 protocol,
bool isAsync, uint32 protocolTimeout,
bool isDefaultProtocol, uint32 channelID,
NetworkReceiver* recv);
63 NetworkChannel* createTCPConnection(
const char* addr, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync,
bool autoreconnect, uint32 channelID,
NetworkReceiver* recv, uint64& conid, uint64& location, uint32 timeoutMS = 5000);
64 NetworkChannel* createTCPConnection(uint64 location, uint8 encryption, uint8 protocol,
bool isAsync,
bool autoreconnect, uint32 channelID,
NetworkReceiver* recv, uint64& conid, uint32 timeoutMS = 5000);
65 NetworkChannel* createTCPConnection(
const uint32* addresses, uint16 addressCount, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync,
bool autoreconnect, uint32 channelID,
NetworkReceiver* recv, uint64& conid, uint64& location, uint32 timeoutMS = 5000);
66 NetworkChannel* createUDPConnection(uint16 port, uint8 protocol,
bool isAsync,
bool autoreconnect, uint32 channelID,
NetworkReceiver* recv, uint64& conid);
67 NetworkChannel* addTCPConnection(
const char* addr, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync, uint32 channelID,
NetworkReceiver* recv, uint64& conid, uint64& location, uint32 timeoutMS = 5000,
const char* greetingData = NULL, uint32 greetingSize = 0);
68 NetworkChannel* addTCPConnection(uint64 location, uint8 encryption, uint8 protocol,
bool isAsync, uint32 channelID,
NetworkReceiver* recv, uint64& conid, uint32 timeoutMS = 5000,
const char* greetingData = NULL, uint32 greetingSize = 0);
70 bool stopListener(uint16 port, uint8 protocol);
71 bool endConnection(uint64 conid);
72 bool endUDPConnection(uint16 port);
74 uint8 getConnectionType(uint64 conid);
75 uint64 getRemoteAddress(uint64 conid);
81 bool sendUDPMessage(
DataMessage* msg, uint64 destination);
83 HTTPReply* makeHTTPRequest(
const char* url, uint32 timeout,
const char* content = NULL, uint32 contentSize = 0);
84 HTTPReply* makeHTTPRequest(
HTTPRequest* req,
const char* addr, uint16 port, uint8 encryption, uint32 timeout);
87 std::map<uint32, NetworkChannel*> channels;
88 std::map<uint64, NetworkChannel*> channelsByConnection;
89 std::map<uint16, NetworkChannel*> listeners;
90 std::map<uint16, NetworkChannel*> udpListeners;
92 std::string sslCertPath;
93 std::string sslKeyPath;
99 uint64 lastConnectionID;
107 #define NETWORKEVENT_CONNECT 1 108 #define NETWORKEVENT_RECONNECT 2 109 #define NETWORKEVENT_DISCONNECT 3 110 #define NETWORKEVENT_DISCONNECT_RETRYING 4 111 #define NETWORKEVENT_BUFFER_LOW 5 112 #define NETWORKEVENT_BUFFER_FULL 6 113 #define NETWORKEVENT_UNPROCESSED_DATA 7 125 uint32 defaultProtocol;
126 uint32 autoProtocols;
127 uint32 autoProtocolTimeout;
143 bool isConnected(uint64 conid);
148 bool startListener(uint64 cid, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync, uint32 protocolTimeout = 3000,
bool isDefaultProtocol =
false);
149 bool stopListener(uint16 port, uint8 protocol);
151 uint64 createTCPConnection(
const char* addr, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync,
bool autoreconnect, uint64& location, uint32 timeoutMS = 5000);
152 uint64 createTCPConnection(uint64 location, uint8 encryption, uint8 protocol,
bool isAsync,
bool autoreconnect, uint32 timeoutMS = 5000);
153 uint64 createTCPConnection(
const uint32* addresses, uint16 addressCount, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync,
bool autoreconnect, uint64& location, uint32 timeoutMS = 5000);
154 uint64 createUDPConnection(uint16 port, uint8 protocol,
bool isAsync,
bool autoreconnect);
155 uint64 addTCPConnection(
const char* addr, uint16 port, uint8 encryption, uint8 protocol,
bool isAsync, uint64& location, uint32 timeoutMS = 5000,
const char* greetingData = NULL, uint32 greetingSize = 0);
156 uint64 addTCPConnection(uint64 location, uint8 encryption, uint8 protocol,
bool isAsync, uint32 timeoutMS = 5000,
const char* greetingData = NULL, uint32 greetingSize = 0);
157 bool endConnection(uint64 conid);
158 bool endUDPConnection(uint16 port);
159 uint8 getConnectionType(uint64 conid);
160 uint64 getRemoteAddress(uint64 conid);
162 uint64 autoDetectConnection(
NetworkConnection* con, uint16 port, uint32 autoProtocols, uint32 autoProtocolTimeout, uint32 defaultProtocol,
bool isAsync,
bool autoreconnect);
164 uint64 startConnection(
NetworkConnection* con, uint8 protocol,
bool isAsync,
bool autoreconnect, uint32 timeoutMS = 5000);
170 HTTPRequest* waitForHTTPRequest(uint64& conid, uint32 ms);
171 TelnetLine* waitForTelnetLine(uint64& conid, uint32 ms);
172 DataMessage* waitForMessage(uint64& conid, uint32 ms);
173 HTTPReply* waitForHTTPReply(uint64& conid, uint32 ms);
175 bool sendHTTPReply(
HTTPReply* reply, uint64 conid);
176 bool sendTelnetLine(
TelnetLine* line, uint64 conid);
178 bool sendHTTPRequest(
HTTPRequest* req, uint64 conid);
180 TelnetLine* sendReceiveTelnetLine(
TelnetLine* line, uint64 conid, uint32 timeout, uint32 size = 0);
182 uint32 getOutputSpeed(uint64 conid);
183 uint32 getInputSpeed(uint64 conid);
188 std::map<uint64, NetworkThread*> connectionThreads;
189 std::map<uint16, NetworkThread*> listeners;
190 std::map<uint16, NetworkThread*> udpListeners;
192 std::queue<NetworkEvent*> eventQueue;
196 bool enterNetworkEvent(uint8 type, uint8 protocol, uint64 conid);
198 bool enterHTTPRequest(
HTTPRequest* req, uint64 conid);
201 bool enterTelnetLine(
TelnetLine* line, uint64 conid);
203 std::queue<HTTPRequest*> queueHTTPRequests;
206 std::queue<HTTPReply*> queueHTTPReplies;
209 std::queue<DataMessage*> queueMessages;
212 std::queue<TelnetLine*> queueTelnetLines;
216 static THREAD_RET THREAD_FUNCTION_CALL NetworkListenerRun(THREAD_ARG arg);
217 static THREAD_RET THREAD_FUNCTION_CALL ConnectionAutodetectRun(THREAD_ARG arg);
219 static THREAD_RET THREAD_FUNCTION_CALL HTTPClientRun(THREAD_ARG arg);
220 static THREAD_RET THREAD_FUNCTION_CALL HTTPServerRun(THREAD_ARG arg);
221 static THREAD_RET THREAD_FUNCTION_CALL MessageConnectionRun(THREAD_ARG arg);
222 static THREAD_RET THREAD_FUNCTION_CALL TelnetServerRun(THREAD_ARG arg);
228 #endif // _NETWORKMANAGER_H_ Definition: NetworkProtocols.h:194
Definition: NetworkManager.h:47
Definition: NetworkConnections.h:66
Definition: NetworkManager.h:136
Definition: ThreadManager.h:33
Definition: NetworkProtocols.h:135
Definition: NetworkManager.h:115
Definition: NetworkConnections.h:153
Definition: NetworkManager.h:25
Definition: NetworkConnections.h:95
Definition: NetworkProtocols.h:81
Definition: NetworkManager.h:12
Definition: NetworkManager.h:35
Definition: DataMessage.h:95