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

#include <XrdSutAux.hh>

+ Collaboration diagram for XrdSutFileLocker:

Public Types

enum  ELockType {
  kShared = 0 ,
  kExcl = 1
}
 

Public Member Functions

 XrdSutFileLocker (int fd, ELockType lock)
 
 ~XrdSutFileLocker ()
 
bool IsValid () const
 

Detailed Description

Definition at line 238 of file XrdSutAux.hh.

Member Enumeration Documentation

◆ ELockType

Enumerator
kShared 
kExcl 

Definition at line 243 of file XrdSutAux.hh.

Constructor & Destructor Documentation

◆ XrdSutFileLocker()

XrdSutFileLocker::XrdSutFileLocker ( int  fd,
ELockType  lock 
)

Definition at line 621 of file XrdSutAux.cc.

622{
623 // Constructor: locks the file in 'lock' mode.
624 // Use IsValid() to test success.
625
626 valid = 0;
627 fdesk = fd;
628
629 // Exclusive lock of the whole file
630 int lockmode = (lock == XrdSutFileLocker::kExcl) ? (F_WRLCK | F_RDLCK)
631 : F_RDLCK;
632 struct flock flck;
633 memset(&flck, 0, sizeof(flck));
634 flck.l_type = lockmode;
635 flck.l_whence = SEEK_SET;
636 if (fcntl(fdesk, F_SETLK, &flck) != 0)
637 // Failure
638 return;
639
640 // Success
641 valid = 1;
642}
int fcntl(int fd, int cmd,...)

References fcntl(), and kExcl.

+ Here is the call graph for this function:

◆ ~XrdSutFileLocker()

XrdSutFileLocker::~XrdSutFileLocker ( )

Definition at line 644 of file XrdSutAux.cc.

645{
646 // Destructor: unlocks the file if locked.
647
648 if (fdesk < 0 || !IsValid())
649 return;
650 //
651 // Unlock the file
652 struct flock flck = {F_UNLCK, SEEK_SET, 0, 0, 0};
653 memset(&flck, 0, sizeof(flck));
654 flck.l_type = F_UNLCK;
655 flck.l_whence = SEEK_SET;
656 fcntl(fdesk, F_SETLK, &flck);
657}
bool IsValid() const
Definition XrdSutAux.hh:246

References fcntl(), and IsValid().

+ Here is the call graph for this function:

Member Function Documentation

◆ IsValid()

bool XrdSutFileLocker::IsValid ( ) const
inline

Definition at line 246 of file XrdSutAux.hh.

246{ return valid; }

Referenced by ~XrdSutFileLocker(), and XrdCryptosslX509ChainToFile().

+ Here is the caller graph for this function:

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