From 02de8341aa689808022f0fe2ed469b9c3d21e0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 14 Mar 2018 20:43:40 +0100 Subject: [PATCH] Call the callback on connectStream socket creation failure. The callback must *always* be called at some point, because the generic async->sync logic in vibe-core otherwise has no way to know whether to expect a callback or not. --- source/eventcore/driver.d | 1 + source/eventcore/drivers/posix/sockets.d | 5 ++++- source/eventcore/drivers/winapi/sockets.d | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index a411bd1..613a90b 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -570,6 +570,7 @@ enum ConnectStatus { refused, timeout, bindFailure, + socketCreateFailure, unknownError } diff --git a/source/eventcore/drivers/posix/sockets.d b/source/eventcore/drivers/posix/sockets.d index d472e44..610aeef 100644 --- a/source/eventcore/drivers/posix/sockets.d +++ b/source/eventcore/drivers/posix/sockets.d @@ -90,7 +90,10 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets assert(on_connect !is null); auto sockfd = createSocket(address.addressFamily, SOCK_STREAM); - if (sockfd == -1) return StreamSocketFD.invalid; + if (sockfd == -1) { + on_connect(StreamSocketFD.invalid, ConnectStatus.socketCreateFailure); + return StreamSocketFD.invalid; + } auto sock = cast(StreamSocketFD)sockfd; diff --git a/source/eventcore/drivers/winapi/sockets.d b/source/eventcore/drivers/winapi/sockets.d index 4d9b9b4..da97b93 100644 --- a/source/eventcore/drivers/winapi/sockets.d +++ b/source/eventcore/drivers/winapi/sockets.d @@ -41,8 +41,10 @@ final class WinAPIEventDriverSockets : EventDriverSockets { assert(m_tid == GetCurrentThreadId()); auto fd = WSASocketW(peer_address.addressFamily, SOCK_STREAM, IPPROTO_TCP, null, 0, WSA_FLAG_OVERLAPPED); - if (fd == INVALID_SOCKET) + if (fd == INVALID_SOCKET) { + on_connect(StreamSocketFD.invalid, ConnectStatus.socketCreateFailure); return StreamSocketFD.invalid; + } void invalidateSocket() @nogc @trusted nothrow { closesocket(fd); fd = INVALID_SOCKET; }