CCAFFEINE
0.8.8
|
00001 #ifdef CCAFE_THREADS 00002 #ifndef SocketConnectionManager_seen 00003 #define SocketConnectionManager_seen 00004 00005 #include "ConnectionManager.h" 00016 #ifndef bufsize_seen 00017 #define bufsize_seen 00018 #define BSIZ BUFSIZ 00019 00020 enum { 00021 NORMAL_BUF, 00022 LINE_BUF, 00023 NO_BUF 00024 }; 00025 #endif // bufsize_seen 00026 00027 00028 00029 class RunProcess; 00030 class SocketConnection; 00031 00032 00033 00034 class SocketConnectionManager : public ConnectionManager { 00035 private: 00036 int readWakeup[2]; 00037 int connectWakeup[2]; 00038 JCPN(Vector) connectionsImpl; // shutdown and delete 00039 JCPN(Vector) disconnected; // leave 00040 CCAFEThreadSafeQueue disconnectedConnections; 00041 CCAFEThreadSafeQueue connections; 00042 int numMachines; 00043 int serverPort; 00044 char* serverName; // delete 00045 boolean amServer; 00046 boolean amConnected; 00047 boolean amShutdown; 00048 boolean asyncNotify; 00049 int serverSocket; // shutdown 00050 CCAFEReadWriteMutex mutex; 00051 00052 // Buffering options, probably LINE_BUF will work best. 00053 char buffering; 00054 //Backlog of connections that will wait on a connect. 00055 int backlog; 00056 00057 void initialize(); 00058 int acceptConnections(int timeout); 00059 int connectToServer(); 00060 protected: 00061 friend class Connection; 00062 virtual void disconnectConnection(Connection* connection); 00063 public: 00064 SocketConnectionManager(int myProcNumber, int serverPort, 00065 JCPN(Vector)* machines, boolean asyncNotify = TRUE); 00066 // constructs a single client connection 00067 SocketConnectionManager(int serverPort, 00068 char* serverName, boolean asyncNotify = TRUE); 00069 // constructs a server with multiple connections from clients 00070 SocketConnectionManager(int serverPort, 00071 int numMachines, boolean asyncNotify = TRUE); 00072 ~SocketConnectionManager(); 00073 virtual int makeConnection(int timeout); 00076 virtual int notifyReconnect(); 00080 virtual void notifyReads(); 00085 virtual void shutdown(); 00086 virtual CCAFEThreadSafeQueue* getConnections(); 00087 virtual int getNumConnections() { return numMachines - 1;}; 00088 virtual boolean isConnected() { return amConnected; }; 00089 boolean isServer(); 00090 }; 00091 00092 class SocketConnection : public Connection { 00093 private: 00094 friend class RunProcess; // BUGBUG 00095 int connSocket; 00096 int connNumber; 00097 FILE* in; 00098 FILE* out; 00099 JCPN(Reader)* reader; 00100 JCPN(Writer)* writer; 00101 protected: 00102 friend class SocketConnectionManager; 00103 void doSetup(char buffering, boolean asyncNotify); 00104 public: 00105 SocketConnection(SocketConnectionManager* manager, int connNumber); 00106 ~SocketConnection(); 00107 CDELETE JCPN(Reader)* getIn(); 00108 CDELETE JCPN(Writer)* getOut(); 00109 CFREE char* getName(); 00110 void shutdown(); 00111 int getId() { return connNumber; }; 00112 }; 00113 #endif 00114 00115 #else // ccafethread 00116 extern int ccafe_no_socketcm; 00117 #endif // CCAFE_THREADS