XrdNetCmsNotify.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                    X r d N e t C m s N o t i f y . c c                     */
00004 /*                                                                            */
00005 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //       $Id: XrdNetCmsNotify.cc 35287 2010-09-14 21:19:35Z ganis $
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 /*                           C o n s t r u c t o r                            */
00028 /******************************************************************************/
00029   
00030 XrdNetCmsNotify::XrdNetCmsNotify(XrdSysError *erp, const char *aPath, 
00031                                  const char *iName, int Opts)
00032 {
00033    char buff[1024], *p;
00034 
00035 // Make sure we are not getting anon as an instance name
00036 //
00037    if (iName) iName = XrdOucUtils::InstName(iName,0);
00038 
00039 // Construct the path for notification
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 // Construct message object
00046 //
00047    xMsg = new XrdNetMsg(erp, destPath);
00048 
00049 // Complete initialization
00050 //
00051    eDest= erp;
00052    Pace = !(Opts & noPace);
00053 }
00054 
00055 /******************************************************************************/
00056 /*                            D e s t r u c t o r                             */
00057 /******************************************************************************/
00058   
00059 XrdNetCmsNotify::~XrdNetCmsNotify()
00060 {
00061    if (destPath) free(destPath);
00062    if (xMsg) delete xMsg;
00063 }
00064 
00065 /******************************************************************************/
00066 /*                                  G o n e                                   */
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 // Construct message to be sent
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 // Send the message
00083 //
00084    return Send(theMsg, n);
00085 }
00086 
00087 /******************************************************************************/
00088 /*                                  H a v e                                   */
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 // Construct message to be sent
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 // Send the message
00105 //
00106    return Send(theMsg, n);
00107 }
00108 
00109 /******************************************************************************/
00110 /*                                  S e n d                                   */
00111 /******************************************************************************/
00112   
00113 int XrdNetCmsNotify::Send(const char *theMsg, int theLen)
00114 {
00115    static XrdSysMutex myMutex;
00116    int rc;
00117 
00118 // Check if pacing is in effect
00119 //
00120    if (Pace) {myMutex.Lock(); XrdSysTimer::Wait(10); myMutex.UnLock();}
00121 
00122 // Send the message
00123 //
00124    if ((rc = xMsg->Send(theMsg, theLen))) return rc < 0 ? rc : -ETIMEDOUT;
00125    return 0;
00126 }

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