@@ -115,27 +115,6 @@ AuthenticatedChannelFactoryConfig::AuthenticatedChannelFactoryConfig(
115115// ---------------------------------
116116
117117// PRIVATE ACCESSORS
118- void AuthenticatedChannelFactory::baseResultCallback (
119- const ResultCallback& cb,
120- bmqio::ChannelFactoryEvent::Enum event,
121- const bmqio::Status& status,
122- const bsl::shared_ptr<bmqio::Channel>& channel) const
123- {
124- if (event != bmqio::ChannelFactoryEvent::e_CHANNEL_UP) {
125- cb (event, status, channel);
126- return ; // RETURN
127- }
128-
129- // We will skip authentication if no authentication credential
130- // callback provided.
131- if (d_config.d_authnCredentialCb ) {
132- authenticate (channel, cb);
133- }
134- else {
135- cb (event, status, channel);
136- }
137- }
138-
139118void AuthenticatedChannelFactory::sendRequest (
140119 const bsl::shared_ptr<bmqio::Channel>& channel,
141120 const ResultCallback& cb) const
@@ -227,12 +206,49 @@ void AuthenticatedChannelFactory::authenticate(
227206 readResponse (channel, cb);
228207}
229208
209+ int AuthenticatedChannelFactory::timeoutInterval (int lifetimeMs) const
210+ {
211+ BSLS_ASSERT_SAFE (lifetimeMs >= 0 );
212+ const int intervalMsWithRatio = lifetimeMs * k_REAUTHN_EARLY_RATIO;
213+ const int intervalMsWithBuffer = bsl::max (0 ,
214+ lifetimeMs -
215+ k_REAUTHN_EARLY_BUFFER);
216+ return bsl::min (intervalMsWithRatio, intervalMsWithBuffer);
217+ }
218+
219+ // PRIVATE MANIPULATORS
220+ void AuthenticatedChannelFactory::baseResultCallback (
221+ const ResultCallback& cb,
222+ bmqio::ChannelFactoryEvent::Enum event,
223+ const bmqio::Status& status,
224+ const bsl::shared_ptr<bmqio::Channel>& channel)
225+ {
226+ if (event != bmqio::ChannelFactoryEvent::e_CHANNEL_UP) {
227+ cb (event, status, channel);
228+ return ; // RETURN
229+ }
230+
231+ channel->onClose (
232+ bdlf::BindUtil::bind (&AuthenticatedChannelFactory::onChannelDown,
233+ this ,
234+ bdlf::PlaceHolders::_1)); // status
235+
236+ // We will skip authentication if no authentication credential
237+ // callback provided.
238+ if (d_config.d_authnCredentialCb ) {
239+ authenticate (channel, cb);
240+ }
241+ else {
242+ cb (event, status, channel);
243+ }
244+ }
245+
230246void AuthenticatedChannelFactory::readPacketsCb (
231247 const bsl::shared_ptr<bmqio::Channel>& channel,
232248 const ResultCallback& cb,
233249 const bmqio::Status& status,
234250 int * numNeeded,
235- bdlbb::Blob* blob) const
251+ bdlbb::Blob* blob)
236252{
237253 if (!status) {
238254 // Read failure.
@@ -272,7 +288,7 @@ void AuthenticatedChannelFactory::readPacketsCb(
272288void AuthenticatedChannelFactory::onBrokerAuthenticationResponse (
273289 const bdlbb::Blob& packet,
274290 const ResultCallback& cb,
275- const bsl::shared_ptr<bmqio::Channel>& channel) const
291+ const bsl::shared_ptr<bmqio::Channel>& channel)
276292{
277293 BALL_LOG_TRACE << " Received a packet:\n "
278294 << bmqu::BlobStartHexDumper (&packet);
@@ -303,20 +319,19 @@ void AuthenticatedChannelFactory::onBrokerAuthenticationResponse(
303319 cb (bmqio::ChannelFactoryEvent::e_CHANNEL_UP, bmqio::Status (), channel);
304320}
305321
306- int AuthenticatedChannelFactory::timeoutInterval (int lifetimeMs) const
322+ void AuthenticatedChannelFactory::onChannelDown (
323+ BSLA_UNUSED const bmqio::Status& status)
307324{
308- BSLS_ASSERT_SAFE (lifetimeMs >= 0 );
309- const int intervalMsWithRatio = lifetimeMs * k_REAUTHN_EARLY_RATIO;
310- const int intervalMsWithBuffer = bsl::max (0 ,
311- lifetimeMs -
312- k_REAUTHN_EARLY_BUFFER);
313- return bsl::min (intervalMsWithRatio, intervalMsWithBuffer);
325+ // executed by the *IO* thread
326+
327+ // Cancel pending reauthentication event when a channel goes down.
328+ d_config.d_scheduler_p ->cancelEvent (&d_reauthenticationTimeoutHandle);
314329}
315330
316331void AuthenticatedChannelFactory::processAuthenticationEvent (
317332 const bmqp::Event& event,
318333 const ResultCallback& cb,
319- const bsl::shared_ptr<bmqio::Channel>& channel) const
334+ const bsl::shared_ptr<bmqio::Channel>& channel)
320335{
321336 bmqp_ctrlmsg::AuthenticationMessage response;
322337 const int rc = event.loadAuthenticationEvent (&response);
@@ -372,6 +387,7 @@ void AuthenticatedChannelFactory::processAuthenticationEvent(
372387
373388 // Pening events will be cancelled when Application stops.
374389 d_config.d_scheduler_p ->scheduleEvent (
390+ &d_reauthenticationTimeoutHandle,
375391 bsls::TimeInterval (bmqsys::Time::nowMonotonicClock ())
376392 .addMilliseconds (intervalMs),
377393 bdlf::BindUtil::bind (&AuthenticatedChannelFactory::sendRequest,
0 commit comments