Plink's front-end select loop was failing to send error messages to
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 10 Jan 2002 13:06:26 +0000 (13:06 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 10 Jan 2002 13:06:26 +0000 (13:06 +0000)
winnet.c. The result was that complete failures to make an SSH
connection (connection refused, for example) were causing a hang
instead of a proper error report.

git-svn-id: svn://svn.tartarus.org/sgt/putty@1539 cda61777-01e9-0310-a592-d414129be87e

plink.c

diff --git a/plink.c b/plink.c
index 047414a..891e7d5 100644 (file)
--- a/plink.c
+++ b/plink.c
@@ -679,21 +679,26 @@ int main(int argc, char **argv)
                socket = sklist[i];
                wp = (WPARAM) socket;
                if (!WSAEnumNetworkEvents(socket, NULL, &things)) {
+                    static const struct { int bit, mask; } eventtypes[] = {
+                        {FD_CONNECT_BIT, FD_CONNECT},
+                        {FD_READ_BIT, FD_READ},
+                        {FD_CLOSE_BIT, FD_CLOSE},
+                        {FD_OOB_BIT, FD_OOB},
+                        {FD_WRITE_BIT, FD_WRITE},
+                        {FD_ACCEPT_BIT, FD_ACCEPT},
+                    };
+                    int e;
+
                    noise_ultralight(socket);
                    noise_ultralight(things.lNetworkEvents);
-                   if (things.lNetworkEvents & FD_CONNECT)
-                       connopen &= select_result(wp, (LPARAM) FD_CONNECT);
-                   if (things.lNetworkEvents & FD_READ)
-                       connopen &= select_result(wp, (LPARAM) FD_READ);
-                   if (things.lNetworkEvents & FD_CLOSE)
-                       connopen &= select_result(wp, (LPARAM) FD_CLOSE);
-                   if (things.lNetworkEvents & FD_OOB)
-                       connopen &= select_result(wp, (LPARAM) FD_OOB);
-                   if (things.lNetworkEvents & FD_WRITE)
-                       connopen &= select_result(wp, (LPARAM) FD_WRITE);
-                   if (things.lNetworkEvents & FD_ACCEPT)
-                       connopen &= select_result(wp, (LPARAM) FD_ACCEPT);
 
+                    for (e = 0; e < lenof(eventtypes); e++)
+                        if (things.lNetworkEvents & eventtypes[e].mask) {
+                            LPARAM lp;
+                            int err = things.iErrorCode[eventtypes[e].bit];
+                            lp = WSAMAKESELECTREPLY(eventtypes[e].mask, err);
+                            connopen &= select_result(wp, lp);
+                        }
                }
            }
        } else if (n == 1) {