nghttpx: Add error logging for listener socket creation failure
This commit is contained in:
parent
bbbddedb8f
commit
4894e24dc8
30
src/shrpx.cc
30
src/shrpx.cc
|
@ -311,11 +311,15 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
|
||||||
fd =
|
fd =
|
||||||
socket(rp->ai_family, rp->ai_socktype | SOCK_NONBLOCK, rp->ai_protocol);
|
socket(rp->ai_family, rp->ai_socktype | SOCK_NONBLOCK, rp->ai_protocol);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
auto error = errno;
|
||||||
|
LOG(WARN) << "socket() syscall failed, error=" << error;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#else // !SOCK_NONBLOCK
|
#else // !SOCK_NONBLOCK
|
||||||
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
auto error = errno;
|
||||||
|
LOG(WARN) << "socket() syscall failed, error=" << error;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
util::make_socket_nonblocking(fd);
|
util::make_socket_nonblocking(fd);
|
||||||
|
@ -323,6 +327,10 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
|
||||||
int val = 1;
|
int val = 1;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val,
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val,
|
||||||
static_cast<socklen_t>(sizeof(val))) == -1) {
|
static_cast<socklen_t>(sizeof(val))) == -1) {
|
||||||
|
auto error = errno;
|
||||||
|
LOG(WARN)
|
||||||
|
<< "Failed to set SO_REUSEADDR option to listener socket, error="
|
||||||
|
<< error;
|
||||||
close(fd);
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -331,6 +339,10 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
|
||||||
if (family == AF_INET6) {
|
if (family == AF_INET6) {
|
||||||
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val,
|
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val,
|
||||||
static_cast<socklen_t>(sizeof(val))) == -1) {
|
static_cast<socklen_t>(sizeof(val))) == -1) {
|
||||||
|
auto error = errno;
|
||||||
|
LOG(WARN)
|
||||||
|
<< "Failed to set IPV6_V6ONLY option to listener socket, error="
|
||||||
|
<< error;
|
||||||
close(fd);
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -345,11 +357,21 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
|
||||||
}
|
}
|
||||||
#endif // TCP_DEFER_ACCEPT
|
#endif // TCP_DEFER_ACCEPT
|
||||||
|
|
||||||
if (bind(fd, rp->ai_addr, rp->ai_addrlen) == 0 &&
|
if (bind(fd, rp->ai_addr, rp->ai_addrlen) == -1) {
|
||||||
listen(fd, get_config()->backlog) == 0) {
|
auto error = errno;
|
||||||
break;
|
LOG(WARN) << "bind() syscall failed, error=" << error;
|
||||||
}
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listen(fd, get_config()->backlog) == -1) {
|
||||||
|
auto error = errno;
|
||||||
|
LOG(WARN) << "listen() syscall failed, error=" << error;
|
||||||
|
close(fd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rp) {
|
if (!rp) {
|
||||||
|
|
Loading…
Reference in New Issue