Ignore error setting socket option SO_REUSEADDR

Shouldn't fail.  If it fails, but bind() works, the failure doesn't
matter.  If bind() fails, we can just as well report that failure
instead of setsockopt()'s.
This commit is contained in:
Markus Armbruster 2013-04-07 19:14:57 +02:00
parent 8233c06317
commit 75be45f1e4

View file

@ -81,8 +81,7 @@ tcp_listen(char *host, char *serv, size_t *addrlenp)
if (fd < 0) if (fd < 0)
continue; /* error, try next one */ continue; /* error, try next one */
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
cant_listen(host, serv, strerror(errno));
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == 0) if (bind(fd, ai->ai_addr, ai->ai_addrlen) == 0)
break; /* success */ break; /* success */
@ -127,8 +126,7 @@ tcp_listen(char *host, char *serv, size_t *addrlenp)
} }
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
cant_listen(host, serv, strerror(errno)); cant_listen(host, serv, strerror(errno));
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
cant_listen(host, serv, strerror(errno));
if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
cant_listen(host, serv, strerror(errno)); cant_listen(host, serv, strerror(errno));
if (listen(fd, SOMAXCONN) < 0) if (listen(fd, SOMAXCONN) < 0)