00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 ;
00073 static const int FAILED;
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
00162 void setSockets(int* Sockets, int NumSockets);
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 protected:
00174
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;
00217
00219 static const int FAILED;
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