*
* @return
* - Bytes : The number of bytes received successfully
+ * - 0 : Buffer length parameter is zero / connection closed by peer
* - HTTPD_SOCK_ERR_INVALID : Invalid arguments
* - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
* - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
* @param[in] buf_len Length of the buffer
*
* @return
- * - Bytes : Number of bytes read into the buffer successfully
- * - Zero : When no more data is left for read
+ * - Bytes : Number of bytes read into the buffer successfully
+ * - 0 : Buffer length parameter is zero / connection closed by peer
* - HTTPD_SOCK_ERR_INVALID : Invalid arguments
* - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
* - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
int ret = ra->sd->recv_fn(ra->sd->fd, buf, buf_len, 0);
if (ret < 0) {
ESP_LOGD(TAG, LOG_FMT("error in recv_fn"));
+ if ((ret == HTTPD_SOCK_ERR_TIMEOUT) && (pending_len != 0)) {
+ /* If recv() timeout occurred, but pending data is
+ * present, return length of pending data.
+ * This behavior is similar to that of socket recv()
+ * function, which, in case has only partially read the
+ * requested length, due to timeout, returns with read
+ * length, rather than error */
+ return pending_len;
+ }
return ret;
}