Mercurial > dovecot > core-2.2
diff src/lib/net.c @ 16822:6a814345f16c
lib: Added net_listen_full() with a flag to set SO_REUSEPORT on the socket if available.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 23 Sep 2013 04:06:08 +0300 |
parents | 07cc79e0041d |
children | 93cf0434dda4 |
line wrap: on
line diff
--- a/src/lib/net.c Sun Sep 22 07:43:31 2013 +0300 +++ b/src/lib/net.c Mon Sep 23 04:06:08 2013 +0300 @@ -384,6 +384,14 @@ int net_listen(const struct ip_addr *my_ip, unsigned int *port, int backlog) { + enum net_listen_flags flags = 0; + + return net_listen_full(my_ip, port, &flags, backlog); +} + +int net_listen_full(const struct ip_addr *my_ip, unsigned int *port, + enum net_listen_flags *flags, int backlog) +{ union sockaddr_union so; int ret, fd, opt = 1; socklen_t len; @@ -413,6 +421,14 @@ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)); + if ((*flags & NET_LISTEN_FLAG_REUSEPORT) != 0) { +#ifdef SO_REUSEPORT + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, + &opt, sizeof(opt)) < 0) +#endif + *flags &= ~NET_LISTEN_FLAG_REUSEPORT; + } + /* If using IPv6, bind only to IPv6 if possible. This avoids ambiguities with IPv4-mapped IPv6 addresses. */ #ifdef IPV6_V6ONLY