00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "CAVERNnet_tcp_c.hxx"
00018
00019 #ifndef _CAVERNPLUS_TCP_REFLECTOR
00020 #define _CAVERNPLUS_TCP_REFLECTOR
00021
00022 #define TCP_REFLECTOR_DEFAULT_PORT 7000
00023 #define PERFDAEMON_ALIVE 1
00024 #define PERFDAEMON_NOT_ALIVE 0
00025
00026 class CAVERNnet_tcpReflectorClient_c;
00027
00044 class CAVERNnet_tcpReflector_c
00045 {
00046 public:
00047 CAVERNnet_tcpReflector_c();
00048 ~CAVERNnet_tcpReflector_c();
00049
00051
00052 static const int OK;
00053
00055 static const int FAILED;
00056
00058 static const int MEM_ALLOC_ERR;
00059
00061 static const int NEW_CONNECTION_ESTABLISHED;
00062
00064 static const int TOO_MANY_CLIENTS;
00065
00067 static const int NO_NEW_CONNECTION;
00068
00070 static const int NON_BLOCKING_HAS_NO_DATA;
00071
00073 static const int SKIP_DISTRIBUTION;
00074
00075 static const int DEFAULT_PORT;
00077
00085 int init(int incomingPort=TCP_REFLECTOR_DEFAULT_PORT, int maxClients = 64,
00086 char* forwardAddr = NULL, unsigned short forwardPort = 0);
00087
00092 int process();
00093
00101 int checkForNewClients();
00102
00106 int setForcedDestination(char *ipAddr, unsigned short port);
00107
00110 void sendToAll(char* buffer, int dataSize);
00111
00128 void intercept(int (*callback) (CAVERNnet_tcpReflectorClient_c *client, char** buffer, int *bufferSize, void *userData), void* userData);
00129
00136 void interceptNewConnection(void (*callback) (CAVERNnet_tcpReflectorClient_c *newClient, void* userData), void *userData);
00137
00138
00139
00151 void showStats(char* streamInfo, char* comment);
00152
00169 int logStats(char* streamInfo, char* comment, FILE* filePtr);
00170
00187 int sendStats(char* streamInfo, char* comment);
00188
00202 int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00203
00207 void exitSendStats();
00208
00209 private:
00210 CAVERNnet_tcpReflectorClient_c **clients;
00211 CAVERNnet_tcpServer_c *server;
00212 unsigned short incomingPort;
00213 char* perfDaemonIP;
00214 int perfDaemonPort;
00215 int perfDaemonStatus;
00216 int (*interceptCallback) (CAVERNnet_tcpReflectorClient_c *newClient, char** buffer, int* bufsize, void *userData);
00217 void *interceptUserData;
00218
00219 void (*interceptNewConnectionCallback) (CAVERNnet_tcpReflectorClient_c *newClient, void *userData);
00220 void *interceptNewConnectionUserData;
00221
00222
00223
00224
00225 int distributeDataExceptTo(int clientToIgnore, char* buf, int incomingSize);
00226
00227
00228 void removeClient(int clientNum);
00229
00230
00231
00232 void closeDownSockets();
00233
00234
00235 int addNewClient(CAVERNnet_tcpReflectorClient_c* newClient);
00236
00237 int maxNumClients;
00238 };
00239
00246 class CAVERNnet_tcpReflectorClient_c
00247 {
00248 private:
00249 CAVERNnet_tcpClient_c *client;
00250 int timeOut;
00251 int connectionAlive;
00252
00253 public:
00254
00256
00257 static const int OK;
00258
00260 static const int FAILED;
00261
00263 static const int MEM_ALLOC_ERR;
00264
00266 static const int NON_BLOCKING_HAS_NO_DATA;
00267
00269 static const int CONNECTION_TERMINATED;
00270
00272 static const int NOT_READY;
00273
00275 static const int READY_TO_READ;
00276
00278 static const int READY_TO_WRITE;
00279
00281 static const int READY_TO_READ_AND_WRITE;
00282
00283 static const int BLOCKING;
00284 static const int NON_BLOCKING;
00285
00286 static const int NO_TIME_OUT;
00287
00289
00290 CAVERNnet_tcpReflectorClient_c();
00291
00293 CAVERNnet_tcpReflectorClient_c(CAVERNnet_tcpClient_c *);
00294
00295 ~CAVERNnet_tcpReflectorClient_c();
00296
00305 int read(char** ret, int* nbytes, int blockingType);
00306
00312 int write(char *outgoingData, int* nbytes);
00313
00318 int isReadyToRead();
00319
00324 int isReadyToWrite();
00325
00332 int isReady();
00333
00335
00336
00340 unsigned int getRemoteIP();
00341
00346 void getRemoteIP(char* name);
00347
00349 unsigned int getSelfIP();
00350
00352 void getSelfIP(char *name);
00353
00355 int getSelfPort();
00356
00358 int getRemotePort();
00360
00362 void showStatus(int status, int nbytes);
00363
00365 void close();
00366
00372 int connectToServer(char *ip, int port=CAVERNnet_tcpReflector_c::DEFAULT_PORT);
00373
00382 void setTimeOut(int timeout=CAVERNnet_tcpReflectorClient_c::NO_TIME_OUT);
00383
00384
00385
00398 void showStats(char* streamInfo, char* comment);
00399
00416 int logStats(char* streamInfo, char* comment, FILE* filePtr);
00417
00434 int sendStats(char* streamInfo, char* comment);
00435
00449 int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00450
00455 void exitSendStats();
00456 };
00457
00458 #endif