Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_tcp_c.hxx

00001 /******************************************************************
00002  * CAVERNsoft
00003  * Copyright (C) 1994-2000 Electronic Visualization Laboratory,
00004  * all rights reserved
00005  * By Jason Leigh, Yong-joo Cho, Naveen Krishnaprasad, Chris Scharver,
00006  * Stuart Bailey, Atul Nayak, Shalini Venkataraman
00007  * University of Illinois at Chicago
00008  * 
00009  * This publication and its text and code may not be copied for commercial 
00010  * use without the express written permission of the University of Illinois
00011  * at Chicago.
00012  * The contributors disclaim any representation of warranty: use this
00013  * code at your own risk.
00014  * Direct questions, comments etc to cavern@evl.uic.edu
00015  ******************************************************************/
00016 /*
00017 This is a C++ class to support TCP/IP sockets.
00018 The 2 main classes are CAVERNnet_tcpClient_c and CAVERNnet_tcpServer_c.
00019 
00020 If you are writing a server you need to instantiate a tcpServer object.
00021 Likewise if you are writing a client you need to instantiate a tcpClient
00022 object.
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 //#include "CAVERNnet_perfDaemon_c.hxx"
00038 
00039 class CAVERNnet_perfMonitor_c;
00040 class CAVERNnet_tcpServer_c;
00041 //class CAVERNnet_perfDaemon_c;
00042 
00046 class CAVERNnet_tcpClient_c : public CAVERNnet_socketbase_c {
00047 
00048         // Allow CAVERNnet_tcpServer_c objects to call MakeNonBlocking.
00049         friend class CAVERNnet_tcpServer_c;
00050 
00051 protected:
00052         /* Not to be called by user */
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/* = 1*/;
00067 
00069         static const int NON_BLOCKING/* = 2*/;
00070 
00071         // Make the conncection blocking and never time out.
00072         //static const int NEVER_TIME_OUT_BLOCKING/* = 3*/;
00073 
00075 
00077 
00078 
00079         static const int NO_TIME_OUT/* = -1*/;
00080 
00082         static const int DEFAULT_TIME_OUT/* = NO_TIME_OUT*/; 
00084 
00086 
00087 
00088         static const int SOCKET_NOT_OPEN/* = -1*/;
00089 
00091         static const int CONNECTION_TERMINATED/* = -2*/;
00092 
00094         static const int NON_BLOCKING_HAS_NO_DATA/* = -3*/;
00095 
00097         static const int TIMED_OUT/* = -4*/;
00098 
00100         static const int OK/* = 1*/;
00101 
00103         static const int NON_BLOCKING_NOT_READY_TO_WRITE/* = -6*/;
00104 
00106         static const int NOT_READY/* = -7*/;
00107 
00109         static const int READY_TO_READ/* = -8*/;
00110 
00112         static const int READY_TO_WRITE/* = -9*/;
00113 
00115         static const int READY_TO_READ_AND_WRITE/* = -10*/;
00116 
00118     static const int READ_BUFFER_SIZE/* = -11*/;
00119 
00121     static const int WRITE_BUFFER_SIZE/* = -12*/;
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     //Functions added for performance monitoring interface
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     //Set the instantaneous latency 
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/* = 1*/;
00347 
00349         static const int FAILED/* = 0*/;
00351 
00352         //      static int CAVERNnet_tcpServer_c::NO_TIME_OUT;
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

Generated at Mon Jul 2 14:24:42 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001