Problem with SetSendCallback when NSC tcp is used

12 views
Skip to first unread message

Sangwook Bae

unread,
Sep 4, 2016, 8:58:52 AM9/4/16
to ns-3-users
Hello,

I have trouble with SetSendCallback function when I uses  NSC TCP socket.
What I am trying to do is implementing the TCP application, which works similar to bulksender. 
Therefore, after setting receiving / sending window size, I called socket->Send() function whenever the socket->GetTxAvailable() shows larger than zero.
However,  even I register the call back function through the socket->SetSendCallback, It isn't called back again.

Is that a known bug? or Is there any option that I should take care?

The followings are the used code that give me the problem.

void 
StartFlow (Ptr<Socket> localSocket, Ipv4Address servAddress, uint16_t servPort)
{
  NS_LOG_LOGIC ("Starting flow at time " <<  Simulator::Now ().GetSeconds ());
  localSocket->Connect (InetSocketAddress (servAddress, servPort));

  localSocket->SetSendCallback (MakeCallback (&WriteUntilBufferFull));
  WriteUntilBufferFull (localSocket, localSocket->GetTxAvailable ()); 
}

void 
WriteUntilBufferFull (Ptr<Socket> localSocket, uint32_t txSpace)
{
  while (currentTxBytes < totalTxBytes && localSocket->GetTxAvailable () > 0) {

    uint32_t left = totalTxBytes - currentTxBytes;
    uint32_t toWrite = writeSize;
    uint32_t dataOffset = 0;
    toWrite = std::min (toWrite, left);
    toWrite = std::min (toWrite, localSocket->GetTxAvailable ());

    int amountSent = localSocket->Send (&data[dataOffset], toWrite, 0);
    if (amountSent < 0) {
      NS_LOG_INFO(" we will be called again when new tx space becomes available");
      return;
    }
    currentTxBytes += amountSent;
    NS_LOG_INFO ("curtime: " << Simulator::Now ().GetSeconds () << " currentTXbytes: " << currentTxBytes << " / totalBytes: " << totalTxBytes);
  }
}
Reply all
Reply to author
Forward
0 new messages