-
- uint32_t packetSize = 1024;
- uint32_t toWrite = min (mysocket->remaining, packetSize);
- uint8_t *data = (uint8_t*)malloc(sizeof(uint8_t)*toWrite);
- int amountSent = localSocket->Send (&data[0], toWrite, 0);
- free (data);
- if (amountSent > 0){
- mysocket->bufferedBytes += amountSent;
- mysocket->remaining -= amountSent;
+ while (mysocket->sentBytes < mysocket->totalBytes
+ && localSocket->GetTxAvailable () > 0)
+ {
+ uint32_t toWrite = min ((mysocket->remaining), txSpace);
+ toWrite = min (toWrite, localSocket->GetTxAvailable ());
+ int amountSent = localSocket->Send (&data[0], toWrite, 0);
+
+ if(amountSent < 0)
+ return;
+ (mysocket->sentBytes) += 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);
+
+ }
+ if ((mysocket->sentBytes) >= mysocket->totalBytes){
+ localSocket->Close();