fix(tcp_tranport): Fix handling of select() return value

When both readset/writeset and errset are set for a single socket,
the HTTP client incorrectly handled the condition, causing premature termination.
Added a check to ensure readset/writeset is prioritized before errset.

Closes https://github.com/espressif/esp-idf/issues/14673
This commit is contained in:
nilesh.kale 2024-10-07 14:24:43 +05:30
parent 260c81d5c0
commit d09f48c97b

View File

@ -166,7 +166,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);