我想知道Linux2.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.)使用上面的选项,我想我可以将两个不同的套接字绑定到相同的IPADRESS和端口号
发布于 2013-07-08 16:14:47
此选项是在内核3.9中完成的,请参阅此git提交
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c617f398edd4db2b8567a28e899a88f8f574798d
发布于 2010-07-16 12:49:34
来自/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 */嗯。看起来它是未定义的或处于折旧的最后阶段。
下面是a post on KernelTrap所说的:
Linux上的
、SO_REUSEADDR提供了SO_REUSEPORT在BSD上提供的大部分功能。
在任何情况下,创建多个TCP侦听器都是没有意义的。
多个线程可以同时在同一个侦听器上接受()。
--
Rémi Denis-Courmont
http://www.remlab.net/
发布于 2012-10-17 17:46:16
试试这个:
#ifdefined (SO_REUSEPORT)
... set this option
#endif有些平台(比如OS/X)如果你要绑定多个UDP监听器到一个端口,就需要设置这个参数。
https://stackoverflow.com/questions/3261965
复制相似问题