00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _CAVERNPLUS_TCP_C
00027 #define _CAVERNPLUS_TCP_C
00028
00029 #ifdef WIN32
00030 #include <errno.h>
00031 #elif defined(__sgi)
00032 extern int errno;
00033 #endif
00034
00035 #include "CAVERNnet_socketbase_c.hxx"
00036 #include "CAVERNnet_perfMonitor_c.hxx"
00037
00038
00039 class CAVERNnet_perfMonitor_c;
00040 class CAVERNnet_tcpServer_c;
00041
00042
00046 class CAVERNnet_tcpClient_c : public CAVERNnet_socketbase_c {
00047
00048
00049 friend class CAVERNnet_tcpServer_c;
00050
00051 protected:
00052
00053 void makeNonBlocking();
00054
00055 struct sockaddr_in clientInfo;
00056 int clientSockFd;
00057 int clientStatus;
00058 int timeOutStatus;
00059 int timeOutPeriod;
00060 CAVERNnet_perfMonitor_c pmonitor;
00061 public:
00062
00064
00065
00066 static const int BLOCKING;
00067
00069 static const int NON_BLOCKING;
00070
00071
00072
00073
00075
00077
00078
00079 static const int NO_TIME_OUT;
00080
00082 static const int DEFAULT_TIME_OUT;
00084
00086
00087
00088 static const int SOCKET_NOT_OPEN;
00089
00091 static const int CONNECTION_TERMINATED;
00092
00094 static const int NON_BLOCKING_HAS_NO_DATA;
00095
00097 static const int TIMED_OUT;
00098
00100 static const int OK;
00101
00103 static const int NON_BLOCKING_NOT_READY_TO_WRITE;
00104
00106 static const int NOT_READY;
00107
00109 static const int READY_TO_READ;
00110
00112 static const int READY_TO_WRITE;
00113
00115 static const int READY_TO_READ_AND_WRITE;
00116
00118 static const int READ_BUFFER_SIZE;
00119
00121 static const int WRITE_BUFFER_SIZE;
00123
00124
00128 void setTimeOut(int t) {timeOutPeriod = t;}
00129
00131 int getTimeOut() {return timeOutPeriod;}
00132
00136 void setClientInfo(struct sockaddr_in* info) { clientInfo = *info; }
00137
00141 void setClientSockFd(int sockfd) { clientSockFd = sockfd; }
00142
00143 CAVERNnet_tcpClient_c();
00144 ~CAVERNnet_tcpClient_c() { if (clientSockFd) close(); }
00145
00147
00148
00152 unsigned int getRemoteIP();
00153
00158 void getRemoteIP(char* name);
00159
00161 unsigned int getSelfIP();
00162
00164 void getSelfIP(char *name);
00165
00167 int getSelfPort();
00168
00170 int getRemotePort();
00172
00199 int read(char *ptr, int *nbytes, int blockingType);
00200
00210 void setSockOptions(int option, int buffersize);
00211
00212
00217 int isReadyToRead();
00218
00223 int isReadyToWrite();
00224
00231 int isReady();
00232
00236 int write(char *ptr, int *nbytes, int blockingType);
00237
00239
00241 void showStatus(int status, int nbytes);
00242
00244 void close();
00245
00249 int connectToServer(char *ip, int port);
00250
00251
00252
00265 void showStats(char* streamInfo, char* comment);
00266
00284 int logStats(char* streamInfo, char* comment, FILE* filePtr);
00285
00300 int sendStats(char* streamInfo, char* comment);
00301
00315 int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00316
00321 void exitSendStats();
00322
00323
00324 void setInstantaneousLatency(double latency);
00325
00326
00327 };
00328
00332 class CAVERNnet_tcpServer_c : public CAVERNnet_socketbase_c {
00333
00334
00335 protected:
00336 int serverPort;
00337
00338 int timeOutPeriod;
00339 int sockfd;
00340 struct sockaddr_in serverInfo;
00341
00342 public:
00343
00345
00346 static const int OK;
00347
00349 static const int FAILED;
00351
00352
00353
00357 void setTimeOut(int t) {timeOutPeriod = t;}
00358
00360 int getTimeOut() {return timeOutPeriod;}
00361
00362 CAVERNnet_tcpServer_c();
00363 ~CAVERNnet_tcpServer_c() { if (sockfd) close(); }
00364
00366 unsigned int getSelfIP();
00367
00369 void getSelfIP(char* name);
00370
00372 int getSelfPort() {
00373 return ntohs(serverInfo.sin_port);
00374 }
00375
00381 int init(int port);
00382
00384 void close();
00385
00391 CAVERNnet_tcpClient_c *checkForNewConnections();
00392 };
00393
00394 #endif