]> granicus.if.org Git - esp-idf/commitdiff
HTTP Server : Bug fixed in httpd_recv logic and updated function descriptions
authorAnurag Kar <anurag.kar@espressif.com>
Tue, 9 Oct 2018 12:24:33 +0000 (17:54 +0530)
committerAnurag Kar <anurag.kar@espressif.com>
Wed, 17 Oct 2018 12:06:50 +0000 (17:36 +0530)
components/http_server/include/http_server.h
components/http_server/src/httpd_txrx.c

index fa65dd32fb5750099499efa09a72ef5ba85efeba..dec25768dfade0db0ab7deba28b04a6734df0883 100644 (file)
@@ -378,6 +378,7 @@ typedef int (*httpd_send_func_t)(int sockfd, const char *buf, size_t buf_len, in
  *
  * @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()
@@ -480,8 +481,8 @@ int httpd_req_to_sockfd(httpd_req_t *r);
  * @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()
index 0d31eaed279b7d8dcf482456a2b91705567ecd77..ed90cb75da17d7fa112abbe0e2f07b1f42d484c8 100644 (file)
@@ -128,6 +128,15 @@ int httpd_recv_with_opt(httpd_req_t *r, char *buf, size_t buf_len, bool halt_aft
     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;
     }