Make PacketSink multitasking for TCP (closes bug 244)
authorRaj Bhattacharjea <raj.b@gatech.edu>
Wed, 23 Jul 2008 16:09:17 -0400
changeset 3475 8523b98f949c
parent 3474 dac9146297c8
child 3476 b834a9204124
Make PacketSink multitasking for TCP (closes bug 244)
src/applications/packet-sink/packet-sink.cc
src/applications/packet-sink/packet-sink.h
src/internet-stack/tcp-socket-impl.cc
--- a/src/applications/packet-sink/packet-sink.cc	Wed Jul 23 11:48:17 2008 +0100
+++ b/src/applications/packet-sink/packet-sink.cc	Wed Jul 23 16:09:17 2008 -0400
@@ -88,11 +88,17 @@
   m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));
   m_socket->SetAcceptCallback (
             MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
-            MakeNullCallback<void, Ptr<Socket>, 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<Socket> acceptedSocket = m_socketList.front();
+    m_socketList.pop_front();
+    acceptedSocket->Close();
+  }
   if (m_socket) 
     {
       m_socket->Close ();
@@ -117,4 +123,10 @@
     }
 }
 
+void PacketSink::HandleAccept (Ptr<Socket> s, const Address& from)
+{
+  s->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));
+  m_socketList.push_back (s);
+}
+
 } // Namespace ns3
--- a/src/applications/packet-sink/packet-sink.h	Wed Jul 23 11:48:17 2008 +0100
+++ b/src/applications/packet-sink/packet-sink.h	Wed Jul 23 16:09:17 2008 -0400
@@ -81,8 +81,13 @@
   virtual void StopApplication (void);     // Called at time specified by Stop
 
   void HandleRead (Ptr<Socket> socket);
+  void HandleAccept (Ptr<Socket>, const Address& from);
 
-  Ptr<Socket>     m_socket;       // Associated socket
+  // In the case of TCP, each socket accept returns a new socket, so the 
+  // listening socket is stored seperately from the accepted sockets
+  Ptr<Socket>     m_socket;       // Listening socket
+  std::list<Ptr<Socket> > m_socketList; //the accepted sockets
+
   Address         m_local;        // Local address to bind to
   TypeId          m_tid;          // Protocol TypeId
   TracedCallback<Ptr<const Packet>, const Address &> m_rxTrace;
--- a/src/internet-stack/tcp-socket-impl.cc	Wed Jul 23 11:48:17 2008 +0100
+++ b/src/internet-stack/tcp-socket-impl.cc	Wed Jul 23 16:09:17 2008 -0400
@@ -86,7 +86,7 @@
 }
 
 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 @@
     {
       m_rtt = sock.m_rtt->Copy();
     }
+  //null out the socket base class recvcallback,
+  //make user of the socket register this explicitly
+  SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > () );
   //can't "copy" the endpoint just yes, must do this when we know the peer info
   //too; this is in SYN_ACK_TX
 }