strange setsockopt usage

Hey there,

I found another strange thing in a code I have to take over.

Guys used strange looking socket option set:


SOCKET connectionSocket;

......................
.... some more code...
......................

long size = 2048;
setsockopt(connectionSocket, SOL_SOCKET, TCP_NODELAY, (char)* size, sizeof(size));


They do not check for return value. I have not checked that yet but from MSDN docs it looks like it should return error code (such as WSAEINVAL or WSAENOPROTOOPT) because you can't have TCP_NODELAY option for SOL_SOCKET level (and vice versa). They could have TCP_NODELAY with IPPROTO_TCP not with SOL_SOCKET level.

It's still hard for me to say whether they wanted to turn Nagle's algorithm off (in such case 'size' parameter looks like having no sense at all) or something at SOL_SOCKET level.

Any hints?

2048 value is basically binary 1 at 12th position (0000100000000000) so maybe that was supossed to be some flag in a status word.

Thanks,
Szymon
kbw:
I found many sites (including MSDN) with similar examples.
So it looks like they really did it in the wrong way.

How about default settings for WinNt and Win2k3 Server - is Nagle's algorithm switched on by default?

Thanks,
Szymon
You're correct. The code should be using IPPROTO_TCP.
Topic archived. No new replies allowed.