Skip to content

Commit

Permalink
[SSI]Implement background stop for teh service.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 authored and simonmichal committed Jun 21, 2019
1 parent 5d40c32 commit 80f0326
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
17 changes: 15 additions & 2 deletions src/XrdSsi/XrdSsiServReal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void XrdSsiServReal::Recycle(XrdSsiSessReal *sObj, bool reuse)
EPNAME("Recycle");
static const char *tident = 0;
const char *resKey;
bool doDel;

// Clear all pending events (likely not needed)
//
Expand All @@ -256,6 +257,13 @@ void XrdSsiServReal::Recycle(XrdSsiSessReal *sObj, bool reuse)
DEBUG("Sess " <<sObj->GetSID() <<"# reuse=" <<reuse <<" free=" <<freeCnt
<<" active=" <<actvSes);
if (!reuse || freeCnt >= freeMax) {myMutex.UnLock(); delete sObj;}

doDel = ((actvSes == 0 && doStop) || !reuse || freeCnt >= freeMax);

DEBUG("reuse=" <<reuse <<" del=" <<doDel
<<"; sessions: free=" <<freeCnt <<" active=" <<actvSes);

if (doDel) {myMutex.UnLock(); delete sObj;}
else {sObj->nextSess = freeSes;
freeSes = sObj;
freeCnt++;
Expand Down Expand Up @@ -306,12 +314,17 @@ bool XrdSsiServReal::ResReuse(XrdSsiRequest &reqRef,
/* S t o p */
/******************************************************************************/

bool XrdSsiServReal::Stop()
bool XrdSsiServReal::Stop(bool immed)
{
// Make sure we are clean
//
myMutex.Lock();
if (actvSes) {myMutex.UnLock(); return false;}
if (actvSes)
{if (immed) {myMutex.UnLock(); return false;}
doStop = true;
myMutex.UnLock();
return true;
}
myMutex.UnLock();
delete this;
return true;
Expand Down
6 changes: 4 additions & 2 deletions src/XrdSsi/XrdSsiServReal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ void ProcessRequest(XrdSsiRequest &reqRef, XrdSsiResource &resRef);

void Recycle(XrdSsiSessReal *sObj, bool reuse);

bool Stop();
bool Stop(bool immed=false);

void StopReuse(const char *resKey);

XrdSsiServReal(const char *contact, int hObj)
: manNode(strdup(contact)), freeSes(0),
freeCnt(0), freeMax(hObj), actvSes(0) {}
freeCnt(0), freeMax(hObj), actvSes(0),
doStop(false) {}

~XrdSsiServReal();
private:
Expand All @@ -71,5 +72,6 @@ XrdSsiSessReal *freeSes;
int freeCnt;
int freeMax;
int actvSes;
bool doStop;
};
#endif
11 changes: 8 additions & 3 deletions src/XrdSsi/XrdSsiService.hh
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,17 @@ virtual void ProcessRequest(XrdSsiRequest &reqRef,
//-----------------------------------------------------------------------------
//! @brief Stop the client-side service. This is never called server-side.
//!
//! @return true Service has been stopped and this object has been deleted.
//! @param immed When true, the service is only stopped if here are no
//! active requests. Otherwise, after all requests have
//! finished. the service object is deleted.
//!
//! @return true Service has been stopped. Once all requests have been
//! completed, the service object will be deleted.
//! @return false Service cannot be stopped because there are still active
//! foreground requests. Cancel the requests then call Stop().
//! foreground requests and the immed parameter was true.
//-----------------------------------------------------------------------------

virtual bool Stop() {return false;}
virtual bool Stop(bool immed=false) {return !immed;}

//-----------------------------------------------------------------------------
//! Constructor
Expand Down

0 comments on commit 80f0326

Please sign in to comment.