vendredi 27 février 2015

Does a blocking send() returns immediately?

I thought that calling send() on a blocking socket does not return until all data are sent (until the last chunk of data is sent to the send buffer that is), however the following test showed otherwise:



// buffer = "AAAAAAAA...B" (10 MB)
char *buffer = new char[10485760];
memset(buffer, 0x41, 10485760);
buffer[10485758] = 0x42;
buffer[10485759] = '\0';

// Send buffer
send(s, buffer, 10485760, 0) ;

printf("send() has returned");


So basically I connected to Netcat and sent buffer, and even after send() has returned, AAAAAAAAAAAAAA... was still being displayed to the console on the other end. You can close the sender at any moment and the sending would stop (so it is not that buffer has already arrived to the other end but it takes a long time to display it to the console).


This can only make sense if the send buffer is 10+ MB.


Aucun commentaire:

Enregistrer un commentaire