XRootD
Loading...
Searching...
No Matches
XrdNetCmsNotify.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d N e t C m s N o t i f y . c c */
4/* */
5/* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <cstdlib>
32#include <cstring>
33#include <sys/param.h>
34
36#include "XrdNet/XrdNetMsg.hh"
37#include "XrdOuc/XrdOucUtils.hh"
38#include "XrdSys/XrdSysError.hh"
40#include "XrdSys/XrdSysTimer.hh"
41
42/******************************************************************************/
43/* C o n s t r u c t o r */
44/******************************************************************************/
45
47 const char *iName, int Opts)
48{
49 char buff[1024], *p;
50
51// Make sure we are not getting anon as an instance name
52//
53 if (iName) iName = XrdOucUtils::InstName(iName,0);
54
55// Construct the path for notification
56//
57 p = XrdOucUtils::genPath(aPath, iName, ".olb");
58 strcpy(buff, p); strcat(buff, (Opts & isServ ? "olbd.notes":"olbd.seton"));
59 destPath = strdup(buff); free(p);
60
61// Construct message object
62//
63 xMsg = new XrdNetMsg(erp, destPath);
64
65// Complete initialization
66//
67 eDest= erp;
68 Pace = !(Opts & noPace);
69}
70
71/******************************************************************************/
72/* D e s t r u c t o r */
73/******************************************************************************/
74
76{
77 if (destPath) free(destPath);
78 if (xMsg) delete xMsg;
79}
80
81/******************************************************************************/
82/* G o n e */
83/******************************************************************************/
84
85int XrdNetCmsNotify::Gone(const char *Path, int isPfn)
86{
87 static const int Cln = 6;
88 const char *Cmd = (isPfn ? "gone " : "rmdid ");
89 char theMsg[MAXPATHLEN+8];
90 int n;
91
92// Construct message to be sent
93//
94 if ((n = strlen(Path)) > MAXPATHLEN) return -ENAMETOOLONG;
95 strcpy(theMsg, Cmd); strcpy(theMsg+Cln, Path);
96 n += Cln; theMsg[n] = '\n';
97
98// Send the message
99//
100 return Send(theMsg, n);
101}
102
103/******************************************************************************/
104/* H a v e */
105/******************************************************************************/
106
107int XrdNetCmsNotify::Have(const char *Path, int isPfn)
108{
109 static const int Cln = 6;
110 const char *Cmd = (isPfn ? "have " : "newfn ");
111 char theMsg[MAXPATHLEN+8];
112 int n;
113
114// Construct message to be sent
115//
116 if ((n = strlen(Path)) > MAXPATHLEN) return -ENAMETOOLONG;
117 strcpy(theMsg, Cmd); strcpy(theMsg+Cln, Path);
118 n += Cln; theMsg[n] = '\n';
119
120// Send the message
121//
122 return Send(theMsg, n);
123}
124
125/******************************************************************************/
126/* S e n d */
127/******************************************************************************/
128
129int XrdNetCmsNotify::Send(const char *theMsg, int theLen)
130{
131 static XrdSysMutex myMutex;
132 int rc;
133
134// Check if pacing is in effect
135//
136 if (Pace) {myMutex.Lock(); XrdSysTimer::Wait(10); myMutex.UnLock();}
137
138// Send the message
139//
140 if ((rc = xMsg->Send(theMsg, theLen))) return rc < 0 ? rc : -ETIMEDOUT;
141 return 0;
142}
XrdOucString Path
static const int isServ
int Have(const char *Path, int isPfn=1)
static const int noPace
XrdNetCmsNotify(XrdSysError *erp, const char *aPath, const char *iName, int Opts=0)
int Gone(const char *Path, int isPfn=1)
static char * genPath(const char *path, const char *inst, const char *psfx=0)
static const char * InstName(int TranOpt=0)
static void Wait(int milliseconds)