From 9dcfa5bda8c03d0acecd87953ebfc78372bb9755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Tue, 28 Jun 2016 13:02:45 +0200 Subject: [PATCH 07/17] socket.7: document SO_REUSEPORT option --- man-pages/man7/socket.7 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/man-pages/man7/socket.7 b/man-pages/man7/socket.7 index 17bd0c3..94c98b6 100644 --- a/man-pages/man7/socket.7 +++ b/man-pages/man7/socket.7 @@ -649,6 +649,39 @@ with a specific port then it is not possible to bind to this port for any local address. Argument is an integer boolean flag. .TP +.BR SO_REUSEPORT +Permits multiple +.B AF_INET +or +.B AF_INET6 +sockets to be bound to an identical socket address. +This option must be set on each socket (including the first socket) +prior to calling +.BR bind (2) +on the socket. +To prevent port hijacking, +all of the processes binding to the same address must have the same +effective UID. +This option can be employed with both TCP and UDP sockets. + +For TCP sockets, this option allows +.BR accept (2) +load distribution in a multi-threaded server to be improved by +using a distinct listener socket for each thread. +This provides improved load distribution as compared +to traditional techniques such using a single +.BR accept (2)ing +thread that distributes connections, +or having multiple threads that compete to +.BR accept (2) +from the same socket. + +For UDP sockets, +the use of this option can provide better distribution +of incoming datagrams to multiple processes (or threads) as compared +to the traditional technique of having multiple processes +compete to receive datagrams on the same socket. +.TP .B SO_SNDBUF Sets or gets the maximum socket send buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead) -- 2.7.4