- if (mysocket->remaining == 0){
- //everything was buffered to send, tell NS3 to close the socket
- localSocket->Close();
- }
- return;
+ while (mysocket->bufferedBytes < mysocket->totalBytes
+ && localSocket->GetTxAvailable () > 0)
+ {
+ uint32_t toWrite = min ((mysocket->remaining), txSpace);
+ toWrite = min (toWrite, localSocket->GetTxAvailable ());
+ int amountSent = localSocket->Send (data, toWrite, 0);
+
+ if(amountSent < 0)
+ return;
+ (mysocket->bufferedBytes) += amountSent;
+ (mysocket->remaining) -= amountSent;
+ XBT_DEBUG("send_cb of F[%p, %p, %d] (%d/%d) %d buffered", mysocket, mysocket->action, mysocket->totalBytes, mysocket->remaining, mysocket->totalBytes, amountSent);
+
+ }
+
+ free(data);
+
+ if ((mysocket->bufferedBytes) >= mysocket->totalBytes){
+ localSocket->Close();
+ }