0

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. :)

NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277

2 Answers2

5

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().

nouney
  • 4,363
  • 19
  • 31
  • 1
    I feel it is notable that changing the socket's buffers size shall be applied prior to any call to `connect()` or `accept()` to take effect. – alk Aug 26 '13 at 19:38
3

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) );
mark
  • 5,269
  • 2
  • 21
  • 34