Commit acd929c1 authored by Mike Hibler's avatar Mike Hibler
Browse files

For dynamic socket buffer sizing, don't trust the return value of setsockopt

In at least the Linux 3.2 kernel on Ubuntu 12, setsockopt to set the socket
buffer size does not return an error if you try to set a value higher than
the kernel max. So we do an immediately following getsockopt to verify.

This will prevent the server from over-driving the send socket (leading to
re-requests of blocks from clients) for really high bandwidth values (i.e.,
with large burst sizes).
parent 58c871e1
......@@ -99,6 +99,23 @@ GetSockbufSize(void)
i = SOCKBUFSIZE;
sbsize = i;
}
else {
int i = 0;
unsigned int ilen = sizeof(i);
if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF,
&i, &ilen) < 0)
pfatal("Could not read sockbuf size");
#ifdef linux
/* In Linux, getsockopt returns 2 * actual value */
if (i == 2 * sbsize)
i = sbsize;
#endif
if (i != sbsize) {
warning("Actual socket buffer size is %d"
" (instead of %d)", i, sbsize);
sbsize = i;
}
}
close(sock);
#else
sbsize = SOCKBUFSIZE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment