OLD | NEW |
| (Empty) |
1 diff --git a/third_party/mongoose/mongoose.c b/third_party/mongoose/mongoose.c | |
2 --- a/third_party/mongoose/mongoose.c | |
3 +++ b/third_party/mongoose/mongoose.c | |
4 @@ -23,7 +23,9 @@ | |
5 #else | |
6 #define _XOPEN_SOURCE 600 // For flockfile() on Linux | |
7 #define _LARGEFILE_SOURCE // Enable 64-bit file offsets | |
8 +#ifndef __STDC_FORMAT_MACROS | |
9 #define __STDC_FORMAT_MACROS // <inttypes.h> wants this for C++ | |
10 +#endif // __STDC_FORMAT_MACROS | |
11 #endif | |
12 | |
13 #if defined(__SYMBIAN32__) | |
14 @@ -51,8 +53,12 @@ | |
15 #include <stdio.h> | |
16 | |
17 #if defined(_WIN32) && !defined(__SYMBIAN32__) // Windows specific | |
18 + #ifdef _WIN32_WINNT | |
19 + #undef _WIN32_WINNT | |
20 + #endif | |
21 #define _WIN32_WINNT 0x0400 // To make it link in VS2005 | |
22 #include <windows.h> | |
23 +#include <winsock2.h> | |
24 | |
25 #ifndef PATH_MAX | |
26 #define PATH_MAX MAX_PATH | |
27 @@ -63,7 +69,6 @@ | |
28 #include <direct.h> | |
29 #include <io.h> | |
30 #else // _WIN32_WCE | |
31 -#include <winsock2.h> | |
32 #define NO_CGI // WinCE has no pipes | |
33 | |
34 typedef long off_t; | |
35 @@ -849,7 +854,9 @@ static int pthread_cond_init(pthread_cond_t *cv, const void
*unused) { | |
36 } | |
37 | |
38 static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) { | |
39 - HANDLE handles[] = {cv->signal, cv->broadcast}; | |
40 + HANDLE handles[2]; | |
41 + handles[0] = cv->signal; | |
42 + handles[1] = cv->broadcast; | |
43 ReleaseMutex(*mutex); | |
44 WaitForMultipleObjects(2, handles, FALSE, INFINITE); | |
45 return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0? 0 : -1; | |
46 @@ -3424,6 +3431,10 @@ static int set_ports_option(struct mg_context *ctx) { | |
47 struct vec vec; | |
48 struct socket so, *listener; | |
49 | |
50 + struct linger linger; | |
51 + linger.l_onoff = 1; | |
52 + linger.l_linger = 1; | |
53 + | |
54 while (success && (list = next_option(list, &vec, NULL)) != NULL) { | |
55 if (!parse_port_string(&vec, &so)) { | |
56 cry(fc(ctx), "%s: %.*s: invalid port spec. Expecting list of: %s", | |
57 @@ -3448,6 +3459,8 @@ static int set_ports_option(struct mg_context *ctx) { | |
58 // Thanks to Igor Klopov who suggested the patch. | |
59 setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &on, | |
60 sizeof(on)) != 0 || | |
61 + setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &linger, | |
62 + sizeof(linger)) || | |
63 bind(sock, &so.lsa.u.sa, so.lsa.len) != 0 || | |
64 listen(sock, 100) != 0) { | |
65 closesocket(sock); | |
66 @@ -3768,15 +3781,8 @@ static void reset_per_request_attributes(struct mg_connec
tion *conn) { | |
67 | |
68 static void close_socket_gracefully(SOCKET sock) { | |
69 char buf[BUFSIZ]; | |
70 - struct linger linger; | |
71 int n; | |
72 | |
73 - // Set linger option to avoid socket hanging out after close. This prevent | |
74 - // ephemeral port exhaust problem under high QPS. | |
75 - linger.l_onoff = 1; | |
76 - linger.l_linger = 1; | |
77 - setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger)); | |
78 - | |
79 // Send FIN to the client | |
80 (void) shutdown(sock, SHUT_WR); | |
81 set_non_blocking_mode(sock); | |
82 @@ -4233,8 +4239,6 @@ struct mg_context *mg_start(mg_callback_t user_callback, v
oid *user_data, | |
83 // Ignore SIGPIPE signal, so if browser cancels the request, it | |
84 // won't kill the whole process. | |
85 (void) signal(SIGPIPE, SIG_IGN); | |
86 - // Also ignoring SIGCHLD to let the OS to reap zombies properly. | |
87 - (void) signal(SIGCHLD, SIG_IGN); | |
88 #endif // !_WIN32 | |
89 | |
90 (void) pthread_mutex_init(&ctx->mutex, NULL); | |
91 @@ -3812,1 +3812,1 @@ static void close_connection(struct mg_connection *conn) { | |
92 } | |
93 | |
94 static void discard_current_request_from_buffer(struct mg_connection *conn) { | |
95 - char *buffered; | |
96 int buffered_len, body_len; | |
97 | |
98 - buffered = conn->buf + conn->request_len; | |
99 buffered_len = conn->data_len - conn->request_len; | |
100 assert(buffered_len >= 0); | |
101 | |
102 @@ -3867,7 +3865,7 @@ static void handle_proxy_request(struct mg_connection *con
n) { | |
103 } | |
104 conn->peer->client.is_ssl = is_ssl; | |
105 } | |
106 - | |
107 + | |
108 // Forward client's request to the target | |
109 mg_printf(conn->peer, "%s %s HTTP/%s\r\n", ri->request_method, ri->uri + len, | |
110 ri->http_version); | |
111 @@ -2820,6 +2820,8 @@ static void prepare_cgi_environment(struct mg_connection *
conn, | |
112 blk->len = blk->nvars = 0; | |
113 blk->conn = conn; | |
114 | |
115 + memset(&root, 0, sizeof(root)); | |
116 + | |
117 get_document_root(conn, &root); | |
118 | |
119 addenv(blk, "SERVER_NAME=%s", conn->ctx->config[AUTHENTICATION_DOMAIN]); | |
120 @@ -2916,6 +2918,8 @@ static void handle_cgi_request(struct mg_connection *conn,
const char *prog) { | |
121 FILE *in, *out; | |
122 pid_t pid; | |
123 | |
124 + memset(&ri, 0, sizeof(ri)); | |
125 + | |
126 prepare_cgi_environment(conn, prog, &blk); | |
127 | |
128 // CGI must be executed in its own directory. 'dir' must point to the | |
129 | |
OLD | NEW |