Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_process_cycle.c @ 2685:6c8a5165ed2a
fix r2590: error_page made an external redirect without query string
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 07 Apr 2009 15:50:08 +0000 |
parents | c9da3e4dc706 |
children | d43d73277c5c |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
5 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
461 | 10 #include <nginx.h> |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
563 | 13 static ngx_thread_value_t __stdcall ngx_worker_thread_cycle(void *data); |
2627 | 14 static void ngx_process_tray(ngx_cycle_t *cycle); |
461 | 15 static long __stdcall ngx_window_procedure(HWND window, u_int message, |
509 | 16 u_int wparam, long lparam); |
461 | 17 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 #if 0 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 ngx_pid_t ngx_new_binary; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 sig_atomic_t ngx_reap; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 sig_atomic_t ngx_timer; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
23 |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
24 #endif |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
25 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
324
diff
changeset
|
26 ngx_uint_t ngx_process; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
324
diff
changeset
|
27 ngx_pid_t ngx_pid; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
324
diff
changeset
|
28 ngx_uint_t ngx_threaded; |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
29 ngx_uint_t ngx_inherited; |
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
30 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
31 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 sig_atomic_t ngx_terminate; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 sig_atomic_t ngx_quit; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
324
diff
changeset
|
34 ngx_uint_t ngx_exiting; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
35 |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
36 #if 0 |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
37 |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 sig_atomic_t ngx_noaccept; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 sig_atomic_t ngx_reconfigure; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 sig_atomic_t ngx_reopen; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 sig_atomic_t ngx_change_binary; |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 #endif |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 |
461 | 46 static HMENU ngx_menu; |
47 | |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
48 |
509 | 49 void |
50 ngx_master_process_cycle(ngx_cycle_t *cycle) | |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 { |
324
0ab66f4b6c4d
nginx-0.0.3-2004-04-22-00:13:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
52 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "master mode is not supported"); |
0ab66f4b6c4d
nginx-0.0.3-2004-04-22-00:13:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
53 |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
54 exit(2); |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
55 } |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
56 |
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
57 |
509 | 58 void |
59 ngx_single_process_cycle(ngx_cycle_t *cycle) | |
318
56496082668b
nginx-0.0.3-2004-04-16-09:14:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
60 { |
461 | 61 ngx_int_t i; |
62 ngx_err_t err; | |
63 ngx_tid_t tid; | |
64 ngx_core_conf_t *ccf; | |
282
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
65 |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
66 ngx_init_temp_number(); |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
67 |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
68 for (i = 0; ngx_modules[i]; i++) { |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
69 if (ngx_modules[i]->init_process) { |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
70 if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) { |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
71 /* fatal */ |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
72 exit(2); |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
73 } |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
74 } |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
75 } |
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
76 |
461 | 77 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
78 | |
2627 | 79 if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle) |
80 != NGX_OK) | |
577 | 81 { |
461 | 82 /* fatal */ |
83 exit(2); | |
84 } | |
85 | |
86 err = ngx_thread_key_create(&ngx_core_tls_key); | |
87 if (err != 0) { | |
88 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
89 ngx_thread_key_create_n " failed"); | |
90 /* fatal */ | |
91 exit(2); | |
92 } | |
93 | |
2627 | 94 if (ngx_create_thread(&tid, ngx_worker_thread_cycle, NULL, cycle->log) |
95 != 0) | |
96 { | |
97 /* fatal */ | |
98 exit(2); | |
99 } | |
100 | |
101 ngx_process_tray(cycle); | |
102 } | |
103 | |
104 | |
105 static ngx_thread_value_t __stdcall | |
106 ngx_worker_thread_cycle(void *data) | |
107 { | |
108 ngx_cycle_t *cycle; | |
109 | |
110 cycle = (ngx_cycle_t *) ngx_cycle; | |
111 | |
112 while (!ngx_quit) { | |
113 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); | |
114 | |
115 ngx_process_events_and_timers(cycle); | |
116 } | |
117 | |
118 return 0; | |
119 } | |
120 | |
121 | |
122 static void | |
123 ngx_process_tray(ngx_cycle_t *cycle) | |
124 { | |
125 int rc; | |
126 MSG message; | |
127 HWND window; | |
128 HMENU menu; | |
129 HICON icon, tray; | |
130 WNDCLASS wc; | |
131 HINSTANCE instance; | |
461 | 132 |
133 instance = GetModuleHandle(NULL); | |
134 | |
135 icon = LoadIcon(instance, "nginx"); | |
136 if (icon == NULL) { | |
137 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
138 "LoadIcon(\"nginx\") failed"); | |
139 /* fatal */ | |
140 exit(2); | |
141 } | |
142 | |
143 tray = LoadIcon(instance, "tray"); | |
144 if (icon == NULL) { | |
145 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
146 "LoadIcon(\"tray\") failed"); | |
147 /* fatal */ | |
148 exit(2); | |
149 } | |
150 | |
151 menu = LoadMenu(instance, "nginx"); | |
152 if (menu == NULL) { | |
153 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
154 "LoadMenu() failed"); | |
155 /* fatal */ | |
156 exit(2); | |
157 } | |
158 | |
159 ngx_menu = GetSubMenu(menu, 0); | |
160 if (ngx_menu == NULL) { | |
161 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
162 "GetSubMenu() failed"); | |
163 /* fatal */ | |
164 exit(2); | |
165 } | |
166 | |
167 | |
577 | 168 wc.style = CS_HREDRAW|CS_VREDRAW; |
461 | 169 wc.lpfnWndProc = ngx_window_procedure; |
170 wc.cbClsExtra = 0; | |
171 wc.cbWndExtra = 0; | |
172 wc.hInstance = instance; | |
173 wc.hIcon = icon; | |
174 wc.hCursor = NULL; | |
175 wc.hbrBackground = NULL; | |
176 wc.lpszMenuName = NULL; | |
177 wc.lpszClassName = "nginx"; | |
178 | |
179 if (RegisterClass(&wc) == 0) { | |
180 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
181 "RegisterClass() failed"); | |
182 /* fatal */ | |
183 exit(2); | |
184 } | |
185 | |
186 window = CreateWindow("nginx", "nginx", WS_OVERLAPPEDWINDOW, | |
187 CW_USEDEFAULT, CW_USEDEFAULT, | |
188 CW_USEDEFAULT, CW_USEDEFAULT, | |
189 NULL, NULL, instance, NULL); | |
190 | |
191 if (window == NULL) { | |
192 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
193 "CreateWindow() failed"); | |
194 /* fatal */ | |
195 exit(2); | |
196 } | |
197 | |
198 | |
199 if (ngx_system_tray_icon(window, NIM_ADD, tray, (u_char *) " nginx") | |
509 | 200 != NGX_OK) |
461 | 201 { |
202 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
203 "Shell_NotifyIcon(NIM_ADD) failed"); | |
204 /* fatal */ | |
205 exit(2); | |
206 } | |
207 | |
208 for ( ;; ) { | |
209 rc = GetMessage(&message, NULL, 0, 0); | |
210 | |
211 if (rc == -1) { | |
212 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
213 "GetMessage() failed"); | |
214 continue; | |
215 } | |
216 | |
217 if (rc == 0) { | |
218 exit(0); | |
219 } | |
220 | |
221 TranslateMessage(&message); | |
222 DispatchMessage(&message); | |
223 } | |
224 } | |
225 | |
226 | |
509 | 227 static long __stdcall |
228 ngx_window_procedure(HWND window, u_int message, u_int wparam, long lparam) | |
461 | 229 { |
230 POINT mouse; | |
231 | |
232 switch (message) { | |
233 | |
234 case NGX_WM_TRAY: | |
235 if (lparam == WM_RBUTTONDOWN) { | |
236 if (GetCursorPos(&mouse) == 0) { | |
237 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
238 "GetCursorPos() failed"); | |
239 return 0; | |
240 } | |
241 | |
242 if (SetForegroundWindow(window) == 0) { | |
243 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
244 "SetForegroundWindow() failed"); | |
245 return 0; | |
246 } | |
247 | |
248 if (TrackPopupMenu(ngx_menu, TPM_RIGHTBUTTON, | |
2627 | 249 mouse.x, mouse.y, 0, window, NULL) |
250 == 0) | |
461 | 251 { |
252 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
253 "TrackPopupMenu() failed"); | |
254 return 0; | |
255 } | |
256 } | |
257 | |
258 return 0; | |
259 | |
260 case WM_COMMAND: | |
261 if (wparam == NGX_WM_ABOUT) { | |
262 ngx_message_box("nginx", MB_OK, 0, | |
2627 | 263 NGINX_VER CRLF "(C) 2002-2009 Igor Sysoev"); |
461 | 264 return 0; |
265 } | |
266 | |
267 if (wparam == NGX_WM_EXIT) { | |
268 if (ngx_system_tray_icon(window, NIM_DELETE, NULL, NULL) | |
509 | 269 != NGX_OK) |
461 | 270 { |
271 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
272 "Shell_NotifyIcon(NIM_DELETE) failed"); | |
273 } | |
274 } | |
275 | |
276 PostQuitMessage(0); | |
277 | |
278 return 0; | |
279 | |
280 default: | |
281 return DefWindowProc(window, message, wparam, lparam); | |
282 } | |
283 } |