+static void send_callback(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace){
+ SgFlow* flow = getFlowFromSocket(sock);
+
+ if (flow->remaining_ == 0) // all data was already buffered (and socket was already closed)
+ return;
+
+ uint8_t *data = (uint8_t*)malloc(sizeof(uint8_t)*txSpace);
+
+ while (flow->bufferedBytes_ < flow->totalBytes_ && sock->GetTxAvailable () > 0) {
+
+ uint32_t toWrite = std::min ({flow->remaining_, txSpace, sock->GetTxAvailable ()});
+ int amountSent = sock->Send (data, toWrite, 0);
+
+ if(amountSent < 0)
+ return;
+ flow->bufferedBytes_ += amountSent;
+ flow->remaining_ -= amountSent;
+
+ XBT_DEBUG("send_cb of F[%p, %p, %d] (%d/%d) %d buffered", flow, flow->action_, flow->totalBytes_,
+ flow->remaining_, flow->totalBytes_, amountSent);
+ }
+ free(data);
+
+ if ((flow->bufferedBytes_) >= flow->totalBytes_)
+ sock->Close();