00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _CAVERNNET_UDP
00018 #define _CAVERNNET_UDP
00019
00020 #include "CAVERNnet_socketbase_c.hxx"
00021 #include "CAVERNnet_perfMonitor_c.hxx"
00022 #include "CAVERNnet_perfDaemon_c.hxx"
00023
00024 #ifdef WIN32
00025 #include <winsock.h>
00026 #elif defined(__sgi)
00027 extern int h_errno;
00028 #endif
00029
00045
00046
00047
00048 class CAVERNnet_udp_c : public CAVERNnet_socketbase_c {
00049
00050 private:
00051
00052 int enableInstr;
00053
00054
00055 int sockfd;
00056
00057
00058 int timeOutStatus;
00059 int timeOutPeriod;
00060
00061
00062 struct sockaddr_in selfAddress, sendAddress, receiveAddress;
00063
00064
00065 CAVERNnet_perfMonitor_c pmonitor;
00066
00067
00068 int typeOfBlocking;
00069
00070 public:
00071
00073
00074
00075 static const int OK;
00076
00078 static const int FAILED;
00079
00081
00083
00084
00085 static const int BLOCKING;
00086
00088 static const int NON_BLOCKING;
00089
00091 static const int NULL_VALUE;
00092
00094
00096
00097
00098 static const int NO_TIME_OUT;
00099
00101 static const int DEFAULT_TIME_OUT;
00102
00104
00106
00107
00108 static const int SOCKET_NOT_OPEN;
00109
00111 static const int TIMED_OUT;
00112
00114 static const int NON_BLOCKING_NOT_READY_TO_WRITE ;
00115
00117 static const int NON_BLOCKING_HAS_NO_DATA ;
00118
00119
00121
00122 CAVERNnet_udp_c();
00123
00132 void enableInstrumentation();
00133
00140 void disableInstrumentation();
00141
00145 void setTimeOut(int t) {timeOutPeriod = t;}
00146
00148 int getTimeOut() {return timeOutPeriod;}
00149
00159 int init(unsigned short port = 0);
00160
00166 int setSendAddress(char *host, unsigned short port);
00167
00171 void copyReceiveAddressToSendAddress();
00172
00180 CAVERNnet_udp_c * clone();
00181
00204 int send(char *message, int length, int blockingType = CAVERNnet_udp_c::NULL_VALUE);
00205
00230 int receive(char *message, int length, int blockingType = CAVERNnet_udp_c::NULL_VALUE);
00231
00232
00236 int peek(char *message, int length);
00237
00239 void makeNonBlocking();
00240
00242
00243
00244 unsigned long getReceiveIP();
00246 void getReceiveIP(char *ip);
00248 unsigned short getReceivePort();
00249
00251 unsigned long getSendIP();
00253 void getSendIP(char *ip);
00255 unsigned short getSendPort();
00256
00258 unsigned long getSelfIP();
00260 void getSelfIP(char *ip);
00262 unsigned short getSelfPort();
00264
00265
00267 void printInfo();
00268
00274 #ifdef WIN32
00275 void close() {::closesocket(sockfd);}
00276 #else
00277 void close() {::close(sockfd);}
00278 #endif
00279
00280
00281
00293 void showStats(char* streamInfo, char* comment);
00294
00311 int logStats(char* streamInfo, char* comment, FILE* filePtr);
00312
00327 int sendStats(char* streamInfo, char* comment);
00328
00342 int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00343
00348 void exitSendStats();
00349
00350
00351 };
00352
00353
00354 #endif