From 19a4b6894f8b4021b866ac0ab1da0f60a8200914 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Thu, 13 Jun 2024 12:16:12 +0800 Subject: [PATCH] Update tlcp_client.c --- tools/tlcp_client.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/tlcp_client.c b/tools/tlcp_client.c index a65d68e0..87377435 100644 --- a/tools/tlcp_client.c +++ b/tools/tlcp_client.c @@ -245,6 +245,8 @@ int tlcp_client_main(int argc, char *argv[]) goto end; } } + + read_stdin = 0; } for (;;) { @@ -252,22 +254,33 @@ int tlcp_client_main(int argc, char *argv[]) FD_ZERO(&fds); FD_SET(conn.sock, &fds); - if (read_stdin) + + if (read_stdin) { #ifdef WIN32 - FD_SET(_fileno, &fds); // in WIN32, first arg type is SOCKET, maybe typedef of uint + if (fgets(buf, sizeof(buf), stdin)) { + if (tls_send(&conn, (uint8_t *)buf, strlen(buf), &len) != 1) { + fprintf(stderr, "%s: send error\n", prog); + goto end; + } + } else { + if (!feof(stdin)) { + fprintf(stderr, "%s: length of input line exceeds buffer size\n", prog); + goto end; + } + read_stdin = 0; + } #else FD_SET(STDIN_FILENO, &fds); // in POSIX, first arg type is int #endif + } if (select(conn.sock + 1, &fds, NULL, NULL, NULL) < 0) { fprintf(stderr, "%s: select error\n", prog); goto end; } #ifdef WIN32 - if (read_stdin && FD_ISSET(_fileno, &fds)) { #else if (read_stdin && FD_ISSET(STDIN_FILENO, &fds)) { -#endif if (fgets(buf, sizeof(buf), stdin)) { if (tls_send(&conn, (uint8_t *)buf, strlen(buf), &len) != 1) { @@ -282,6 +295,7 @@ int tlcp_client_main(int argc, char *argv[]) read_stdin = 0; } } +#endif if (FD_ISSET(conn.sock, &fds)) { int rv;