[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use WSAGetLastError on Windows to detect that connect is in progress


Hello,

Here is a patch for the nonblocking connect on Windows. The patch uses
WSAGetLastError on Windows to check that the connect is in progress, Using
errno on Windows does not work, errno will always be 0, even if the connect
fails.

I do not know whether errno = 0; before connect and the check for (errno !=
0) is still needed on other platforms. I'd expect that a "successful"
connect that cannot complete immediately will always set errno to
EINPROGRESS on platforms that use errno.

Regards
Jan


From 0024ccae310accc2245a6f7e74cd5e6ed7db5282 Mon Sep 17 00:00:00 2001
From: Jan Krause <voltamund@xxxxxxxxx>
Date: Wed, 23 May 2018 19:39:48 +0200
Subject: [PATCH] Use WSAGetLastError on Windows to detect that connect is in
 progress

Signed-off-by: Jan Krause <voltamund@xxxxxxxxx>
---
 src/connect.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/connect.c b/src/connect.c
index d7c2a32c..ecd1489d 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -408,7 +408,12 @@ socket_t ssh_connect_host_nonblocking(ssh_session
session, const char *host,

     errno = 0;
     rc = connect(s, itr->ai_addr, itr->ai_addrlen);
-    if (rc == -1 && (errno != 0) && (errno != EINPROGRESS)) {
+#ifdef _WIN32
+    if ((rc == -1) && (WSAGetLastError() != WSAEWOULDBLOCK))
+#else
+    if (rc == -1 && (errno != 0) && (errno != EINPROGRESS))
+#endif
+    {
       ssh_set_error(session, SSH_FATAL,
           "Failed to connect: %s", strerror(errno));
       ssh_connect_socket_close(s);
-- 
2.16.1.windows.4



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Archive administrator: postmaster@lists.cynapses.org