|
xrootd
|
00001 #ifndef __CMS_RESP__ 00002 #define __CMS_RESP__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C m s r e s p . h h */ 00006 /* */ 00007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 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 00033 #include "XrdOuc/XrdOucErrInfo.hh" 00034 #include "XrdSys/XrdSysPthread.hh" 00035 00036 #include "XProtocol/YProtocol.hh" 00037 00038 /******************************************************************************/ 00039 /* X r d C m s R e s p C B */ 00040 /******************************************************************************/ 00041 00042 class XrdCmsRespCB : XrdOucEICB 00043 { 00044 public: 00045 00046 void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0) 00047 {respSync.Post();} 00048 00049 void Init() {while(respSync.CondWait()) {}} 00050 00051 int Same(unsigned long long arg1, unsigned long long arg2) {return 0;} 00052 00053 void Wait() {respSync.Wait();} 00054 00055 XrdCmsRespCB() : respSync(0) {} 00056 ~XrdCmsRespCB() {} 00057 00058 private: 00059 00060 XrdSysSemaphore respSync; 00061 }; 00062 00063 /******************************************************************************/ 00064 /* X r d C m s R e s p */ 00065 /******************************************************************************/ 00066 00067 class XrdNetBuffer; 00068 00069 class XrdCmsResp : public XrdOucEICB, public XrdOucErrInfo 00070 { 00071 public: 00072 friend class XrdCmsRespQ; 00073 00074 static XrdCmsResp *Alloc(XrdOucErrInfo *erp, int msgid); 00075 00076 void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0) 00077 {Recycle();} 00078 00079 inline int ID() {return myID;} 00080 00081 void Reply(const char *Man, XrdCms::CmsRRHdr &rrhdr, 00082 XrdNetBuffer *netbuff); 00083 00084 static void Reply(); 00085 00086 int Same(unsigned long long arg1, unsigned long long arg2) 00087 {return 0;} 00088 00089 static void setDelay(int repdly) {RepDelay = repdly;} 00090 00091 XrdCmsResp() : XrdOucErrInfo(UserID) {next = 0; myBuff = 0;} 00092 ~XrdCmsResp() {} 00093 00094 private: 00095 void Recycle(); 00096 void ReplyXeq(); 00097 00098 static XrdSysSemaphore isReady; 00099 static XrdSysMutex rdyMutex; // Protects the below 00100 static XrdCmsResp *First; 00101 static XrdCmsResp *Last; 00102 00103 static XrdSysMutex myMutex; // Protects above and below 00104 static XrdCmsResp *nextFree; 00105 static int numFree; 00106 static const int maxFree = 300; 00107 static int RepDelay; 00108 00109 XrdCms::CmsRRHdr myRRHdr; 00110 XrdNetBuffer *myBuff; 00111 char theMan[128]; 00112 00113 XrdCmsRespCB SyncCB; 00114 XrdCmsResp *next; 00115 int myID; 00116 char UserID[64]; 00117 }; 00118 00119 /******************************************************************************/ 00120 /* X r d O d c R e s p Q */ 00121 /******************************************************************************/ 00122 00123 class XrdCmsRespQ 00124 { 00125 public: 00126 void Add(XrdCmsResp *rp); 00127 00128 void Purge(); 00129 00130 XrdCmsResp *Rem(int msgid); 00131 00132 XrdCmsRespQ(); 00133 ~XrdCmsRespQ() {Purge();} 00134 00135 private: 00136 00137 XrdSysMutex myMutex; // Protects above and below 00138 static const int mqSize = 512; 00139 00140 XrdCmsResp *mqTab[mqSize]; 00141 }; 00142 #endif
1.7.6.1