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