00001 #ifndef XRC_CONNMGR_H 00002 #define XRC_CONNMGR_H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C l i e n t C o n n M g r . h h */ 00006 /* */ 00007 /* Author: Fabrizio Furano (INFN Padova, 2004) */ 00008 /* Adapted from TXNetFile (root.cern.ch) originally done by */ 00009 /* Alvise Dorigo, Fabrizio Furano */ 00010 /* INFN Padova, 2003 */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00034 // // 00035 // The connection manager maps multiple logical connections on a single // 00036 // physical connection. // 00037 // There is one and only one logical connection per client // 00038 // and one and only one physical connection per server:port. // 00039 // Thus multiple objects withing a given application share // 00040 // the same physical TCP channel to communicate with a server. // 00041 // This reduces the time overhead for socket creation and reduces also // 00042 // the server load due to handling many sockets. // 00043 // // 00045 00046 #include "XrdOuc/XrdOucHash.hh" 00047 #include "XrdSys/XrdSysPthread.hh" 00048 #include "XrdClient/XrdClientUnsolMsg.hh" 00049 #include "XrdClient/XrdClientPhyConnection.hh" 00050 #include "XrdClient/XrdClientVector.hh" 00051 00052 class XrdClientSid; 00053 class XrdClientLogConnection; 00054 class XrdClientMessage; 00055 class XrdClientThread; 00056 00057 // Ugly prototype to avoid warnings under solaris 00058 //void * GarbageCollectorThread(void * arg, XrdClientThread *thr); 00059 00060 class XrdClientConnectionMgr: public XrdClientAbsUnsolMsgHandler, 00061 XrdClientUnsolMsgSender { 00062 00063 private: 00064 XrdClientSid *fSidManager; 00065 00066 XrdClientVector<XrdClientLogConnection*> fLogVec; 00067 XrdOucHash<XrdClientPhyConnection> fPhyHash; 00068 00069 // To try not to reuse too much the same array ids 00070 int fLastLogIdUsed; 00071 // Phyconns are inserted here when they have to be destroyed later 00072 // All the phyconns here are disconnected. 00073 XrdClientVector<XrdClientPhyConnection *> fPhyTrash; 00074 00075 // To arbitrate between multiple threads trying to connect to the same server. 00076 // The first has to connect, all the others have to wait for the completion 00077 // The meaning of this is: if there is a condvar associated to the hostname key, 00078 // then wait for it to be signalled before deciding what to do 00079 class CndVarInfo { 00080 public: 00081 XrdSysCondVar cv; 00082 int cnt; 00083 CndVarInfo(): cv(0), cnt(0) {}; 00084 }; 00085 00086 XrdOucHash<CndVarInfo> fConnectingCondVars; 00087 00088 XrdSysRecMutex fMutex; // mutex used to protect local variables 00089 // of this and TXLogConnection, TXPhyConnection 00090 // classes; not used to protect i/o streams 00091 00092 XrdClientThread *fGarbageColl; 00093 00094 friend void * GarbageCollectorThread(void *, XrdClientThread *thr); 00095 UnsolRespProcResult 00096 ProcessUnsolicitedMsg(XrdClientUnsolMsgSender *sender, 00097 XrdClientMessage *unsolmsg); 00098 public: 00099 XrdClientConnectionMgr(); 00100 00101 virtual ~XrdClientConnectionMgr(); 00102 00103 bool BootUp(); 00104 bool ShutDown(); 00105 00106 00107 int Connect(XrdClientUrlInfo RemoteAddress); 00108 void Disconnect(int LogConnectionID, bool ForcePhysicalDisc); 00109 00110 void GarbageCollect(); 00111 00112 XrdClientLogConnection 00113 *GetConnection(int LogConnectionID); 00114 XrdClientPhyConnection *GetPhyConnection(XrdClientUrlInfo server); 00115 00116 XrdClientMessage* 00117 ReadMsg(int LogConnectionID); 00118 00119 int ReadRaw(int LogConnectionID, void *buffer, int BufferLength); 00120 int WriteRaw(int LogConnectionID, const void *buffer, 00121 int BufferLength, int substreamid); 00122 00123 XrdClientSid *SidManager() { return fSidManager; } 00124 00125 friend int DisconnectElapsedPhyConn(const char *, 00126 XrdClientPhyConnection *, void *); 00127 friend int DestroyPhyConn(const char *, 00128 XrdClientPhyConnection *, void *); 00129 }; 00130 #endif