|  | @@ -3691,8 +3691,15 @@ static void reset_per_request_attributes(struct mg_connection *conn) {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  static void close_socket_gracefully(SOCKET sock) {
 |  |  static void close_socket_gracefully(SOCKET sock) {
 | 
											
												
													
														|  |    char buf[BUFSIZ];
 |  |    char buf[BUFSIZ];
 | 
											
												
													
														|  | 
 |  | +  struct linger linger;
 | 
											
												
													
														|  |    int n;
 |  |    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
 |  |    // Send FIN to the client
 | 
											
												
													
														|  |    (void) shutdown(sock, SHUT_WR);
 |  |    (void) shutdown(sock, SHUT_WR);
 | 
											
												
													
														|  |    set_non_blocking_mode(sock);
 |  |    set_non_blocking_mode(sock);
 |