Skip to content

Commit ed79675

Browse files
juhaylinendanieldegrasse
authored andcommitted
net: http_client: Fix handling of POLLHUP
POLLHUP event may be returned even if there is still data to read and POLLIN is set. To ensure all data is consumed, check for POLLHUP after handling POLLIN. https://man7.org/linux/man-pages/man2/poll.2.html Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
1 parent bd2f4ef commit ed79675

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

subsys/net/lib/http/http_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,6 @@ static int http_wait_data(int sock, struct http_request *req, const k_timepoint_
517517
} else if (fds[0].revents & ZSOCK_POLLNVAL) {
518518
ret = -EBADF;
519519
goto error;
520-
} else if (fds[0].revents & ZSOCK_POLLHUP) {
521-
/* Connection closed */
522-
goto closed;
523520
} else if (fds[0].revents & ZSOCK_POLLIN) {
524521
received = zsock_recv(sock, req->internal.response.recv_buf + offset,
525522
req->internal.response.recv_buf_len - offset, 0);
@@ -593,6 +590,9 @@ static int http_wait_data(int sock, struct http_request *req, const k_timepoint_
593590
req->internal.response.recv_buf + processed,
594591
offset);
595592
}
593+
} else if (fds[0].revents & ZSOCK_POLLHUP) {
594+
/* Connection closed */
595+
goto closed;
596596
}
597597

598598
} while (!req->internal.response.message_complete);

0 commit comments

Comments
 (0)