src/internet-stack/tcp-socket-impl.cc
changeset 4621 bb360763b0e2
parent 4603 67a0a49c1db4
child 4623 e5cedb4b33b0
equal deleted inserted replaced
4620:5d448b8564e5 4621:bb360763b0e2
   170   NS_LOG_FUNCTION(this);
   170   NS_LOG_FUNCTION(this);
   171   m_node = 0;
   171   m_node = 0;
   172   if (m_endPoint != 0)
   172   if (m_endPoint != 0)
   173     {
   173     {
   174       NS_ASSERT (m_tcp != 0);
   174       NS_ASSERT (m_tcp != 0);
   175       /**
   175       /*
   176        * Note that this piece of code is a bit tricky:
   176        * Note that this piece of code is seriously convoluted: When we do a 
   177        * when DeAllocate is called, it will call into
   177        * Bind we allocate an Ipv4Endpoint.  Immediately thereafter we always do
   178        * Ipv4EndPointDemux::Deallocate which triggers
   178        * a FinishBind which sets the DestroyCallback of that endpoint to be
   179        * a delete of the associated endPoint which triggers
   179        * TcpSocketImpl::Destroy, below.  When m_tcp->DeAllocate is called, it 
   180        * in turn a call to the method ::Destroy below
   180        * will in turn call into Ipv4EndpointDemux::DeAllocate with the endpoint
   181        * will will zero the m_endPoint field.
   181        * (m_endPoint).  The demux will look up the endpoint and destroy it (the
       
   182        * corollary is that we don't own the object pointed to by m_endpoint, we
       
   183        * just borrowed it).  The destructor for the endpoint will call the 
       
   184        * DestroyCallback which will then invoke TcpSocketImpl::Destroy below. 
       
   185        * Destroy will zero m_node, m_tcp and m_endpoint.  Yes, we zeroed m_node
       
   186        * above and will zero m_tcp below as well; but that's what it does.
   182        */
   187        */
   183       NS_ASSERT (m_endPoint != 0);
   188       NS_ASSERT (m_endPoint != 0);
   184       m_tcp->DeAllocate (m_endPoint);
   189       m_tcp->DeAllocate (m_endPoint);
   185       NS_ASSERT (m_endPoint == 0);
   190       NS_ASSERT (m_endPoint == 0);
   186     }
   191     }
   692               << " event " << e);
   697               << " event " << e);
   693       NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from "
   698       NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from "
   694           << m_state << " event " << e
   699           << m_state << " event " << e
   695           << " set CloseNotif ");
   700           << " set CloseNotif ");
   696     }
   701     }
       
   702 
       
   703   if (m_state == CLOSED && saveState != CLOSED && m_endPoint != 0)
       
   704     {
       
   705       NS_ASSERT (m_tcp != 0);
       
   706       /*
       
   707        * We want to deallocate the endpoint now.  We can't just naively call
       
   708        * Deallocate (see the comment in TcpSocketImpl::~TcpSocketImpl), we 
       
   709        * have to turn off the DestroyCallback to keep it from calling back 
       
   710        * into TcpSocketImpl::Destroy and closing pretty much everything down.
       
   711        * Once we have the callback disconnected, we can DeAllocate the
       
   712        * endpoint which actually deals with destroying the actual endpoint,
       
   713        * and then zero our member varible on general principles.
       
   714        */
       
   715       m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
       
   716       m_tcp->DeAllocate (m_endPoint);
       
   717       m_endPoint = 0;
       
   718     }
       
   719     
   697   return stateAction.action;
   720   return stateAction.action;
   698 }
   721 }
   699 
   722 
   700 void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
   723 void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
   701 {
   724 {