mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-21 11:30:01 +00:00
close_socket_gracefully(): set linger option to prevent port exhaustion
This commit is contained in:
1 parent
71b6a53617
commit
a844115043
1 file changed
+7
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user