00001 #ifndef __CMS_RESP__
00002 #define __CMS_RESP__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "XrdOuc/XrdOucErrInfo.hh"
00034 #include "XrdSys/XrdSysPthread.hh"
00035
00036 #include "XProtocol/YProtocol.hh"
00037
00038
00039
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
00065
00066
00067 class XrdOucBuffer;
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 XrdOucBuffer *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;
00100 static XrdCmsResp *First;
00101 static XrdCmsResp *Last;
00102
00103 static XrdSysMutex myMutex;
00104 static XrdCmsResp *nextFree;
00105 static int numFree;
00106 static const int maxFree = 300;
00107 static int RepDelay;
00108
00109 XrdCms::CmsRRHdr myRRHdr;
00110 XrdOucBuffer *myBuff;
00111 char theMan[128];
00112
00113 XrdCmsRespCB SyncCB;
00114 XrdCmsResp *next;
00115 int myID;
00116 char UserID[64];
00117 };
00118
00119
00120
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;
00138 static const int mqSize = 512;
00139
00140 XrdCmsResp *mqTab[mqSize];
00141 };
00142 #endif