LCOV - code coverage report
Current view: top level - xmpp - xmpp_connection_manager.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 27 48.1 %
Date: 2026-06-22 02:21:21 Functions: 3 6 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "xmpp/xmpp_connection_manager.h"
       6             : 
       7             : #include <boost/bind/bind.hpp>
       8             : 
       9             : #include "base/lifetime.h"
      10             : #include "base/task_annotations.h"
      11             : #include "xmpp/xmpp_session.h"
      12             : 
      13             : using namespace boost::placeholders;
      14             : 
      15             : //
      16             : // Constructor for XmppConnectionManager.
      17             : //
      18        7192 : XmppConnectionManager::XmppConnectionManager(EventManager *evm,
      19             :     boost::asio::ssl::context::method m,
      20        7192 :     bool ssl_enabled, bool ssl_handshake_delayed)
      21             :     : SslServer(evm, m, ssl_enabled, ssl_handshake_delayed),
      22        7192 :       session_queue_(TaskScheduler::GetInstance()->GetTaskId("bgp::Config"),
      23       14384 :           0, boost::bind(&XmppConnectionManager::DequeueSession, this, _1)) {
      24        7192 : }
      25             : 
      26             : //
      27             : // Shutdown the XmppConnectionManager.
      28             : //
      29             : // Register an exit callback to the session WorkQueue so that we can retry
      30             : // deletion when the WorkQueue becomes empty.
      31             : //
      32        7190 : void XmppConnectionManager::Shutdown() {
      33        7190 :     TcpServer::Shutdown();
      34        7190 :     session_queue_.SetExitCallback(
      35             :         boost::bind(&XmppConnectionManager::WorkQueueExitCallback, this, _1));
      36        7190 :     session_queue_.Shutdown();
      37        7190 : }
      38             : 
      39             : //
      40             : // Concurrency: called in the context of io thread.
      41             : //
      42             : // Add a XmppSession to the queue of write ready sessions.
      43             : // Take a reference to make sure that XmppSession doesn't get deleted before
      44             : // it's processed.
      45             : //
      46           0 : void XmppConnectionManager::EnqueueSession(XmppSession *session) {
      47           0 :     if (deleter()->IsDeleted())
      48           0 :         return;
      49           0 :     session_queue_.Enqueue(TcpSessionPtr(session));
      50             : }
      51             : 
      52             : //
      53             : // Concurrency: called in the context of bgp::Config task.
      54             : //
      55             : // Handler for XmppSessions that are dequeued from the session WorkQueue.
      56             : //
      57             : // The Xmpp[Client|Server] doesn't get destroyed if the WorkQueue is non-empty.
      58             : //
      59           0 : bool XmppConnectionManager::DequeueSession(TcpSessionPtr tcp_session) {
      60           0 :     CHECK_CONCURRENCY("bgp::Config");
      61           0 :     XmppSession *session = static_cast<XmppSession *>(tcp_session.get());
      62           0 :     session->ProcessWriteReady();
      63           0 :     return true;
      64             : }
      65             : 
      66             : //
      67             : // Exit callback for the session WorkQueue.
      68             : //
      69           0 : void XmppConnectionManager::WorkQueueExitCallback(bool done) {
      70           0 :     CHECK_CONCURRENCY("bgp::Config");
      71           0 :     if (!deleter()->IsDeleted())
      72           0 :         return;
      73           0 :     deleter()->RetryDelete();
      74             : }
      75             : 
      76             : //
      77             : // Return size of WorkQueue of write ready XmppSessions.
      78             : //
      79        7190 : size_t XmppConnectionManager::GetSessionQueueSize() const {
      80        7190 :     CHECK_CONCURRENCY("bgp::Config");
      81        7190 :     return session_queue_.Length();
      82             : }

Generated by: LCOV version 1.14