XRootD
Loading...
Searching...
No Matches
XrdOucSxeq Class Reference

#include <XrdOucSxeq.hh>

+ Collaboration diagram for XrdOucSxeq:

Public Member Functions

 XrdOucSxeq (const char *sfx, const char *sfx1=0, const char *Dir="/tmp/")
 
 XrdOucSxeq (int sOpts, const char *path)
 
 ~XrdOucSxeq ()
 
int Detach ()
 
int lastError ()
 
int Release ()
 
int Serialize (int Opts=0)
 

Static Public Member Functions

static int Release (int fileD)
 
static int Serialize (int fileD, int Opts)
 

Static Public Attributes

static const int Lock = 0x0008
 
static const int noWait = 0x0001
 
static const int Share = 0x0002
 
static const int Unlink = 0x0004
 

Detailed Description

Definition at line 33 of file XrdOucSxeq.hh.

Constructor & Destructor Documentation

◆ XrdOucSxeq() [1/2]

XrdOucSxeq::XrdOucSxeq ( int sOpts,
const char * path )

Definition at line 48 of file XrdOucSxeq.cc.

49{
50 static const int AMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
51 lokFN = strdup(path);
52 lokUL = 0;
53
54// Open the file, creating it
55//
56 if ((lokFD = open(lokFN, O_CREAT|O_RDWR, AMode)) < 0) lokRC = errno;
57 else {lokRC = 0;
58 if (sOpts) Serialize(sOpts);
59 }
60}
#define open
Definition XrdPosix.hh:76
int Serialize(int Opts=0)

References open, and Serialize().

+ Here is the call graph for this function:

◆ XrdOucSxeq() [2/2]

XrdOucSxeq::XrdOucSxeq ( const char * sfx,
const char * sfx1 = 0,
const char * Dir = "/tmp/" )

Definition at line 64 of file XrdOucSxeq.cc.

65{
66 static const int AMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
67 char pbuff[MAXPATHLEN+1], *pP;
68
69// Construct the lock file name
70//
71 strcpy(pbuff, Dir);
72 pP = pbuff + strlen(Dir);
73 if (*sfx1 != '/' && *(pP-1) != '/') *pP++ = '/';
74 strcpy(pP, sfx1);
75 if (sfx2) strcpy(pP+strlen(sfx1), sfx2);
76 lokFN = strdup(pbuff);
77 lokUL = 0;
78
79// Open the file, creating it
80//
81 if ((lokFD = open(lokFN, O_CREAT|O_RDWR, AMode)) < 0) lokRC = errno;
82 else lokRC = 0;
83}
XrdOucString Dir

References Dir, and open.

◆ ~XrdOucSxeq()

XrdOucSxeq::~XrdOucSxeq ( )

Definition at line 89 of file XrdOucSxeq.cc.

90{
91
92// Check if we should unlink this file we need to do so while it's locked)
93//
94 if (lokFD >= 0 && lokUL) unlink(lokFN);
95
96// Close the file and free th file name
97//
98 if (lokFD >= 0) close(lokFD);
99 free(lokFN);
100}
#define close(a)
Definition XrdPosix.hh:48
#define unlink(a)
Definition XrdPosix.hh:113

References close, and unlink.

Member Function Documentation

◆ Detach()

int XrdOucSxeq::Detach ( )
inline

Definition at line 42 of file XrdOucSxeq.hh.

42{int lFD = lokFD; lokFD = -1; return lFD;}

Referenced by XrdFrcXLock::Init().

+ Here is the caller graph for this function:

◆ lastError()

int XrdOucSxeq::lastError ( )
inline

Definition at line 54 of file XrdOucSxeq.hh.

54{return lokRC;}

◆ Release() [1/2]

int XrdOucSxeq::Release ( )

Definition at line 106 of file XrdOucSxeq.cc.

107{
108 FLOCK_t lock_args;
109 int rc;
110
111// If the file is not open, return failure
112//
113 if (lokFD < 0) return 0;
114
115// Establish locking options
116//
117 bzero(&lock_args, sizeof(lock_args));
118 lock_args.l_type = F_UNLCK;
119
120// Now perform the action
121//
122 do {rc = fcntl(lokFD, F_SETLKW, &lock_args);}
123 while(rc < 0 && errno == EINTR);
124
125// Determine result
126//
127 if (rc < 0) {lokRC = errno; return 0;}
128
129// We succeeded, unlink is not possible now
130//
131 lokUL = 0;
132 lokRC = 0;
133 return 1;
134}
#define FLOCK_t

References FLOCK_t.

Referenced by XrdFrcXLock::~XrdFrcXLock().

+ Here is the caller graph for this function:

◆ Release() [2/2]

int XrdOucSxeq::Release ( int fileD)
static

Definition at line 137 of file XrdOucSxeq.cc.

138{
139 FLOCK_t lock_args;
140 int rc;
141
142// If the file is not open, return failure
143//
144 if (fileD < 0) return EBADF;
145
146// Establish locking options
147//
148 bzero(&lock_args, sizeof(lock_args));
149 lock_args.l_type = F_UNLCK;
150
151// Now perform the action
152//
153 do {rc = fcntl(fileD, F_SETLKW, &lock_args);}
154 while(rc < 0 && errno == EINTR);
155
156// Return result
157//
158 return (rc ? errno : 0);
159}

References FLOCK_t.

◆ Serialize() [1/2]

int XrdOucSxeq::Serialize ( int fileD,
int Opts )
static

Definition at line 200 of file XrdOucSxeq.cc.

201{
202 FLOCK_t lock_args;
203
204// Make sure we have a lock outstanding
205//
206 if (fileD < 0) return EBADF;
207
208// Establish locking options
209//
210 bzero(&lock_args, sizeof(lock_args));
211 if (opts & Share) lock_args.l_type = F_RDLCK;
212 else lock_args.l_type = F_WRLCK;
213
214// Perform action.
215//
216 if (fcntl(fileD, (opts & noWait ? F_SETLK : F_SETLKW), &lock_args))
217 return errno;
218 return 0;
219}
struct myOpts opts
static const int Share
Definition XrdOucSxeq.hh:38
static const int noWait
Definition XrdOucSxeq.hh:37

References FLOCK_t, noWait, opts, and Share.

◆ Serialize() [2/2]

int XrdOucSxeq::Serialize ( int Opts = 0)

Definition at line 165 of file XrdOucSxeq.cc.

166{
167 FLOCK_t lock_args;
168 int Act, rc;
169
170// If the file is not open, return failure
171//
172 if (lokFD < 0) return 0;
173
174// Establish lock flags
175//
176
177// Establish locking options
178//
179 bzero(&lock_args, sizeof(lock_args));
180 lock_args.l_type = (Opts & Share ? F_RDLCK : F_WRLCK);
181 Act = (Opts & noWait ? F_SETLK : F_SETLKW);
182
183// Now perform the action
184//
185 do {rc = fcntl(lokFD, Act, &lock_args);} while(rc < 0 && errno == EINTR);
186
187// Determine result
188//
189 if (rc < 0) {lokRC = errno; return 0;}
190
191// We succeeded check if an unlink is possible
192//
193 if (Opts & Unlink && !(Opts & Share)) lokUL = 1;
194 lokRC = 0;
195 return 1;
196}
static const int Unlink
Definition XrdOucSxeq.hh:39

References FLOCK_t, noWait, Share, and Unlink.

Referenced by XrdFrcXLock::XrdFrcXLock(), and XrdOucSxeq().

+ Here is the caller graph for this function:

Member Data Documentation

◆ Lock

const int XrdOucSxeq::Lock = 0x0008
static

Definition at line 40 of file XrdOucSxeq.hh.

◆ noWait

const int XrdOucSxeq::noWait = 0x0001
static

Definition at line 37 of file XrdOucSxeq.hh.

Referenced by Serialize(), and Serialize().

◆ Share

const int XrdOucSxeq::Share = 0x0002
static

Definition at line 38 of file XrdOucSxeq.hh.

Referenced by Serialize(), and Serialize().

◆ Unlink

const int XrdOucSxeq::Unlink = 0x0004
static

Definition at line 39 of file XrdOucSxeq.hh.

Referenced by Serialize().


The documentation for this class was generated from the following files: