XRootD
XrdTlsFlush Namespace Reference

Functions

void * Flusher (void *parg)
 
bool Setup_Flusher (XrdTlsContextImpl *pImpl, int flushT)
 

Function Documentation

◆ Flusher()

void* XrdTlsFlush::Flusher ( void *  parg)

Definition at line 178 of file XrdTlsContext.cc.

179 {
180  EPNAME("Flusher");
181  time_t tStart, tWaited;
182  int flushT, waitT, hits, miss, sesn, tmos;
183  long tNow;
184 
185 // Get the implementation details
186 //
187  XrdTlsContextImpl *ctxImpl = static_cast<XrdTlsContextImpl*>(parg);
188 
189 // Get the interval as it may change as we are running
190 //
191  ctxImpl->crlMutex.ReadLock();
192  waitT = flushT = ctxImpl->flushT;
193  ctxImpl->crlMutex.UnLock();
194 
195 // Indicate we have started in the trace record
196 //
197  DBG_CTX("Cache flusher started; interval="<<flushT<<" seconds.");
198 
199 // Do this forever
200 //
201 do{tStart = time(0);
202  ctxImpl->flsCVar->Wait(waitT);
203  tWaited= time(0) - tStart;
204 
205 // Check if this context is still alive. Generally, it never gets deleted.
206 //
207  ctxImpl->crlMutex.ReadLock();
208  if (!ctxImpl->owner) break;
209 
210 // If the interval changed, see if we should wait a bit longer
211 //
212  if (flushT != ctxImpl->flushT && tWaited < ctxImpl->flushT-1)
213  {waitT = ctxImpl->flushT - tWaited;
214  ctxImpl->crlMutex.UnLock();
215  continue;
216  }
217 
218 // Get the new values and drop the lock
219 //
220  waitT = flushT = ctxImpl->flushT;
221  ctxImpl->crlMutex.UnLock();
222 
223 // Get some relevant statistics
224 //
225  sesn = SSL_CTX_sess_number(ctxImpl->ctx);
226  hits = SSL_CTX_sess_hits(ctxImpl->ctx);
227  miss = SSL_CTX_sess_misses(ctxImpl->ctx);
228  tmos = SSL_CTX_sess_timeouts(ctxImpl->ctx);
229 
230 // Flush the cache
231 //
232  tNow = time(0);
233  SSL_CTX_flush_sessions(ctxImpl->ctx, tNow);
234 
235 // Print some stuff should debugging be on
236 //
237  if (TRACING(XrdTls::dbgCTX))
238  {char mBuff[512];
239  snprintf(mBuff, sizeof(mBuff), "sess=%d hits=%d miss=%d timeouts=%d",
240  sesn, hits, miss, tmos);
241  DBG_CTX("Cache flushed; " <<mBuff);
242  }
243  } while(true);
244 
245 // If we are here the context that started us has gone away and we are done
246 //
247  bool keepctx = ctxImpl->crlRunning;
248  ctxImpl->flsRunning = false;
249  ctxImpl->crlMutex.UnLock();
250  if (!keepctx) delete ctxImpl;
251  return (void *)0;
252 }
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
#define DBG_CTX(y)
Definition: XrdTlsTrace.hh:39
#define TRACING(x)
Definition: XrdTrace.hh:70
static const int dbgCTX
Turn debugging in for context operations.
Definition: XrdTls.hh:100
XrdTlsContext * owner
XrdSysCondVar * flsCVar
XrdSysRWLock crlMutex

References XrdTlsContextImpl::crlMutex, XrdTlsContextImpl::crlRunning, XrdTlsContextImpl::ctx, DBG_CTX, XrdTls::dbgCTX, EPNAME, XrdTlsContextImpl::flsCVar, XrdTlsContextImpl::flsRunning, XrdTlsContextImpl::flushT, XrdTlsContextImpl::owner, XrdSysRWLock::ReadLock(), TRACING, XrdSysRWLock::UnLock(), and XrdSysCondVar::Wait().

Referenced by Setup_Flusher().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Setup_Flusher()

bool XrdTlsFlush::Setup_Flusher ( XrdTlsContextImpl pImpl,
int  flushT 
)

Definition at line 258 of file XrdTlsContext.cc.

259 {
260  pthread_t tid;
261  int rc;
262 
263 // Set the new flush interval
264 //
265  pImpl->crlMutex.WriteLock();
266  pImpl->flushT = flushT;
267  pImpl->crlMutex.UnLock();
268 
269 // If the flush thread is already running, then wake it up to get the new value
270 //
271  if (pImpl->flsRunning)
272  {pImpl->flsCVar->Signal();
273  return true;
274  }
275 
276 // Start the flusher thread
277 //
278  pImpl->flsCVar = new XrdSysCondVar();
279  if ((rc = XrdSysThread::Run(&tid, XrdTlsFlush::Flusher, (void *)pImpl,
280  0, "Cache Flusher")))
281  {char eBuff[512];
282  snprintf(eBuff, sizeof(eBuff),
283  "Unable to start cache flusher thread; rc=%d", rc);
284  XrdTls::Emsg("SessCache:", eBuff, false);
285  return false;
286  }
287 
288 // Finish up
289 //
290  pImpl->flsRunning = true;
291  SSL_CTX_set_session_cache_mode(pImpl->ctx, SSL_SESS_CACHE_NO_AUTO_CLEAR);
292  return true;
293 }
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void Emsg(const char *tid, const char *msg=0, bool flush=true)
Definition: XrdTls.cc:104
void * Flusher(void *parg)

References XrdTlsContextImpl::crlMutex, XrdTlsContextImpl::ctx, XrdTls::Emsg(), XrdTlsContextImpl::flsCVar, XrdTlsContextImpl::flsRunning, Flusher(), XrdTlsContextImpl::flushT, XrdSysThread::Run(), XrdSysCondVar::Signal(), XrdSysRWLock::UnLock(), and XrdSysRWLock::WriteLock().

Referenced by XrdTlsContext::SessionCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: