Is there a way to force windows to produce short reads/writes on socket calls?

200 views Asked by At

this is for debugging purposes.
To test that short send/short recv handling part of the code is working...
Is there a way to force Windows to produce short send/rcvs even for small number of bytes to be read/written from/to socket?
I prefer to do this per process, but if this cant be done per process Im ready to test how Firefox/ Outlook code handles this also. :)

Ofc I know I can manually add the huge msg to force this, but Im working on huge old code base that has layers of stuff so even adding a simple huge msg that is filled with random bytes is nontrivial. :)

2

There are 2 answers

1
nouney On

You can change the size of the internal buffers used by recv() and send() by using setsockopt() with the flag SO_RCVBUF for the recv() buffer and with the flag SO_SNDBUF for the send() one.

You can find an example here.

EDIT : You may want to disable the Nagle's algorithm. In this case, take a look at the mark's anwser.

EDIT2 : Like alk said in comment, it is important to change the buffers size before any call toaccept() or connect().

0
mark On

If you're controlling the send-side as well, you could disable Nagle's algorithm and send whatever sizes you wanted (without write accumulation)...

int flag = 1;
setsockopt( handle, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int) );