TCP socket options

Some collected useful tips about various TCP socket options, e.g. setsockotp() and getsockopt().

TCP_DEFER_ACCEPT

This is availble on Linux, and is a poor mans "accept filtering" (as FreeBSD implements it). Apache HTTPD v2.2.x sets this to "1" (which I assume was a mistake), which translates to 3s before timing out. HTTPD 2.3.x increases this to 30s, which according to the table I found for Linux v2.6.32 (and later) translates to 45s. Internally, the kernel translates the timeout to a number of retransmits to perform before the timeout, which means a call to setsockopt() followed by getsockopt() won't necessarily show the same value. I found the following conversions, from the requested timeout (in seconds) to effective timeout as used internally):

1-3	-> 3
4-9	-> 9
10-21	-> 21
22-45	-> 45
46-93	-> 93
94-189	-> 189
190-309	-> 309
310-429	-> 429

On older kernels, I see the following conversion (due to different rounding I think):

1-3	-> 3
4-6	-> 6
7-12	-> 12
13-24	-> 24
25-48	-> 48
49-96	-> 96
97-192	-> 192
193-384	-> 384

The code for this is available here.

Hacking: