diff options
Diffstat (limited to 'src/lib/web/mongoose.c')
-rw-r--r-- | src/lib/web/mongoose.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lib/web/mongoose.c b/src/lib/web/mongoose.c index b98149acc30..57804c17566 100644 --- a/src/lib/web/mongoose.c +++ b/src/lib/web/mongoose.c @@ -548,6 +548,12 @@ static sock_t ns_open_listening_socket(union socket_address *sa) { if ((sock = socket(sa->sa.sa_family, SOCK_STREAM, 6)) != INVALID_SOCKET && #ifndef _WIN32 + // SO_RESUSEADDR is not enabled on Windows because the semantics of + // SO_REUSEADDR on UNIX and Windows is different. On Windows, + // SO_REUSEADDR allows to bind a socket to a port without error even if + // the port is already open by another program. This is not the behavior + // SO_REUSEADDR was designed for, and leads to hard-to-track failure + // scenarios. Therefore, SO_REUSEADDR was disabled on Windows. !setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) && #endif !bind(sock, &sa->sa, sa->sa.sa_family == AF_INET ? @@ -4931,7 +4937,10 @@ static void mg_ev_handler(struct ns_connection *nc, enum ns_event ev, void *p) { case NS_POLL: if (call_user(conn, MG_POLL) == MG_TRUE) { - nc->flags |= NSF_FINISHED_SENDING_DATA; + if (conn->ns_conn->flags & MG_HEADERS_SENT) { + write_terminating_chunk(conn); + } + close_local_endpoint(conn); } if (conn != NULL && conn->endpoint_type == EP_FILE) { |