CCAFFEINE  0.8.8
ClientServerSocket.h
00001 #ifdef CCAFE_SOCKETS
00002 
00003 #ifndef __CLIENTSERVERSOCKET_H__
00004 #define __CLIENTSERVERSOCKET_H__
00005 
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include <sys/file.h>
00009 #include <sys/types.h>
00010 #include <sys/socket.h>
00011 #include <netinet/in.h>
00012 #include <netdb.h>
00013 #include "jc++/jc++.h"
00014 #include "jc++/lang/jc++lang.h"
00015 #include "jc++/util/jc++util.h"
00016 #ifdef HAVE_CLASSIC
00017 #include <cca.h>
00018 #endif // HAVE_CLASSIC
00019 #include "util/IO.h"
00020 #include "ProcessorInfo.h"
00021 
00022 #ifndef bufsize_seen
00023 #define bufsize_seen
00024 #define BSIZ BUFSIZ
00025 
00026 enum {
00027   NORMAL_BUF,
00028   LINE_BUF,
00029   NO_BUF
00030 };
00031 #endif
00032 
00033 class ClientServerSocket  {
00034  private:
00035   JCPN(Vector)* machines; // type ProcessorInfo*
00036   // A number that ranges from 0 to nproc -1
00037   int myProcNumber;
00038   int serverProcNumber; // The processor number for the Server
00039   int serverPort; // Port on which the server will be listening.
00040 
00041   // File descriptors for IO.  Server has a vector of valid fd's top
00042   // the clients clients have only in[0] and out[0] as valid.
00043   CDELETE FILE** in;
00044   CDELETE FILE** out;
00045 
00046   // Buffering options, probably LINE_BUF will work best.
00047   char buffering;
00048   //Backlog of connections that will wait on a connect.
00049   int backlog;
00050 
00051  public:
00052 
00053   ClientServerSocket(int myProcNumber, int serverPort, 
00054                      CDELETE JCPN(Vector)* machines);
00055   virtual ~ClientServerSocket();
00056 
00057   FILE** getIn(int& size);
00058   FILE** getOut(int& size);
00059 
00060   int acceptConnections();
00061   int connectToServer();
00062 
00063   boolean isServer();
00068   int makeConnection();
00069 };
00070 
00071 #endif // __CLIENTSERVERSOCKET_H__
00072 #else
00073 extern int ccafe_no_clientserversocket;
00074 #endif // CCAFE_SOCKETS