From eaa62db26f164b660624ab6ec88e0d15dfefcbc4 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Tue, 4 Oct 2022 08:39:14 +0200 Subject: [PATCH] application: Fix setting connect callback for OnOffApplication Thanks to Sharan Naribole for spotting this issue --- src/applications/model/onoff-application.cc | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/applications/model/onoff-application.cc b/src/applications/model/onoff-application.cc index 01a68a131..5900f8eab 100644 --- a/src/applications/model/onoff-application.cc +++ b/src/applications/model/onoff-application.cc @@ -200,22 +200,27 @@ void OnOffApplication::StartApplication () // Called at time specified by Start NS_FATAL_ERROR ("Failed to bind socket"); } - m_socket->Connect (m_peer); - m_socket->SetAllowBroadcast (true); - m_socket->ShutdownRecv (); - m_socket->SetConnectCallback ( MakeCallback (&OnOffApplication::ConnectionSucceeded, this), MakeCallback (&OnOffApplication::ConnectionFailed, this)); + + m_socket->Connect (m_peer); + m_socket->SetAllowBroadcast (true); + m_socket->ShutdownRecv (); } m_cbrRateFailSafe = m_cbrRate; - // Insure no pending event + // Ensure no pending event CancelEvents (); - // If we are not yet connected, there is nothing to do here - // The ConnectionComplete upcall will start timers at that time - //if (!m_connected) return; - ScheduleStartEvent (); + + // If we are not yet connected, there is nothing to do here, + // the ConnectionComplete upcall will start timers at that time. + // If we are already connected, CancelEvents did remove the events, + // so we have to start them again. + if (m_connected) + { + ScheduleStartEvent (); + } } void OnOffApplication::StopApplication () // Called at time specified by Stop @@ -387,6 +392,8 @@ void OnOffApplication::SendPacket () void OnOffApplication::ConnectionSucceeded (Ptr socket) { NS_LOG_FUNCTION (this << socket); + + ScheduleStartEvent (); m_connected = true; }