File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -377,6 +377,10 @@ void TCPSessionFactory::handleInitialConnection(
377377 bdlf::PlaceHolders::_5, // initialConnectionContext
378378 context));
379379
380+ // Cache the context. It will be removed in 'initialConnectionComplete'.
381+ d_initialConnectionContextCache[initialConnectionContext.get ()] =
382+ initialConnectionContext;
383+
380384 // Register as observer of the channel to get the 'onClose'
381385 channel->onClose (
382386 bdlf::BindUtil::bindS (d_allocator_p,
@@ -554,8 +558,14 @@ void TCPSessionFactory::initialConnectionComplete(
554558 return ; // RETURN
555559 }
556560
561+ // Remove the cached InitialConnectionContext
562+ BSLS_ASSERT_SAFE (
563+ d_initialConnectionContextCache.contains (initialConnectionContext_p));
564+ bsl::shared_ptr<InitialConnectionContext> initialConnectionContext_sp =
565+ d_initialConnectionContextCache.at (initialConnectionContext_p);
566+ d_initialConnectionContextCache.erase (initialConnectionContext_p);
567+
557568 // Successful negotiation
558- BSLS_ASSERT_SAFE (initialConnectionContext_p);
559569 BSLS_ASSERT_SAFE (initialConnectionContext_p->negotiationContext ());
560570
561571 BALL_LOG_INFO
Original file line number Diff line number Diff line change @@ -269,6 +269,10 @@ class TCPSessionFactory {
269269
270270 typedef bslma::ManagedPtr<bmqio::StatChannelFactory> StatChannelFactoryMp;
271271
272+ typedef bsl::unordered_map<const InitialConnectionContext*,
273+ bsl::shared_ptr<InitialConnectionContext> >
274+ InitialConnectionContextMp;
275+
272276 typedef TCPSessionFactory_OperationContext OperationContext;
273277
274278 typedef bsl::shared_ptr<bmqio::ChannelFactory::OpHandle> OpHandleSp;
@@ -319,6 +323,14 @@ class TCPSessionFactory {
319323
320324 StatChannelFactoryMp d_statChannelFactory_mp;
321325
326+ // / Cache of shared pointers to @bbref{mqbnet::InitialConnectionContext} to
327+ // / preserve their lifetime while an initial connection
328+ // / (authentication/negotiation) is in progress. Each context is added by
329+ // / @bbref{handleInitialConnection} and removed by
330+ // / @bbref{initialConnectionComplete} once negotiation finishes (success or
331+ // / failure).
332+ InitialConnectionContextMp d_initialConnectionContextCache;
333+
322334 // / Name to use for the IO threads
323335 bsl::string d_threadName;
324336
You can’t perform that action at this time.
0 commit comments