unix: explain SO_REUSEADDR and SO_REUSEPORT

This commit is contained in:
Ben Noordhuis 2012-01-31 16:50:56 +01:00
parent cd16ba5186
commit 45d7bd88c9

View File

@ -340,7 +340,15 @@ static int uv__bind(uv_udp_t* handle,
goto out; goto out;
} }
#ifdef SO_REUSEPORT /* Apple's version of SO_REUSEADDR... */ /* On the BSDs, SO_REUSEADDR lets you reuse an address that's in the TIME_WAIT
* state (i.e. was until recently tied to a socket) while SO_REUSEPORT lets
* multiple processes bind to the same address. Yes, it's something of a
* misnomer but then again, SO_REUSEADDR was already taken.
*
* None of the above applies to Linux: SO_REUSEADDR implies SO_REUSEPORT on
* Linux and hence it does not have SO_REUSEPORT at all.
*/
#ifdef SO_REUSEPORT
yes = 1; yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) { if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno); uv__set_sys_error(handle->loop, errno);