summaryrefslogtreecommitdiffstats
path: root/third_party/mongoose/chrome-mongoose-modifications.diff
blob: b37162dd026f89eab431de9ba1cc4de7829ce816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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