mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-19 15:25:39 +00:00
(svn r15976) -Codechange: make it a bit more clear for what (type of) address binding fails
This commit is contained in:
parent
1eb4aa971e
commit
20e82c46d3
@ -245,46 +245,46 @@ SOCKET NetworkAddress::Connect()
|
|||||||
*/
|
*/
|
||||||
static SOCKET ListenLoopProc(addrinfo *runp)
|
static SOCKET ListenLoopProc(addrinfo *runp)
|
||||||
{
|
{
|
||||||
|
const char *type = runp->ai_socktype == SOCK_STREAM ? "tcp" : "udp";
|
||||||
|
const char *address = NetworkAddress(runp->ai_addr, runp->ai_addrlen).GetAddressAsString();
|
||||||
|
|
||||||
SOCKET sock = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol);
|
SOCKET sock = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol);
|
||||||
if (sock == INVALID_SOCKET) {
|
if (sock == INVALID_SOCKET) {
|
||||||
DEBUG(net, 1, "Could not create socket: %s", strerror(errno));
|
DEBUG(net, 1, "[%s] Could not create socket on port %s: %s", type, address, strerror(errno));
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runp->ai_socktype == SOCK_STREAM && !SetNoDelay(sock)) {
|
if (runp->ai_socktype == SOCK_STREAM && !SetNoDelay(sock)) {
|
||||||
DEBUG(net, 1, "Setting TCP_NODELAY failed");
|
DEBUG(net, 1, "[%s] Setting TCP_NODELAY failed for port %s", type, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
int on = 1;
|
int on = 1;
|
||||||
/* The (const char*) cast is needed for windows!! */
|
/* The (const char*) cast is needed for windows!! */
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) {
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) {
|
||||||
DEBUG(net, 1, "Could not set reusable sockets: %s", strerror(errno));
|
DEBUG(net, 1, "[%s] Could not set reusable sockets for port %s: %s", type, address, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runp->ai_family == AF_INET6 &&
|
if (runp->ai_family == AF_INET6 &&
|
||||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) == -1) {
|
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) == -1) {
|
||||||
DEBUG(net, 1, "Could not disable IPv4 over IPv6: %s", strerror(errno));
|
DEBUG(net, 1, "[%s] Could not disable IPv4 over IPv6 on port %s: %s", type, address, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(sock, runp->ai_addr, runp->ai_addrlen) != 0) {
|
if (bind(sock, runp->ai_addr, runp->ai_addrlen) != 0) {
|
||||||
DEBUG(net, 1, "Could not bind: %s", strerror(errno));
|
DEBUG(net, 1, "[%s] Could not bind on port %s: %s", type, address, strerror(errno));
|
||||||
closesocket(sock);
|
closesocket(sock);
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runp->ai_socktype != SOCK_DGRAM && listen(sock, 1) != 0) {
|
if (runp->ai_socktype != SOCK_DGRAM && listen(sock, 1) != 0) {
|
||||||
DEBUG(net, 1, "Could not listen: %s", strerror(errno));
|
DEBUG(net, 1, "[%s] Could not listen at port %s: %s", type, address, strerror(errno));
|
||||||
closesocket(sock);
|
closesocket(sock);
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connection succeeded */
|
/* Connection succeeded */
|
||||||
if (!SetNonBlocking(sock)) DEBUG(net, 0, "Setting non-blocking mode failed");
|
if (!SetNonBlocking(sock)) DEBUG(net, 0, "[%s] Setting non-blocking mode failed for port %s", type, address);
|
||||||
|
|
||||||
DEBUG(net, 1, "[%s] Listening on port %s",
|
|
||||||
runp->ai_socktype == SOCK_STREAM ? "tcp" : "udp",
|
|
||||||
NetworkAddress(runp->ai_addr, runp->ai_addrlen).GetAddressAsString());
|
|
||||||
|
|
||||||
|
DEBUG(net, 1, "[%s] Listening on port %s", type, address);
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user