blob: b37162dd026f89eab431de9ba1cc4de7829ce816 [file] [log] [blame]
diff --git a/third_party/mongoose/mongoose.c b/third_party/mongoose/mongoose.c
--- a/third_party/mongoose/mongoose.c
+++ b/third_party/mongoose/mongoose.c
@@ -23,7 +23,9 @@
#else
#define _XOPEN_SOURCE 600 // For flockfile() on Linux
#define _LARGEFILE_SOURCE // Enable 64-bit file offsets
+#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS // <inttypes.h> wants this for C++
+#endif // __STDC_FORMAT_MACROS
#endif
#if defined(__SYMBIAN32__)
@@ -51,8 +53,12 @@
#include <stdio.h>
#if defined(_WIN32) && !defined(__SYMBIAN32__) // Windows specific
+ #ifdef _WIN32_WINNT
+ #undef _WIN32_WINNT
+ #endif
#define _WIN32_WINNT 0x0400 // To make it link in VS2005
#include <windows.h>
+#include <winsock2.h>
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
@@ -63,7 +69,6 @@
#include <direct.h>
#include <io.h>
#else // _WIN32_WCE
-#include <winsock2.h>
#define NO_CGI // WinCE has no pipes
typedef long off_t;
@@ -849,7 +854,9 @@ static int pthread_cond_init(pthread_cond_t *cv, const void *unused) {
}
static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) {
- HANDLE handles[] = {cv->signal, cv->broadcast};
+ HANDLE handles[2];
+ handles[0] = cv->signal;
+ handles[1] = cv->broadcast;
ReleaseMutex(*mutex);
WaitForMultipleObjects(2, handles, FALSE, INFINITE);
return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0? 0 : -1;
@@ -3424,6 +3431,10 @@ static int set_ports_option(struct mg_context *ctx) {
struct vec vec;
struct socket so, *listener;
+ struct linger linger;
+ linger.l_onoff = 1;
+ linger.l_linger = 1;
+
while (success && (list = next_option(list, &vec, NULL)) != NULL) {
if (!parse_port_string(&vec, &so)) {
cry(fc(ctx), "%s: %.*s: invalid port spec. Expecting list of: %s",
@@ -3448,6 +3459,8 @@ static int set_ports_option(struct mg_context *ctx) {
// Thanks to Igor Klopov who suggested the patch.
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &on,
sizeof(on)) != 0 ||
+ setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &linger,
+ sizeof(linger)) ||
bind(sock, &so.lsa.u.sa, so.lsa.len) != 0 ||
listen(sock, 100) != 0) {
closesocket(sock);
@@ -3768,15 +3781,8 @@ 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, (void *) &linger, sizeof(linger));
-
// Send FIN to the client
(void) shutdown(sock, SHUT_WR);
set_non_blocking_mode(sock);
@@ -4233,8 +4239,6 @@ struct mg_context *mg_start(mg_callback_t user_callback, void *user_data,
// Ignore SIGPIPE signal, so if browser cancels the request, it
// won't kill the whole process.
(void) signal(SIGPIPE, SIG_IGN);
- // Also ignoring SIGCHLD to let the OS to reap zombies properly.
- (void) signal(SIGCHLD, SIG_IGN);
#endif // !_WIN32
(void) pthread_mutex_init(&ctx->mutex, NULL);
@@ -3812,1 +3812,1 @@ static void close_connection(struct mg_connection *conn) {
}
static void discard_current_request_from_buffer(struct mg_connection *conn) {
- char *buffered;
int buffered_len, body_len;
- buffered = conn->buf + conn->request_len;
buffered_len = conn->data_len - conn->request_len;
assert(buffered_len >= 0);
@@ -3867,7 +3865,7 @@ static void handle_proxy_request(struct mg_connection *conn) {
}
conn->peer->client.is_ssl = is_ssl;
}
-
+
// Forward client's request to the target
mg_printf(conn->peer, "%s %s HTTP/%s\r\n", ri->request_method, ri->uri + len,
ri->http_version);
@@ -2820,6 +2820,8 @@ static void prepare_cgi_environment(struct mg_connection *conn,
blk->len = blk->nvars = 0;
blk->conn = conn;
+ memset(&root, 0, sizeof(root));
+
get_document_root(conn, &root);
addenv(blk, "SERVER_NAME=%s", conn->ctx->config[AUTHENTICATION_DOMAIN]);
@@ -2916,6 +2918,8 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog) {
FILE *in, *out;
pid_t pid;
+ memset(&ri, 0, sizeof(ri));
+
prepare_cgi_environment(conn, prog, &blk);
// CGI must be executed in its own directory. 'dir' must point to the