00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <stdlib.h>
00014 #include <string.h>
00015 #include <sys/param.h>
00016
00017 #include "XrdNet/XrdNetCmsNotify.hh"
00018 #include "XrdNet/XrdNetMsg.hh"
00019 #include "XrdOuc/XrdOucUtils.hh"
00020 #include "XrdSys/XrdSysError.hh"
00021 #include "XrdSys/XrdSysPthread.hh"
00022 #include "XrdSys/XrdSysTimer.hh"
00023
00024 const char *XrdNetCmsNotifyCVSID = "$Id: XrdNetCmsNotify.cc 35287 2010-09-14 21:19:35Z ganis $";
00025
00026
00027
00028
00029
00030 XrdNetCmsNotify::XrdNetCmsNotify(XrdSysError *erp, const char *aPath,
00031 const char *iName, int Opts)
00032 {
00033 char buff[1024], *p;
00034
00035
00036
00037 if (iName) iName = XrdOucUtils::InstName(iName,0);
00038
00039
00040
00041 p = XrdOucUtils::genPath(aPath, iName, ".olb");
00042 strcpy(buff, p); strcat(buff, (Opts & isServ ? "olbd.notes":"olbd.seton"));
00043 destPath = strdup(buff); free(p);
00044
00045
00046
00047 xMsg = new XrdNetMsg(erp, destPath);
00048
00049
00050
00051 eDest= erp;
00052 Pace = !(Opts & noPace);
00053 }
00054
00055
00056
00057
00058
00059 XrdNetCmsNotify::~XrdNetCmsNotify()
00060 {
00061 if (destPath) free(destPath);
00062 if (xMsg) delete xMsg;
00063 }
00064
00065
00066
00067
00068
00069 int XrdNetCmsNotify::Gone(const char *Path, int isPfn)
00070 {
00071 static const int Cln = 6;
00072 const char *Cmd = (isPfn ? "gone " : "rmdid ");
00073 char theMsg[MAXPATHLEN+8];
00074 int n;
00075
00076
00077
00078 if ((n = strlen(Path)) > MAXPATHLEN) return -ENAMETOOLONG;
00079 strcpy(theMsg, Cmd); strcpy(theMsg+Cln, Path);
00080 n += Cln; theMsg[n] = '\n';
00081
00082
00083
00084 return Send(theMsg, n);
00085 }
00086
00087
00088
00089
00090
00091 int XrdNetCmsNotify::Have(const char *Path, int isPfn)
00092 {
00093 static const int Cln = 6;
00094 const char *Cmd = (isPfn ? "have " : "newfn ");
00095 char theMsg[MAXPATHLEN+8];
00096 int n;
00097
00098
00099
00100 if ((n = strlen(Path)) > MAXPATHLEN) return -ENAMETOOLONG;
00101 strcpy(theMsg, Cmd); strcpy(theMsg+Cln, Path);
00102 n += Cln; theMsg[n] = '\n';
00103
00104
00105
00106 return Send(theMsg, n);
00107 }
00108
00109
00110
00111
00112
00113 int XrdNetCmsNotify::Send(const char *theMsg, int theLen)
00114 {
00115 static XrdSysMutex myMutex;
00116 int rc;
00117
00118
00119
00120 if (Pace) {myMutex.Lock(); XrdSysTimer::Wait(10); myMutex.UnLock();}
00121
00122
00123
00124 if ((rc = xMsg->Send(theMsg, theLen))) return rc < 0 ? rc : -ETIMEDOUT;
00125 return 0;
00126 }