Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_parallelTcp_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 #ifndef _CAVERNPLUS_PARALLEL_TCP_C
00018 #define _CAVERNPLUS_PARALLEL_TCP_C
00019 
00020 #include "CAVERNnet_socketbase_c.hxx"
00021 #include "CAVERNnet_datapack_c.hxx"
00022 
00023 #ifdef WIN32
00024 #include <errno.h>
00025 #elif defined(__sgi)
00026 extern int errno;
00027 #endif
00028 
00062 class CAVERNnet_parallelTcpClient_c : public CAVERNnet_socketbase_c
00063 { 
00064 public:
00065         CAVERNnet_parallelTcpClient_c();
00066     ~CAVERNnet_parallelTcpClient_c();
00067 
00069 
00070 
00071                 static const int OK        /* = 1*/;
00073                 static const int FAILED/* = 0*/;
00075 
00088     int write( char* buffer, int* length );
00089 
00103     int read( char* buffer, int* length );
00104 
00105 
00109     void close();
00110 
00131         int connectToServer(char *RemoteName, int RemotePort, int Size);
00132 
00134 
00135 
00139         unsigned int getRemoteIP();
00140 
00145         void getRemoteIP(char* name);
00146 
00148         unsigned int getSelfIP();
00149 
00151         void getSelfIP(char *name);
00152 
00154         int  getSelfPort();
00155 
00157         int  getRemotePort();
00159 
00160 public:
00161         /* These functions are provided to be used in CAVERNnet_parallelTcpServer_c only. */
00162         void setSockets(int* Sockets, int NumSockets);/* { 
00163         sockets = Sockets;
00164         numSockets = NumSockets; 
00165         for (int i = 0; i < NumSockets; i++) {
00166             if (sockets[i] > maxSockDesc) maxSockDesc = sockets[i];
00167         }
00168         pcReadPtr = new char *[NumSockets];
00169         pcWritePtr = new char *[NumSockets];
00170         piBytesLeft = new int[NumSockets];
00171     }*/
00172 
00173 protected:
00174         /* Not to be called by user */
00175         void makeNonBlocking(int Sockfd);
00176         int connectToClient(char* RemoteName, unsigned short RemotePort, 
00177                                                 int& SocketInfo);
00178 
00179         char** pcReadPtr;
00180         char** pcWritePtr;
00181         int* piBytesLeft;
00182         int* sockets;    
00183         fd_set fdSet;
00184     int maxSockDesc;
00185     int numSockets;
00186     struct sockaddr_in remoteAddr;
00187     struct sockaddr_in localAddr;   
00188 };
00189 
00211 class CAVERNnet_parallelTcpServer_c : public CAVERNnet_socketbase_c
00212 {
00213 public:
00215 
00216         static const int OK/* = 1*/;
00217 
00219         static const int FAILED/* = 0*/;
00221 
00222 
00223         CAVERNnet_parallelTcpServer_c() {};
00224         ~CAVERNnet_parallelTcpServer_c() 
00225         { 
00226 #ifdef WIN32
00227                 if (sockfd > 0) closesocket(sockfd); 
00228 #else
00229                 if (sockfd > 0) ::close(sockfd);
00230 #endif
00231         }
00232 
00238         int init(int port);
00239 
00241         void close() { 
00242 #ifdef WIN32
00243                 closesocket(sockfd);
00244 #else
00245                 ::close(sockfd);
00246 #endif
00247                 sockfd = 0;
00248         }
00249 
00255         CAVERNnet_parallelTcpClient_c *checkForNewConnections();
00256 
00258         unsigned int getSelfIP();
00259 
00261         int getSelfPort() { return ntohs(serverInfo.sin_port); };
00262 
00263 protected:
00264         void makeNonBlocking(int Sockfd);
00265         int connectToClient(unsigned long RemoteAddr, unsigned short RemotePort, 
00266                                                 int& SocketInfo);
00267 
00268         struct sockaddr_in  serverInfo;
00269         int sockfd;
00270 };
00271 
00272 #endif

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