Merge pull request #75 from vibe-d/fix_connect_tcp_cancellation
Fix cancellation of connectTCP in case of early errors.
This commit is contained in:
commit
267e3c352d
|
@ -39,6 +39,7 @@ NetworkAddress resolveHost(string host, ushort address_family, bool use_dns = tr
|
||||||
else import core.sys.posix.netinet.in_ : sockaddr_in, sockaddr_in6;
|
else import core.sys.posix.netinet.in_ : sockaddr_in, sockaddr_in6;
|
||||||
|
|
||||||
enforce(host.length > 0, "Host name must not be empty.");
|
enforce(host.length > 0, "Host name must not be empty.");
|
||||||
|
// FIXME: this check needs to be more specific to not disallow valid DNS names
|
||||||
if (host[0] == ':' || host[0] >= '0' && host[0] <= '9') {
|
if (host[0] == ':' || host[0] >= '0' && host[0] <= '9') {
|
||||||
auto addr = parseAddress(host);
|
auto addr = parseAddress(host);
|
||||||
enforce(address_family == AddressFamily.UNSPEC || addr.addressFamily == address_family);
|
enforce(address_family == AddressFamily.UNSPEC || addr.addressFamily == address_family);
|
||||||
|
@ -135,6 +136,7 @@ TCPListener listenTCP(ushort port, void delegate(TCPConnection) connection_callb
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logError("Handling of connection failed: %s", e.msg);
|
logError("Handling of connection failed: %s", e.msg);
|
||||||
conn.close();
|
conn.close();
|
||||||
|
logDebug("Full error: %s", e);
|
||||||
}
|
}
|
||||||
}, address, options);
|
}, address, options);
|
||||||
}
|
}
|
||||||
|
@ -204,6 +206,7 @@ TCPConnection connectTCP(NetworkAddress addr, NetworkAddress bind_address = anyA
|
||||||
cb => eventDriver.sockets.connectStream(uaddr, baddr, cb),
|
cb => eventDriver.sockets.connectStream(uaddr, baddr, cb),
|
||||||
(cb, sock_fd) {
|
(cb, sock_fd) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
if (sock_fd != SocketFD.invalid)
|
||||||
eventDriver.sockets.cancelConnectStream(sock_fd);
|
eventDriver.sockets.cancelConnectStream(sock_fd);
|
||||||
},
|
},
|
||||||
(fd, st) { sock = fd; status = st; }
|
(fd, st) { sock = fd; status = st; }
|
||||||
|
|
Loading…
Reference in a new issue