diff --git a/components/tcp_transport/transport_ssl.c b/components/tcp_transport/transport_ssl.c index a11f160fbc..0a3adbac3b 100644 --- a/components/tcp_transport/transport_ssl.c +++ b/components/tcp_transport/transport_ssl.c @@ -174,7 +174,10 @@ static int base_poll_read(esp_transport_handle_t t, int timeout_ms) return remain; } ret = select(ssl->sockfd + 1, &readset, NULL, &errset, esp_transport_utils_ms_to_timeval(timeout_ms, &timeout)); - if (ret > 0 && FD_ISSET(ssl->sockfd, &errset)) { + // The select() function monitors the socket for readiness to read or write, and checks for errors. + // If both an error (errset) and readiness (readset/writeset) are detected simultaneously, + // this code ensures that the pending read data must be handled before we start processing error. + if (ret == 1 && FD_ISSET(ssl->sockfd, &errset)) { int sock_errno = 0; uint32_t optlen = sizeof(sock_errno); getsockopt(ssl->sockfd, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);