src/internet/model/tcp-socket-base.cc
changeset 7747 53a26ce38807
parent 7717 cfa1741013dd
child 7790 47d6d575412c
--- a/src/internet/model/tcp-socket-base.cc	Fri Feb 24 11:39:28 2012 +0000
+++ b/src/internet/model/tcp-socket-base.cc	Sun Feb 26 19:51:19 2012 +0100
@@ -635,7 +635,7 @@
   if (m_endPoint6 != 0)
     {
       m_endPoint6->SetRxCallback (MakeCallback (&TcpSocketBase::ForwardUp6, Ptr<TcpSocketBase> (this)));
-      m_endPoint6->SetDestroyCallback (MakeCallback (&TcpSocketBase::Destroy, Ptr<TcpSocketBase> (this)));
+      m_endPoint6->SetDestroyCallback (MakeCallback (&TcpSocketBase::Destroy6, Ptr<TcpSocketBase> (this)));
     }
 
   return 0;
@@ -1422,8 +1422,27 @@
 TcpSocketBase::Destroy (void)
 {
   NS_LOG_FUNCTION (this);
-  m_node = 0;
   m_endPoint = 0;
+  if (m_tcp != 0)
+    {
+      std::vector<Ptr<TcpSocketBase> >::iterator it
+        = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this);
+      if (it != m_tcp->m_sockets.end ())
+        {
+          m_tcp->m_sockets.erase (it);
+        }
+    }
+  NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " <<
+                (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
+  CancelAllTimers ();
+}
+
+/** Kill this socket. This is a callback function configured to m_endpoint in
+   SetupCallback(), invoked when the endpoint is destroyed. */
+void
+TcpSocketBase::Destroy6 (void)
+{
+  NS_LOG_FUNCTION (this);
   m_endPoint6 = 0;
   if (m_tcp != 0)
     {
@@ -1433,7 +1452,6 @@
         {
           m_tcp->m_sockets.erase (it);
         }
-      m_tcp = 0;
     }
   NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " <<
                 (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());