Merge branch 'bugifx/httpd_reuseaddr_backport_v3.3' into 'release/v3.3'
esp_http_server : Allow binding to same address and port upon restarting server without delay (backport v3.3) See merge request idf/esp-idf!4939
This commit is contained in:
commit
532c8847c7
1 changed files with 9 additions and 0 deletions
|
@ -254,6 +254,15 @@ static esp_err_t httpd_server_init(struct httpd_data *hd)
|
||||||
.sin6_port = htons(hd->config.server_port)
|
.sin6_port = htons(hd->config.server_port)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Enable SO_REUSEADDR to allow binding to the same
|
||||||
|
* address and port when restarting the server */
|
||||||
|
int enable = 1;
|
||||||
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) {
|
||||||
|
/* This will fail if CONFIG_LWIP_SO_REUSE is not enabled. But
|
||||||
|
* it does not affect the normal working of the HTTP Server */
|
||||||
|
ESP_LOGW(TAG, LOG_FMT("error enabling SO_REUSEADDR (%d)"), errno);
|
||||||
|
}
|
||||||
|
|
||||||
int ret = bind(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
int ret = bind(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ESP_LOGE(TAG, LOG_FMT("error in bind (%d)"), errno);
|
ESP_LOGE(TAG, LOG_FMT("error in bind (%d)"), errno);
|
||||||
|
|
Loading…
Reference in a new issue