summaryrefslogtreecommitdiffstats
path: root/third_party/mongoose/chrome-mongoose-modifications.diff
blob: 0f80a8b0360eb732e21efd2dbbc7130e5cab725d (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
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);