Skip to content

Commit

Permalink
esp_http_server: Add linger in httpd_config_t
Browse files Browse the repository at this point in the history
Closes: #9514
  • Loading branch information
hmalpani committed Sep 27, 2022
1 parent cc74a9b commit efed5ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/esp_http_server/include/esp_http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ initializer that should be kept in sync
.global_user_ctx_free_fn = NULL, \
.global_transport_ctx = NULL, \
.global_transport_ctx_free_fn = NULL, \
.enable_so_linger = false, \
.linger_timeout = 0, \
.open_fn = NULL, \
.close_fn = NULL, \
.uri_match_fn = NULL \
Expand Down Expand Up @@ -185,6 +187,9 @@ typedef struct httpd_config {
*/
httpd_free_ctx_fn_t global_transport_ctx_free_fn;

bool enable_so_linger; /*!< bool to enable/disable linger */
int linger_timeout; /*!< linger timeout (in seconds) */

/**
* Custom session opening callback.
*
Expand Down
7 changes: 7 additions & 0 deletions components/esp_http_server/src/httpd_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ void httpd_sess_delete(struct httpd_data *hd, struct sock_db *session)
}

ESP_LOGD(TAG, LOG_FMT("fd = %d"), session->fd);
if (hd->config.enable_so_linger) {
struct linger so_linger = {
.l_onoff = true,
.l_linger = hd->config.linger_timeout,
};
setsockopt(session->fd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof(struct linger));
}

// Call close function if defined
if (hd->config.close_fn) {
Expand Down

0 comments on commit efed5ee

Please sign in to comment.