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.
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);
}