|
@@ -247,9 +247,9 @@ SOCKET NetworkAddress::Resolve(int famil
|
|
|
auto end = std::chrono::steady_clock::now();
|
|
|
std::chrono::seconds duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
|
|
if (!_resolve_timeout_error_message_shown && duration >= std::chrono::seconds(5)) {
|
|
|
DEBUG(net, 0, "getaddrinfo for hostname \"%s\", port %s, address family %s and socket type %s took %i seconds",
|
|
|
this->hostname.c_str(), port_name, AddressFamilyAsString(family), SocketTypeAsString(socktype), (int)duration.count());
|
|
|
DEBUG(net, 0, " this is likely an issue in the DNS name resolver's configuration causing it to time out");
|
|
|
Debug(net, 0, "getaddrinfo for hostname \"{}\", port {}, address family {} and socket type {} took {} seconds",
|
|
|
this->hostname, port_name, AddressFamilyAsString(family), SocketTypeAsString(socktype), duration.count());
|
|
|
Debug(net, 0, " this is likely an issue in the DNS name resolver's configuration causing it to time out");
|
|
|
_resolve_timeout_error_message_shown = true;
|
|
|
}
|
|
|
|
|
@@ -258,8 +258,8 @@ SOCKET NetworkAddress::Resolve(int famil
|
|
|
|
|
|
if (e != 0) {
|
|
|
if (func != ResolveLoopProc) {
|
|
|
DEBUG(net, 0, "getaddrinfo for hostname \"%s\", port %s, address family %s and socket type %s failed: %s",
|
|
|
this->hostname.c_str(), port_name, AddressFamilyAsString(family), SocketTypeAsString(socktype), FS2OTTD(gai_strerror(e)).c_str());
|
|
|
Debug(net, 0, "getaddrinfo for hostname \"{}\", port {}, address family {} and socket type {} failed: {}",
|
|
|
this->hostname, port_name, AddressFamilyAsString(family), SocketTypeAsString(socktype), FS2OTTD(gai_strerror(e)));
|
|
|
}
|
|
|
return INVALID_SOCKET;
|
|
|
}
|
|
@@ -317,35 +317,35 @@ static SOCKET ListenLoopProc(addrinfo *r
|
|
|
if (sock == INVALID_SOCKET) {
|
|
|
const char *type = NetworkAddress::SocketTypeAsString(runp->ai_socktype);
|
|
|
const char *family = NetworkAddress::AddressFamilyAsString(runp->ai_family);
|
|
|
DEBUG(net, 0, "Could not create %s %s socket: %s", type, family, NetworkError::GetLast().AsString());
|
|
|
Debug(net, 0, "Could not create {} {} socket: {}", type, family, NetworkError::GetLast().AsString());
|
|
|
return INVALID_SOCKET;
|
|
|
}
|
|
|
|
|
|
if (runp->ai_socktype == SOCK_STREAM && !SetNoDelay(sock)) {
|
|
|
DEBUG(net, 1, "Setting no-delay mode failed: %s", NetworkError::GetLast().AsString());
|
|
|
Debug(net, 1, "Setting no-delay mode failed: {}", NetworkError::GetLast().AsString());
|
|
|
}
|
|
|
|
|
|
int on = 1;
|
|
|
/* The (const char*) cast is needed for windows!! */
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) {
|
|
|
DEBUG(net, 0, "Setting reuse-address mode failed: %s", NetworkError::GetLast().AsString());
|
|
|
Debug(net, 0, "Setting reuse-address mode failed: {}", NetworkError::GetLast().AsString());
|
|
|
}
|
|
|
|
|
|
#ifndef __OS2__
|
|
|
if (runp->ai_family == AF_INET6 &&
|
|
|
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) == -1) {
|
|
|
DEBUG(net, 3, "Could not disable IPv4 over IPv6: %s", NetworkError::GetLast().AsString());
|
|
|
Debug(net, 3, "Could not disable IPv4 over IPv6: {}", NetworkError::GetLast().AsString());
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
if (bind(sock, runp->ai_addr, (int)runp->ai_addrlen) != 0) {
|
|
|
DEBUG(net, 0, "Could not bind socket on %s: %s", address.c_str(), NetworkError::GetLast().AsString());
|
|
|
Debug(net, 0, "Could not bind socket on {}: {}", address, NetworkError::GetLast().AsString());
|
|
|
closesocket(sock);
|
|
|
return INVALID_SOCKET;
|
|
|
}
|
|
|
|
|
|
if (runp->ai_socktype != SOCK_DGRAM && listen(sock, 1) != 0) {
|
|
|
DEBUG(net, 0, "Could not listen on socket: %s", NetworkError::GetLast().AsString());
|
|
|
Debug(net, 0, "Could not listen on socket: {}", NetworkError::GetLast().AsString());
|
|
|
closesocket(sock);
|
|
|
return INVALID_SOCKET;
|
|
|
}
|
|
@@ -353,10 +353,10 @@ static SOCKET ListenLoopProc(addrinfo *r
|
|
|
/* Connection succeeded */
|
|
|
|
|
|
if (!SetNonBlocking(sock)) {
|
|
|
DEBUG(net, 0, "Setting non-blocking mode failed: %s", NetworkError::GetLast().AsString());
|
|
|
Debug(net, 0, "Setting non-blocking mode failed: {}", NetworkError::GetLast().AsString());
|
|
|
}
|
|
|
|
|
|
DEBUG(net, 3, "Listening on %s", address.c_str());
|
|
|
Debug(net, 3, "Listening on {}", address);
|
|
|
return sock;
|
|
|
}
|
|
|
|