HTTP Server : Return HTTPD_SOCK_ERR_ based on errno set during send / recv
This feature allows `httpd_req_recv()` and `httpd_send()` functions to return specific `HTTPD_SOCK_ERR_` codes in case of socket errors. This is useful in case of errors like `EAGAIN`, `EINTR`, etc. when the user may want to retry `httpd_req_recv()` / `httpd_send()` function call.
This commit is contained in:
@@ -348,19 +348,39 @@ esp_err_t httpd_unregister_uri(httpd_handle_t handle, const char* uri);
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define HTTPD_SOCK_ERR_FAIL -1
|
||||
#define HTTPD_SOCK_ERR_INVALID -2
|
||||
#define HTTPD_SOCK_ERR_TIMEOUT -3
|
||||
|
||||
/**
|
||||
* @brief Prototype for HTTPDs low-level send function
|
||||
*
|
||||
* @note User specified send function must handle errors internally,
|
||||
* depending upon the set value of errno, and return specific
|
||||
* HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as
|
||||
* return value of httpd_send() function
|
||||
*
|
||||
* @return
|
||||
* - Bytes : The number of bytes sent successfully
|
||||
* - -VE : In case of error
|
||||
* - HTTPD_SOCK_ERR_INVALID : Invalid arguments
|
||||
* - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
|
||||
* - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
|
||||
*/
|
||||
typedef int (*httpd_send_func_t)(int sockfd, const char *buf, size_t buf_len, int flags);
|
||||
|
||||
/**
|
||||
* @brief Prototype for HTTPDs low-level recv function
|
||||
*
|
||||
* @note User specified recv function must handle errors internally,
|
||||
* depending upon the set value of errno, and return specific
|
||||
* HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as
|
||||
* return value of httpd_req_recv() function
|
||||
*
|
||||
* @return
|
||||
* - Bytes : The number of bytes received successfully
|
||||
* - -VE : In case of error
|
||||
* - 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()
|
||||
*/
|
||||
typedef int (*httpd_recv_func_t)(int sockfd, char *buf, size_t buf_len, int flags);
|
||||
|
||||
@@ -462,7 +482,9 @@ int httpd_req_to_sockfd(httpd_req_t *r);
|
||||
* @return
|
||||
* - Bytes : Number of bytes read into the buffer successfully
|
||||
* - Zero : When no more data is left for read
|
||||
* - -1 : On raw recv error / Null arguments / Request pointer is invalid
|
||||
* - 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 httpd_req_recv(httpd_req_t *r, char *buf, size_t buf_len);
|
||||
|
||||
@@ -796,7 +818,9 @@ esp_err_t httpd_resp_send_404(httpd_req_t *r);
|
||||
*
|
||||
* @return
|
||||
* - Bytes : Number of bytes that were sent successfully
|
||||
* - -1 : Error in raw send / Invalid request / Null arguments
|
||||
* - HTTPD_SOCK_ERR_INVALID : Invalid arguments
|
||||
* - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
|
||||
* - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
|
||||
*/
|
||||
int httpd_send(httpd_req_t *r, const char *buf, size_t buf_len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user