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