Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
authorRaj Bhattacharjea <raj.b@gatech.edu>
Thu, 11 Dec 2008 16:48:42 -0500
changeset 4014 b6349d9c007e
parent 4011 2fd3041c3c29
child 4015 76848c77cd84
Null forked TCP socket callbacks, and communicate EOF to higher layers (bugs 423 and 365)
src/applications/packet-sink/packet-sink.cc
src/internet-stack/tcp-socket-impl.cc
--- a/src/applications/packet-sink/packet-sink.cc	Wed Dec 10 21:11:05 2008 -0800
+++ b/src/applications/packet-sink/packet-sink.cc	Thu Dec 11 16:48:42 2008 -0500
@@ -119,6 +119,10 @@
   Address from;
   while (packet = socket->RecvFrom (from))
     {
+      if (packet->GetSize() == 0)
+        { //EOF
+	  break;
+        }
       if (InetSocketAddress::IsMatchingType (from))
         {
           InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
--- a/src/internet-stack/tcp-socket-impl.cc	Wed Dec 10 21:11:05 2008 -0800
+++ b/src/internet-stack/tcp-socket-impl.cc	Thu Dec 11 16:48:42 2008 -0500
@@ -145,9 +145,19 @@
     {
       m_rtt = sock.m_rtt->Copy();
     }
-  //null out the socket base class recvcallback,
+  //null out the socket base class callbacks,
   //make user of the socket register this explicitly
-  SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > () );
+  Callback<void, Ptr< Socket > > vPS =
+      MakeNullCallback<void, Ptr<Socket> > ();
+  Callback<void, Ptr<Socket>, const Address &> vPSA =
+      MakeNullCallback<void, Ptr<Socket>, const Address &> ();
+  Callback<void, Ptr<Socket>, uint32_t> vPSUI =
+      MakeNullCallback<void, Ptr<Socket>, uint32_t> ();
+
+  SetConnectCallback (vPS, vPS);
+  SetDataSentCallback (vPSUI);
+  SetSendCallback (vPSUI);
+  SetRecvCallback (vPS);
   //can't "copy" the endpoint just yes, must do this when we know the peer info
   //too; this is in SYN_ACK_TX
 }
@@ -473,6 +483,11 @@
   NS_LOG_FUNCTION_NOARGS ();
   if(m_bufferedData.empty())
     {
+      if(m_state == CLOSE_WAIT) //means EOF
+        {
+          return Create<Packet>();
+        }
+      //else, means nothing to read
       return 0;
     }
   UnAckData_t out; //serves as buffer to return up to the user
@@ -547,7 +562,8 @@
 {
   NS_LOG_FUNCTION (this << maxSize << flags);
   Ptr<Packet> packet = Recv (maxSize, flags);
-  if (packet != 0)
+  //Null packet means no data to read, and an empty packet indicates EOF
+  if (packet != 0 && packet->GetSize() != 0)
     {
       SocketAddressTag tag;
       bool found;