Skip to content

Commit

Permalink
Replace DispatchSessionEvent with NotifySessionHang on sessions. (#…
Browse files Browse the repository at this point in the history
…33259)

* Replace `Dispatch event` with `NotifySessionHang` on sessions.

Only a single event was ever dispatched and the pattern of passing
in pointers to member methods was not used anywhere else and resulted
in fairly unique code.

Spelling out the `NotifySessionHang` explicitly seems to simplify
maintainability.

* Update src/transport/Session.h

Co-authored-by: mkardous-silabs <[email protected]>

---------

Co-authored-by: mkardous-silabs <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 3, 2024
1 parent e963031 commit 1406076
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void ExchangeContext::NotifyResponseTimeout(bool aCloseIfNeeded)
{
mSession->AsSecureSession()->MarkAsDefunct();
}
mSession->DispatchSessionEvent(&SessionDelegate::OnSessionHang);
mSession->NotifySessionHang();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/messaging/ReliableMessageMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void ReliableMessageMgr::ExecuteActions()
{
session->AsSecureSession()->MarkAsDefunct();
}
session->DispatchSessionEvent(&SessionDelegate::OnSessionHang);
session->NotifySessionHang();
}

// Do not StartTimer, we will schedule the timer at the end of the timer handler.
Expand Down
10 changes: 5 additions & 5 deletions src/transport/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class SessionHolder : public IntrusiveListNodeBase<>

Transport::Session * operator->() const { return &mSession.Value().Get(); }

// There is not delegate, nothing to do here
virtual void DispatchSessionEvent(SessionDelegate::Event event) {}
// There is no delegate, nothing to do here
virtual void OnSessionHang() {}

protected:
// Helper for use by the Grab methods.
Expand Down Expand Up @@ -147,7 +147,7 @@ class SessionHolderWithDelegate : public SessionHolder
SessionHolder::ShiftToSession(session);
}

void DispatchSessionEvent(SessionDelegate::Event event) override { (mDelegate.*event)(); }
void OnSessionHang() override { mDelegate.OnSessionHang(); }

private:
SessionDelegate & mDelegate;
Expand Down Expand Up @@ -237,15 +237,15 @@ class Session
void SetTCPConnection(ActiveTCPConnectionState * conn) { mTCPConnection = conn; }
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

void DispatchSessionEvent(SessionDelegate::Event event)
void NotifySessionHang()
{
// Holders might remove themselves when notified.
auto holder = mHolders.begin();
while (holder != mHolders.end())
{
auto cur = holder;
++holder;
cur->DispatchSessionEvent(event);
cur->OnSessionHang();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/transport/SessionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class DLL_EXPORT SessionDelegate
*/
virtual NewSessionHandlingPolicy GetNewSessionHandlingPolicy() { return NewSessionHandlingPolicy::kShiftToNewSession; }

using Event = void (SessionDelegate::*)();

/**
* @brief
* Called when a session is releasing. Callees SHALL NOT make synchronous calls into SessionManager to allocate a new session.
Expand Down

0 comments on commit 1406076

Please sign in to comment.