Refactor OnOff so Start doesn't immediate close the socket (bug 259)
authorRaj Bhattacharjea <raj.b@gatech.edu>
Fri, 15 Aug 2008 12:58:53 -0400
changeset 3535 016c70fa60d8
parent 3534 e170f2c17e03
child 3536 087b1b45b3b5
Refactor OnOff so Start doesn't immediate close the socket (bug 259)
src/applications/onoff/onoff-application.cc
src/applications/onoff/onoff-application.h
--- a/src/applications/onoff/onoff-application.cc	Fri Aug 15 11:25:18 2008 -0400
+++ b/src/applications/onoff/onoff-application.cc	Fri Aug 15 12:58:53 2008 -0400
@@ -135,7 +135,7 @@
       m_socket->Connect (m_peer);
     }
   // Insure no pending event
-  StopApplication();
+  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;
@@ -146,6 +146,14 @@
 {
   NS_LOG_FUNCTION_NOARGS ();
 
+  CancelEvents ();
+  m_socket->Close ();
+}
+
+void OnOffApplication::CancelEvents ()
+{
+  NS_LOG_FUNCTION_NOARGS ();
+
   if (m_sendEvent.IsRunning ())
     { // Cancel the pending send packet event
       // Calculate residual bits since last packet sent
--- a/src/applications/onoff/onoff-application.h	Fri Aug 15 11:25:18 2008 -0400
+++ b/src/applications/onoff/onoff-application.h	Fri Aug 15 12:58:53 2008 -0400
@@ -83,6 +83,9 @@
   virtual void StartApplication (void);    // Called at time specified by Start
   virtual void StopApplication (void);     // Called at time specified by Stop
 
+  //helpers
+  void CancelEvents ();
+
   void Construct (Ptr<Node> n,
                   const Address &remote,
                   std::string tid,