Linux上的SO_REUSEPORT

cod*_*eak 15 sockets linux udp

我想知道是否在LINUX 2.6中启用了SO_REUSEPORT选项?

如果我尝试使用它并编译我的代码,我会得到以下错误

01.c:72: error: `SO_REUSEPORT' undeclared (first use in this function)
01.c:72: error: (Each undeclared identifier is reported only once
01.c:72: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)

使用上面的选项,我想我可以将两个不同的套接字绑定到相同的IPADRESS和PORT NUMBER

amp*_*ine 5

来自/usr/include/asm-generic/socket.h:

/* For setsockopt(2) */
#define SOL_SOCKET      1

#define SO_DEBUG        1
#define SO_REUSEADDR    2
#define SO_TYPE         3
#define SO_ERROR        4
#define SO_DONTROUTE    5
#define SO_BROADCAST    6
#define SO_SNDBUF       7
#define SO_RCVBUF       8
#define SO_SNDBUFFORCE  32
#define SO_RCVBUFFORCE  33
#define SO_KEEPALIVE    9
#define SO_OOBINLINE    10
#define SO_NO_CHECK     11
#define SO_PRIORITY     12
#define SO_LINGER       13
#define SO_BSDCOMPAT    14
/* To add :#define SO_REUSEPORT 15 */
Run Code Online (Sandbox Code Playgroud)

嗯.看起来它是未定义的或在折旧的最后阶段.

这是关于KernelTrap的帖子所说的:

在Linux上,SO_REUSEADDR提供了SO_REUSEPORT在BSD上提供的大部分内容.

无论如何,创建多个TCP侦听器绝对没有意义.
多个线程可以在同一个侦听器上同时接受().
-
RémiDenis-Courmont
http://www.remlab.net/