Skip to content

Commit

Permalink
Fix listening handles map using ManagedPtr as value
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Foxhall <[email protected]>
  • Loading branch information
hallfox committed Nov 8, 2024
1 parent 613c5ba commit 5cf71ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/groups/mqb/mqbnet/mqbnet_tcpsessionfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,8 @@ TCPSessionFactory::TCPSessionFactory(
, d_initialMissedHeartbeatCounter(calculateInitialMissedHbCounter(config))
, d_listeningHandles(allocator)
, d_isListening(false)
, d_timestampMap(allocator)
, d_listenContexts(allocator)
, d_timestampMap(allocator)
, d_allocator_p(allocator)
{
// PRECONDITIONS
Expand Down Expand Up @@ -1392,6 +1392,8 @@ int TCPSessionFactory::listen(const mqbcfg::TcpInterfaceListener& listener,
const int port = listener.port();

BSLS_ASSERT_SAFE(d_listenContexts.find(port) == d_listenContexts.cend());
BSLS_ASSERT_SAFE(d_listeningHandles.find(port) ==
d_listeningHandles.cend());

// Maintain ownership of 'OperationContext' instead of passing it to
// 'ChannelFactory::listen' because it may delete the context
Expand All @@ -1411,12 +1413,11 @@ int TCPSessionFactory::listen(const mqbcfg::TcpInterfaceListener& listener,
bmqio::ListenOptions listenOptions;
listenOptions.setEndpoint(endpoint.str());

OpHandleMp& listeningHandle = d_listeningHandles[port];

bslma::ManagedPtr<bmqio::ChannelFactory::OpHandle> listeningHandle_mp;
bmqio::Status status;
d_statChannelFactory_mp->listen(
&status,
&listeningHandle,
&listeningHandle_mp,
listenOptions,
bdlf::BindUtil::bind(&TCPSessionFactory::channelStateCallback,
this,
Expand All @@ -1433,7 +1434,11 @@ int TCPSessionFactory::listen(const mqbcfg::TcpInterfaceListener& listener,
return status.category(); // RETURN
}

BSLS_ASSERT_SAFE(listeningHandle);
BSLS_ASSERT_SAFE(listeningHandle_mp);

OpHandleSp listeningHandle_sp(listeningHandle_mp, d_allocator_p);
d_listeningHandles.emplace(port, listeningHandle_sp);

BALL_LOG_INFO << "TCPSessionFactory '" << d_config.name() << "' "
<< "successfully listening to '" << endpoint.str() << "'";

Expand Down
4 changes: 2 additions & 2 deletions src/groups/mqb/mqbnet/mqbnet_tcpsessionfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ class TCPSessionFactory {

typedef TCPSessionFactory_OperationContext OperationContext;

typedef bslma::ManagedPtr<bmqio::ChannelFactory::OpHandle> OpHandleMp;
typedef bsl::shared_ptr<bmqio::ChannelFactory::OpHandle> OpHandleSp;

typedef bsl::unordered_map<bmqio::Channel*, bsls::Types::Int64>
TimestampMap;

typedef bsl::unordered_map<int, OpHandleMp> ListeningHandleMap;
typedef bsl::unordered_map<int, OpHandleSp> ListeningHandleMap;

private:
// DATA
Expand Down

0 comments on commit 5cf71ff

Please sign in to comment.