diff options
author | Matt Caswell <matt@openssl.org> | 2016-05-20 11:53:26 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-05-27 15:18:46 +0100 |
commit | 75dd6c1a39c4e73de7d8d782adb7008645248f50 (patch) | |
tree | e5c004d97e12eb00ba6e51e4938905b861788c74 /apps/apps.c | |
parent | 384f08dc76e4df2c004042bd9b1bad60f98c281f (diff) | |
download | openssl-75dd6c1a39c4e73de7d8d782adb7008645248f50.tar.gz |
Fix s_client/s_server waiting for stdin on Windows
On Windows we were using the function _kbhit() to determine whether there
was input waiting in stdin for us to read. Actually all this does is work
out whether there is a keyboard press event waiting to be processed in the
input buffer. This only seems to work in a standard Windows console (not
Msys console) and also doesn't work if you redirect the input from some
other source (as we do in TLSProxy tests). This commit changes things to
work differently depending on whether we are on the Windows console or not.
RT#4255
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'apps/apps.c')
-rw-r--r-- | apps/apps.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/apps/apps.c b/apps/apps.c index 5db4b22b3a..a3e1794c31 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -14,6 +14,7 @@ */ # define _POSIX_C_SOURCE 2 #endif + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -41,7 +42,7 @@ #endif #include <openssl/bn.h> #include <openssl/ssl.h> - +#include "s_apps.h" #include "apps.h" #ifdef _WIN32 @@ -2550,3 +2551,31 @@ void wait_for_async(SSL *s) select(width, (void *)&asyncfds, NULL, NULL, NULL); #endif } + +/* if OPENSSL_SYS_WINDOWS is defined then so is OPENSSL_SYS_MSDOS */ +#if defined(OPENSSL_SYS_MSDOS) +int has_stdin_waiting(void) +{ +# if defined(OPENSSL_SYS_WINDOWS) + HANDLE inhand = GetStdHandle(STD_INPUT_HANDLE); + DWORD events = 0; + INPUT_RECORD inputrec; + DWORD insize = 1; + BOOL peeked; + + if (inhand == INVALID_HANDLE_VALUE) { + return 0; + } + + peeked = PeekConsoleInput(inhand, &inputrec, insize, &events); + if (!peeked) { + /* Probably redirected input? _kbhit() does not work in this case */ + if (!feof(stdin)) { + return 1; + } + return 0; + } +# endif + return _kbhit(); +} +#endif |