Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Jun 18, 2024
2 parents d65e963 + 19a4b68 commit b1b6c17
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tools/tlcp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,42 @@ int tlcp_client_main(int argc, char *argv[])
goto end;
}
}

read_stdin = 0;
}

for (;;) {
fd_set fds;

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) {
Expand All @@ -282,6 +295,7 @@ int tlcp_client_main(int argc, char *argv[])
read_stdin = 0;
}
}
#endif

if (FD_ISSET(conn.sock, &fds)) {
int rv;
Expand Down

0 comments on commit b1b6c17

Please sign in to comment.