Commit a8441150 authored by valenok's avatar valenok

close_socket_gracefully(): set linger option to prevent port exhaustion

parent 71b6a536
......@@ -3691,8 +3691,15 @@ static void reset_per_request_attributes(struct mg_connection *conn) {
static void close_socket_gracefully(SOCKET sock) {
char buf[BUFSIZ];
struct linger linger;
int n;
// Set linger option to avoid socket hanging out after close. This prevent
// ephemeral port exhaust problem under high QPS.
linger.l_onoff = 1;
linger.l_linger = 1;
setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
// Send FIN to the client
(void) shutdown(sock, SHUT_WR);
set_non_blocking_mode(sock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment