diff --git a/components/esp_http_server/src/httpd_ws.c b/components/esp_http_server/src/httpd_ws.c index c2f0ad581d..c4dd8c07e3 100644 --- a/components/esp_http_server/src/httpd_ws.c +++ b/components/esp_http_server/src/httpd_ws.c @@ -328,9 +328,15 @@ esp_err_t httpd_ws_recv_frame(httpd_req_t *req, httpd_ws_frame_t *frame, size_t return ESP_FAIL; } - if (httpd_recv_with_opt(req, (char *)frame->payload, frame->len, false) <= 0) { - ESP_LOGW(TAG, LOG_FMT("Failed to receive payload")); - return ESP_FAIL; + int read_len = 0, left_len = frame->len; + while (left_len > 0) { + if ((read_len = httpd_recv_with_opt(req, (char *)frame->payload + read_len, left_len, false)) <= 0) { + ESP_LOGW(TAG, LOG_FMT("Failed to receive payload")); + return ESP_FAIL; + } + if (left_len -= read_len) { + ESP_LOGD(TAG, "recv data length is less than the data length we want. Read again!"); + } } /* Unmask payload */