I used this option( int resize=16384; setsockopt((fd, SOL_SOCKET, SO_RCVBUF, &resize, sizeof(int)) ) to try to change my rcv socket buffer size. The option succeeded but the buffer size stayed at 4096. Can I actually change the buffer size with this option or is it hard coded into the kernel
You should always check the return status from a system call.
int status = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &resize, sizeof(int));
if (status < 0)
perror("setsockopt");
will show you any error in the setsockopt call. Also why the double parentheses in the setsockopt call? They are not harmless, as you will discover if you compile with gcc -Wall. The parentheses around the arguments turn what you think are the arguments into a single value. See comma operator in C.
Anyway I think that is your error, but you should check afterwards that the change has gone through with getsockopt as the kernel is not obliged to honour it.
The extra set of parentheses are in the post message only. No errors accured while performing the setsockopt function. But the getsockopt revealed that the value did not change(ignored).
Here is a post i discovered while Researching the cause of the doubling affect:
Thomas Graf 2005-12-09 09:14:19 EST
This behaviour is intended, Linux reserves half of te socket buffer for
metadata. BSD doesn’t do that, therefore in order to have compatibility
with traditional BSD the value gets doubled.
The value returned by getsockopt is the actual value being in use. Due to
maximum and minimum values for buffer values the doubling cannot be undone.
Please read up on various mailing list archives on this topic and why it
is solved the way it is.
That’s good. Next time use the code tag to surround the code to present the code exactly as it appears so there’s no confusion about what you actually compiled.