#ifndef CONNMGR_H #define CONNMGR_H ///////////////////////////////////////////////////////////////////////// // connMgr.h - connection manager, used by server to manage // // ver 1.1 socket connections // // // // Language: Visual C++, ver 6.0 // // Platform: Dell Dimension 8100, Windows 2000 Pro, SP1 // // Application: CSE691/791 help // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////////// /* Module Operations ================= This module provides a connectionMgr class that keeps track of connection status for a socket-based server. Public Interface ================ connectionMgr cm; // create a connection mgr int ID = cm.openConnection(sock); // returns ID of a new connection cm.closeConnection(ID); // closes ID connection qRef sQ = cm.sendQ(ID); // returns reference to a send queue qRef rQ = cm.recvQ(); // returns reference to recv queue SOCKET s = cm.sock(ID); // returns socket for a connection bool b = cm.isOpen(ID); // is this connection open? int num = cm.numConnects(); // how many connections are open? cm.display(int ID); // displays state of open connection cm.displayAll(); // displays all open connections cm.startFindConnection(); // gets ready to start an enumeration int ID = cm.findNextConnection(); // find the next open connection */ ///////////////////////////////////////////////////////////////////////// // Build Process // ///////////////////////////////////////////////////////////////////////// // Required Files: // // connMgr.h connMgr.cpp, mtqueue.h, msgHnd.h, mshHnd.cpp, // // xmlTran.h, xmlTran.cpp, nodePool.h, sysUtils.h // // // // Compiler command: // // cl /GX /DTEST_CONNMGR connMgr.cpp, msgHnd.cpp, xmlTran.cpp // // // ///////////////////////////////////////////////////////////////////////// /* Maintenance History =================== ver 1,1 : 16 Nov 01 - added Mutex object to connection structure. This lets server lock a single sendQ object, instead of locking them all with a GlobalMutex - added Mutex& locker(int ID) to connectionMgr so server can find the right mutex ver 1.0 : 12 Nov 01 - first release */ // #include #include "mtQueue.h" #include "lockingPtr.h" #include "msgHnd.h" typedef mtqueue& qRef; const int MAXCONNECTS = 100; const int connMgrLock = 101; const int svrSendQlock = 335; const int svrRecvQlock = 336; struct connection { // failed must be non-positive enum connectionState { failed = -1, open, closed }; connection(); SOCKET _sock; mtqueue _sendQ; int _ID; connectionState _state; Mutex _mtx; }; inline connection::connection() : _state(connection::closed) {} class connectionMgr { public: connectionMgr(); ~connectionMgr(); int openConnection(SOCKET sock); // returns ID void closeConnection(int ID); Mutex& locker(int ID); qRef sendQ(int ID); qRef recvQ(); SOCKET sock(int ID); bool isOpen(int ID); int numConnects(); void display(int ID); void displayAll(); void startFindConnection(); int findNextConnection(); private: static mtqueue _recvQ; // messages to server static mtqueue _deadLetter; // holds msgs to closed connects static connection conn[MAXCONNECTS]; // all the connections static int _index; // holds state of enumeration static int find(int ID); static int makeID(); static std::string stateToStr(connection::connectionState st); }; #endif