XrdClientConnMgr.hh

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //                                                                      //
00003 // XrdClientConnMgr                                                     //
00004 // Author: Fabrizio Furano (INFN Padova, 2004)                          //
00005 // Adapted from TXNetFile (root.cern.ch) originally done by             //
00006 //  Alvise Dorigo, Fabrizio Furano                                      //
00007 //          INFN Padova, 2003                                           //
00008 //                                                                      //
00009 // The connection manager maps multiple logical connections on a single //
00010 // physical connection.                                                 //
00011 // There is one and only one logical connection per client              //
00012 // and one and only one physical connection per server:port.            //
00013 // Thus multiple objects withing a given application share              //
00014 // the same physical TCP channel to communicate with a server.          //
00015 // This reduces the time overhead for socket creation and reduces also  //
00016 // the server load due to handling many sockets.                        //
00017 //                                                                      //
00018 //////////////////////////////////////////////////////////////////////////
00019 
00020 //       $Id: XrdClientConnMgr.hh 24809 2008-07-14 11:59:17Z ganis $
00021 
00022 #ifndef XRC_CONNMGR_H
00023 #define XRC_CONNMGR_H
00024 
00025 
00026 #include "XrdOuc/XrdOucHash.hh"
00027 #include "XrdSys/XrdSysPthread.hh"
00028 #include "XrdClient/XrdClientUnsolMsg.hh"
00029 #include "XrdClient/XrdClientPhyConnection.hh"
00030 #include "XrdClient/XrdClientVector.hh"
00031 
00032 class XrdClientSid;
00033 class XrdClientLogConnection;
00034 class XrdClientMessage;
00035 class XrdClientThread;
00036 
00037 // Ugly prototype to avoid warnings under solaris
00038 //void * GarbageCollectorThread(void * arg, XrdClientThread *thr);
00039 
00040 class XrdClientConnectionMgr: public XrdClientAbsUnsolMsgHandler, 
00041                        XrdClientUnsolMsgSender {
00042 
00043 private:
00044    XrdClientSid *fSidManager;
00045 
00046    XrdClientVector<XrdClientLogConnection*> fLogVec;
00047    XrdOucHash<XrdClientPhyConnection> fPhyHash;
00048 
00049    // To try not to reuse too much the same array ids
00050    int fLastLogIdUsed;
00051    // Phyconns are inserted here when they have to be destroyed later
00052    // All the phyconns here are disconnected.
00053    XrdClientVector<XrdClientPhyConnection *> fPhyTrash;
00054 
00055    // To arbitrate between multiple threads trying to connect to the same server.
00056    // The first has to connect, all the others have to wait for the completion
00057    // The meaning of this is: if there is a condvar associated to the hostname key,
00058    //  then wait for it to be signalled before deciding what to do
00059   class CndVarInfo {
00060   public:
00061     XrdSysCondVar cv;
00062     int cnt;
00063     CndVarInfo(): cv(0), cnt(0) {};
00064   };
00065 
00066    XrdOucHash<CndVarInfo> fConnectingCondVars;
00067 
00068    XrdSysRecMutex                fMutex; // mutex used to protect local variables
00069                                       // of this and TXLogConnection, TXPhyConnection
00070                                       // classes; not used to protect i/o streams
00071 
00072    XrdClientThread            *fGarbageColl;
00073 
00074    friend void * GarbageCollectorThread(void *, XrdClientThread *thr);
00075    UnsolRespProcResult
00076                  ProcessUnsolicitedMsg(XrdClientUnsolMsgSender *sender,
00077                                        XrdClientMessage *unsolmsg);
00078 public:
00079    XrdClientConnectionMgr();
00080 
00081    virtual ~XrdClientConnectionMgr();
00082 
00083    int           Connect(XrdClientUrlInfo RemoteAddress);
00084    void          Disconnect(int LogConnectionID, bool ForcePhysicalDisc);
00085 
00086    void          GarbageCollect();
00087 
00088    XrdClientLogConnection 
00089                  *GetConnection(int LogConnectionID);
00090    XrdClientPhyConnection *GetPhyConnection(XrdClientUrlInfo server);
00091 
00092    XrdClientMessage*   
00093                  ReadMsg(int LogConnectionID);
00094 
00095    int           ReadRaw(int LogConnectionID, void *buffer, int BufferLength);
00096    int           WriteRaw(int LogConnectionID, const void *buffer, 
00097                           int BufferLength, int substreamid);
00098 
00099   XrdClientSid *SidManager() { return fSidManager; }
00100 
00101   friend int DisconnectElapsedPhyConn(const char *,
00102                                       XrdClientPhyConnection *, void *);
00103   friend int DestroyPhyConn(const char *,
00104                             XrdClientPhyConnection *, void *);
00105 };
00106 
00107 
00108 #endif

Generated on Tue Jul 5 14:46:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1