From 3f05cf98c8423499f02dd29e9147c488c12c3151 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Sun, 4 Feb 2024 11:40:28 +0800 Subject: [PATCH] Update tls.c `tls_set_socket` checks whether socket is in blocking mode --- src/tls.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/tls.c b/src/tls.c index c0a4764b..acd4a852 100644 --- a/src/tls.c +++ b/src/tls.c @@ -2308,21 +2308,17 @@ void tls_cleanup(TLS_CONNECT *conn) int tls_set_socket(TLS_CONNECT *conn, tls_socket_t sock) { -#if 0 - int opts; + int flags; - // FIXME: do we still need this? when using select? - if ((opts = fcntl(sock, F_GETFL)) < 0) { + if ((flags = fcntl(sock, F_GETFL)) == -1) { error_print(); - perror("tls_set_socket"); + perror("fcntl error"); return -1; } - opts &= ~O_NONBLOCK; - if (fcntl(sock, F_SETFL, opts) < 0) { - error_print(); + if (flags & O_NONBLOCK) { + error_puts("socket should be in blocking mode"); return -1; } -#endif conn->sock = sock; return 1; }