diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index 1b4e14bad..a05b5e075 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -88,11 +88,17 @@ void PacketSink::StartApplication() // Called at time specified by Start m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this)); m_socket->SetAcceptCallback ( MakeNullCallback, const Address &> (), - MakeNullCallback, const Address&> ()); + MakeCallback(&PacketSink::HandleAccept, this)); } void PacketSink::StopApplication() // Called at time specified by Stop { + while(!m_socketList.empty()) //these are accepted sockets, close them + { + Ptr acceptedSocket = m_socketList.front(); + m_socketList.pop_front(); + acceptedSocket->Close(); + } if (m_socket) { m_socket->Close (); @@ -117,4 +123,10 @@ void PacketSink::HandleRead (Ptr socket) } } +void PacketSink::HandleAccept (Ptr s, const Address& from) +{ + s->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this)); + m_socketList.push_back (s); +} + } // Namespace ns3 diff --git a/src/applications/packet-sink/packet-sink.h b/src/applications/packet-sink/packet-sink.h index 440af90cd..f8a9a3c1a 100644 --- a/src/applications/packet-sink/packet-sink.h +++ b/src/applications/packet-sink/packet-sink.h @@ -81,8 +81,13 @@ private: virtual void StopApplication (void); // Called at time specified by Stop void HandleRead (Ptr socket); + void HandleAccept (Ptr, const Address& from); + + // In the case of TCP, each socket accept returns a new socket, so the + // listening socket is stored seperately from the accepted sockets + Ptr m_socket; // Listening socket + std::list > m_socketList; //the accepted sockets - Ptr m_socket; // Associated socket Address m_local; // Local address to bind to TypeId m_tid; // Protocol TypeId TracedCallback, const Address &> m_rxTrace; diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index fc0cf1b8b..cb970df79 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -86,7 +86,7 @@ TcpSocketImpl::GetTypeId () } TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) - : TcpSocket(sock), //copy the base class callbacks + : TcpSocket(sock), //copy object::m_tid, copy socket::callbacks m_skipRetxResched (sock.m_skipRetxResched), m_dupAckCount (sock.m_dupAckCount), m_delAckCount (0), @@ -140,6 +140,9 @@ TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) { m_rtt = sock.m_rtt->Copy(); } + //null out the socket base class recvcallback, + //make user of the socket register this explicitly + SetRecvCallback (MakeNullCallback > () ); //can't "copy" the endpoint just yes, must do this when we know the peer info //too; this is in SYN_ACK_TX }