From: Navarrop Date: Tue, 13 Sep 2011 13:27:51 +0000 (+0200) Subject: Cleaning the ns3 send callback function. X-Git-Tag: v3_6_2~96^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0f2e41ab1b3e2ce012c6d47747db0f762be90c56?hp=0c62ac293213c4632f158a2cbedc86e321a324d4 Cleaning the ns3 send callback function. --- diff --git a/src/surf/ns3/ns3_simulator.cc b/src/surf/ns3/ns3_simulator.cc index 07abf0cfda..7c62e05cc8 100644 --- a/src/surf/ns3/ns3_simulator.cc +++ b/src/surf/ns3/ns3_simulator.cc @@ -110,28 +110,29 @@ static void receive_callback(Ptr localSocket){ } static void send_callback(Ptr localSocket, uint32_t txSpace){ + uint8_t *data = (uint8_t*)malloc(sizeof(uint8_t)*txSpace); MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket); - if (mysocket->remaining == 0){ - //all data was already buffered (and socket was already closed), just return - return; + //all data was already buffered (and socket was already closed), just return + return; } - - uint32_t toWrite = min (mysocket->remaining, txSpace); - 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(); } - 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->remaining == 0){ - //everything was buffered to send, tell NS3 to close the socket - localSocket->Close(); - } - return; } static void datasent_callback(Ptr localSocket, uint32_t dataSent){