Add s_client support for waiting for async

s_server already had the ability to wait on an async file descriptor. This
adds it to s_client too.

Reviewed-by: Rich Salz <rsalz@openssl.org>
diff --git a/apps/apps.c b/apps/apps.c
index 89f4340..c6b70d6 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -2884,3 +2884,17 @@
     return bio_open_default_(filename, mode, format, 1);
 }
 
+void wait_for_async(SSL *s)
+{
+    int width, fd;
+    fd_set asyncfds;
+
+    fd = SSL_get_async_wait_fd(s);
+    if (fd < 0)
+        return;
+
+    width = fd + 1;
+    FD_ZERO(&asyncfds);
+    openssl_fdset(fd, &asyncfds);
+    select(width, (void *)&asyncfds, NULL, NULL, NULL);
+}
diff --git a/apps/apps.h b/apps/apps.h
index 185ac24..e259658 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -162,6 +162,7 @@
 CONF *app_load_config_quiet(const char *filename);
 int app_load_modules(const CONF *config);
 void unbuffer(FILE *fp);
+void wait_for_async(SSL *s);
 
 /*
  * Common verification options.
diff --git a/apps/s_client.c b/apps/s_client.c
index 723e7cb..4a93b3d 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -1897,6 +1897,7 @@
                 break;
             case SSL_ERROR_WANT_ASYNC:
                 BIO_printf(bio_c_out, "write A BLOCK\n");
+                wait_for_async(con);
                 write_ssl = 1;
                 read_tty = 0;
                 break;
@@ -1984,6 +1985,7 @@
                 break;
             case SSL_ERROR_WANT_ASYNC:
                 BIO_printf(bio_c_out, "read A BLOCK\n");
+                wait_for_async(con);
                 write_tty = 0;
                 read_ssl = 1;
                 if ((read_tty == 0) && (write_ssl == 0))
diff --git a/apps/s_server.c b/apps/s_server.c
index 8645c6c..c90b700 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -194,7 +194,6 @@
 static RSA *tmp_rsa_cb(SSL *s, int is_export, int keylength);
 #endif
 static int not_resumable_sess_cb(SSL *s, int is_forward_secure);
-static void wait_for_async(SSL *s);
 static int sv_body(char *hostname, int s, int stype, unsigned char *context);
 static int www_body(char *hostname, int s, int stype, unsigned char *context);
 static int rev_body(char *hostname, int s, int stype, unsigned char *context);
@@ -2008,21 +2007,6 @@
                SSL_CTX_sess_get_cache_size(ssl_ctx));
 }
 
-static void wait_for_async(SSL *s)
-{
-    int width, fd;
-    fd_set asyncfds;
-
-    fd = SSL_get_async_wait_fd(s);
-    if (fd < 0)
-        return;
-
-    width = fd + 1;
-    FD_ZERO(&asyncfds);
-    openssl_fdset(fd, &asyncfds);
-    select(width, (void *)&asyncfds, NULL, NULL, NULL);
-}
-
 static int sv_body(char *hostname, int s, int stype, unsigned char *context)
 {
     char *buf = NULL;