XRootD
XrdCl::SIDManager Class Reference

Handle XRootD stream IDs. More...

#include <XrdClSIDManager.hh>

+ Collaboration diagram for XrdCl::SIDManager:

Public Member Functions

 ~SIDManager ()
 Destructor. More...
 
Status AllocateSID (uint8_t sid[2])
 
uint16_t GetNumberOfAllocatedSIDs () const
 Number of allocated streams. More...
 
bool IsAnySIDOldAs (const time_t tlim) const
 Check if any SID was allocated at or before a given time. More...
 
bool IsTimedOut (uint8_t sid[2])
 Check if a SID is timed out. More...
 
uint32_t NumberOfTimedOutSIDs () const
 Number of timeout sids. More...
 
void ReleaseAllTimedOut ()
 Release all timed out SIDs. More...
 
void ReleaseSID (uint8_t sid[2])
 Release the SID that is no longer needed. More...
 
void ReleaseTimedOut (uint8_t sid[2])
 Release a timed out SID. More...
 
void TimeOutSID (uint8_t sid[2])
 Register a SID of a request that timed out. More...
 

Friends

class SIDMgrPool
 

Detailed Description

Handle XRootD stream IDs.

Definition at line 42 of file XrdClSIDManager.hh.

Constructor & Destructor Documentation

◆ ~SIDManager()

XrdCl::SIDManager::~SIDManager ( )
inline

Destructor.

Definition at line 64 of file XrdClSIDManager.hh.

64 { }

Member Function Documentation

◆ AllocateSID()

Status XrdCl::SIDManager::AllocateSID ( uint8_t  sid[2])

Allocate a SID

Parameters
sida two byte array where the allocated SID should be stored
Returns
stOK on success, stError on error

Definition at line 28 of file XrdClSIDManager.cc.

29  {
30  XrdSysMutexHelper scopedLock( pMutex );
31 
32  uint16_t allocSID = 1;
33 
34  //--------------------------------------------------------------------------
35  // Get a SID from the list of free SIDs if it's not empty
36  //--------------------------------------------------------------------------
37  if( !pFreeSIDs.empty() )
38  {
39  allocSID = pFreeSIDs.front();
40  pFreeSIDs.pop_front();
41  }
42  //--------------------------------------------------------------------------
43  // Allocate a new SID if possible
44  //--------------------------------------------------------------------------
45  else
46  {
47  if( pSIDCeiling == 0xffff )
48  return Status( stError, errNoMoreFreeSIDs );
49  allocSID = pSIDCeiling++;
50  }
51 
52  memcpy( sid, &allocSID, 2 );
53  pAllocTime[allocSID] = time(0);
54  return Status();
55  }
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errNoMoreFreeSIDs
Definition: XrdClStatus.hh:97

References XrdCl::errNoMoreFreeSIDs, and XrdCl::stError.

◆ GetNumberOfAllocatedSIDs()

uint16_t XrdCl::SIDManager::GetNumberOfAllocatedSIDs ( ) const

Number of allocated streams.

Definition at line 135 of file XrdClSIDManager.cc.

136  {
137  XrdSysMutexHelper scopedLock( pMutex );
138  return pSIDCeiling - pFreeSIDs.size() - pTimeOutSIDs.size() - 1;
139  }

◆ IsAnySIDOldAs()

bool XrdCl::SIDManager::IsAnySIDOldAs ( const time_t  tlim) const

Check if any SID was allocated at or before a given time.

Definition at line 84 of file XrdClSIDManager.cc.

85  {
86  XrdSysMutexHelper scopedLock( pMutex );
87  return std::any_of( pAllocTime.begin(), pAllocTime.end(),
88  [tlim](const auto& p)
89  {
90  return p.second <= tlim;
91  } );
92  }

◆ IsTimedOut()

bool XrdCl::SIDManager::IsTimedOut ( uint8_t  sid[2])

Check if a SID is timed out.

Definition at line 97 of file XrdClSIDManager.cc.

98  {
99  XrdSysMutexHelper scopedLock( pMutex );
100  uint16_t tiSID = 0;
101  memcpy( &tiSID, sid, 2 );
102  std::set<uint16_t>::iterator it = pTimeOutSIDs.find( tiSID );
103  if( it != pTimeOutSIDs.end() )
104  return true;
105  return false;
106  }

◆ NumberOfTimedOutSIDs()

uint32_t XrdCl::SIDManager::NumberOfTimedOutSIDs ( ) const
inline

Number of timeout sids.

Definition at line 109 of file XrdClSIDManager.hh.

110  {
111  XrdSysMutexHelper scopedLock( pMutex );
112  return pTimeOutSIDs.size();
113  }

◆ ReleaseAllTimedOut()

void XrdCl::SIDManager::ReleaseAllTimedOut ( )

Release all timed out SIDs.

Definition at line 123 of file XrdClSIDManager.cc.

124  {
125  XrdSysMutexHelper scopedLock( pMutex );
126  std::set<uint16_t>::iterator it;
127  for( it = pTimeOutSIDs.begin(); it != pTimeOutSIDs.end(); ++it )
128  pFreeSIDs.push_back( *it );
129  pTimeOutSIDs.clear();
130  }

◆ ReleaseSID()

void XrdCl::SIDManager::ReleaseSID ( uint8_t  sid[2])

Release the SID that is no longer needed.

Definition at line 60 of file XrdClSIDManager.cc.

61  {
62  XrdSysMutexHelper scopedLock( pMutex );
63  uint16_t relSID = 0;
64  memcpy( &relSID, sid, 2 );
65  pFreeSIDs.push_back( relSID );
66  pAllocTime.erase( relSID );
67  }

◆ ReleaseTimedOut()

void XrdCl::SIDManager::ReleaseTimedOut ( uint8_t  sid[2])

Release a timed out SID.

Definition at line 111 of file XrdClSIDManager.cc.

112  {
113  XrdSysMutexHelper scopedLock( pMutex );
114  uint16_t tiSID = 0;
115  memcpy( &tiSID, sid, 2 );
116  pTimeOutSIDs.erase( tiSID );
117  pFreeSIDs.push_back( tiSID );
118  }

◆ TimeOutSID()

void XrdCl::SIDManager::TimeOutSID ( uint8_t  sid[2])

Register a SID of a request that timed out.

Definition at line 72 of file XrdClSIDManager.cc.

73  {
74  XrdSysMutexHelper scopedLock( pMutex );
75  uint16_t tiSID = 0;
76  memcpy( &tiSID, sid, 2 );
77  pTimeOutSIDs.insert( tiSID );
78  pAllocTime.erase( tiSID );
79  }

Friends And Related Function Documentation

◆ SIDMgrPool

friend class SIDMgrPool
friend

Definition at line 44 of file XrdClSIDManager.hh.


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