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: 21 27 77.8 %
Date: 2026-11-09 02:10:49 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14