openssl: fix keypress requirement in apps on win32
authorFedor Indutny <fedor.indutny@gmail.com>
Wed, 11 Dec 2013 17:19:04 +0000 (21:19 +0400)
committerTimothy J Fontaine <tjfontaine@gmail.com>
Wed, 13 Aug 2014 16:26:53 +0000 (09:26 -0700)
Original source:

http://openssl.6102.n7.nabble.com/PATCH-s-client-Fix-keypress-requirement-with-redirected-input-on-Windows-td46787.html

Reviewed-By: Fedor Indutny <fedor@indutny.com>
deps/openssl/openssl/apps/s_client.c

index 4625467d990347c9ac9613c1a310a34c070dd184..973e58e160ab1a61b81b489d3fd798213433d380 100644 (file)
@@ -178,6 +178,13 @@ typedef unsigned int u_int;
 #include <fcntl.h>
 #endif
 
+/* Use Windows API with STD_INPUT_HANDLE when checking for input?
+   Don't look at OPENSSL_SYS_MSDOS for this, since it is always defined if
+   OPENSSL_SYS_WINDOWS is defined */
+#if defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_WINCE) && defined(STD_INPUT_HANDLE)
+#define OPENSSL_USE_STD_INPUT_HANDLE
+#endif
+
 #undef PROG
 #define PROG   s_client_main
 
@@ -1606,10 +1613,10 @@ SSL_set_tlsext_status_ids(con, ids);
                                        tv.tv_usec = 0;
                                        i=select(width,(void *)&readfds,(void *)&writefds,
                                                 NULL,&tv);
-#if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)
-                                       if(!i && (!_kbhit() || !read_tty) ) continue;
-#else
+#if defined(OPENSSL_USE_STD_INPUT_HANDLE)
                                        if(!i && (!((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) || !read_tty) ) continue;
+#else
+                                       if(!i && (!_kbhit() || !read_tty) ) continue;
 #endif
                                } else  i=select(width,(void *)&readfds,(void *)&writefds,
                                         NULL,timeoutp);
@@ -1814,10 +1821,10 @@ printf("read=%d pending=%d peek=%d\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240
                        }
 
 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
-#if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)
-               else if (_kbhit())
-#else
+#if defined(OPENSSL_USE_STD_INPUT_HANDLE)
                else if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))
+#else
+               else if (_kbhit())
 #endif
 #elif defined (OPENSSL_SYS_NETWARE)
                else if (_kbhit())