Mercurial > hg > nginx
comparison src/os/win32/ngx_process_cycle.c @ 461:a88a3e4e158f release-0.1.5
nginx-0.1.5-RELEASE import
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 14:07:14 +0000 |
parents | 23fb87bddda1 |
children | d4ea69372b94 |
comparison
equal
deleted
inserted
replaced
460:5f8319142dfc | 461:a88a3e4e158f |
---|---|
5 | 5 |
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 | 10 #include <nginx.h> |
11 | |
12 | |
13 static void *ngx_worker_thread_cycle(void *data); | |
14 static long __stdcall ngx_window_procedure(HWND window, u_int message, | |
15 u_int wparam, long lparam); | |
11 | 16 |
12 #if 0 | 17 #if 0 |
13 ngx_pid_t ngx_new_binary; | 18 ngx_pid_t ngx_new_binary; |
14 | 19 |
15 sig_atomic_t ngx_reap; | 20 sig_atomic_t ngx_reap; |
35 sig_atomic_t ngx_change_binary; | 40 sig_atomic_t ngx_change_binary; |
36 | 41 |
37 #endif | 42 #endif |
38 | 43 |
39 | 44 |
45 static HMENU ngx_menu; | |
46 | |
40 | 47 |
41 void ngx_master_process_cycle(ngx_cycle_t *cycle) | 48 void ngx_master_process_cycle(ngx_cycle_t *cycle) |
42 { | 49 { |
43 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "master mode is not supported"); | 50 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "master mode is not supported"); |
44 | 51 |
46 } | 53 } |
47 | 54 |
48 | 55 |
49 void ngx_single_process_cycle(ngx_cycle_t *cycle) | 56 void ngx_single_process_cycle(ngx_cycle_t *cycle) |
50 { | 57 { |
51 ngx_int_t i; | 58 int rc; |
59 ngx_int_t i; | |
60 ngx_err_t err; | |
61 ngx_tid_t tid; | |
62 MSG message; | |
63 HWND window; | |
64 HMENU menu; | |
65 HICON icon,tray; | |
66 WNDCLASS wc; | |
67 HINSTANCE instance; | |
68 ngx_core_conf_t *ccf; | |
52 | 69 |
53 ngx_init_temp_number(); | 70 ngx_init_temp_number(); |
54 | 71 |
55 for (i = 0; ngx_modules[i]; i++) { | 72 for (i = 0; ngx_modules[i]; i++) { |
56 if (ngx_modules[i]->init_process) { | 73 if (ngx_modules[i]->init_process) { |
59 exit(2); | 76 exit(2); |
60 } | 77 } |
61 } | 78 } |
62 } | 79 } |
63 | 80 |
81 | |
82 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
83 | |
84 if (ngx_init_threads(ngx_threads_n, | |
85 ccf->thread_stack_size, cycle) == NGX_ERROR) | |
86 { | |
87 /* fatal */ | |
88 exit(2); | |
89 } | |
90 | |
91 err = ngx_thread_key_create(&ngx_core_tls_key); | |
92 if (err != 0) { | |
93 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
94 ngx_thread_key_create_n " failed"); | |
95 /* fatal */ | |
96 exit(2); | |
97 } | |
98 | |
99 | |
100 instance = GetModuleHandle(NULL); | |
101 | |
102 icon = LoadIcon(instance, "nginx"); | |
103 if (icon == NULL) { | |
104 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
105 "LoadIcon(\"nginx\") failed"); | |
106 /* fatal */ | |
107 exit(2); | |
108 } | |
109 | |
110 tray = LoadIcon(instance, "tray"); | |
111 if (icon == NULL) { | |
112 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
113 "LoadIcon(\"tray\") failed"); | |
114 /* fatal */ | |
115 exit(2); | |
116 } | |
117 | |
118 menu = LoadMenu(instance, "nginx"); | |
119 if (menu == NULL) { | |
120 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
121 "LoadMenu() failed"); | |
122 /* fatal */ | |
123 exit(2); | |
124 } | |
125 | |
126 ngx_menu = GetSubMenu(menu, 0); | |
127 if (ngx_menu == NULL) { | |
128 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
129 "GetSubMenu() failed"); | |
130 /* fatal */ | |
131 exit(2); | |
132 } | |
133 | |
134 | |
135 wc.style = CS_HREDRAW|CS_VREDRAW; | |
136 wc.lpfnWndProc = ngx_window_procedure; | |
137 wc.cbClsExtra = 0; | |
138 wc.cbWndExtra = 0; | |
139 wc.hInstance = instance; | |
140 wc.hIcon = icon; | |
141 wc.hCursor = NULL; | |
142 wc.hbrBackground = NULL; | |
143 wc.lpszMenuName = NULL; | |
144 wc.lpszClassName = "nginx"; | |
145 | |
146 if (RegisterClass(&wc) == 0) { | |
147 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
148 "RegisterClass() failed"); | |
149 /* fatal */ | |
150 exit(2); | |
151 } | |
152 | |
153 | |
154 window = CreateWindow("nginx", "nginx", WS_OVERLAPPEDWINDOW, | |
155 CW_USEDEFAULT, CW_USEDEFAULT, | |
156 CW_USEDEFAULT, CW_USEDEFAULT, | |
157 NULL, NULL, instance, NULL); | |
158 | |
159 if (window == NULL) { | |
160 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
161 "CreateWindow() failed"); | |
162 /* fatal */ | |
163 exit(2); | |
164 } | |
165 | |
166 | |
167 if (ngx_system_tray_icon(window, NIM_ADD, tray, (u_char *) " nginx") | |
168 == NGX_ERROR) | |
169 { | |
170 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
171 "Shell_NotifyIcon(NIM_ADD) failed"); | |
172 /* fatal */ | |
173 exit(2); | |
174 } | |
175 | |
176 | |
177 if (ngx_create_thread(&tid, ngx_worker_thread_cycle, NULL, cycle->log) != 0) | |
178 { | |
179 /* fatal */ | |
180 exit(2); | |
181 } | |
182 | |
183 | |
184 for ( ;; ) { | |
185 rc = GetMessage(&message, NULL, 0, 0); | |
186 | |
187 if (rc == -1) { | |
188 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
189 "GetMessage() failed"); | |
190 continue; | |
191 } | |
192 | |
193 if (rc == 0) { | |
194 exit(0); | |
195 } | |
196 | |
197 TranslateMessage(&message); | |
198 DispatchMessage(&message); | |
199 } | |
200 } | |
201 | |
202 | |
203 static void *ngx_worker_thread_cycle(void *data) | |
204 { | |
205 ngx_cycle_t *cycle; | |
206 | |
207 cycle = (ngx_cycle_t *) ngx_cycle; | |
208 | |
64 for ( ;; ) { | 209 for ( ;; ) { |
65 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); | 210 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); |
66 | 211 |
67 ngx_process_events(cycle); | 212 ngx_process_events(cycle); |
68 } | 213 } |
69 } | 214 |
215 return NULL; | |
216 } | |
217 | |
218 | |
219 static long __stdcall ngx_window_procedure(HWND window, u_int message, | |
220 u_int wparam, long lparam) | |
221 { | |
222 POINT mouse; | |
223 | |
224 switch (message) { | |
225 | |
226 case NGX_WM_TRAY: | |
227 if (lparam == WM_RBUTTONDOWN) { | |
228 if (GetCursorPos(&mouse) == 0) { | |
229 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
230 "GetCursorPos() failed"); | |
231 return 0; | |
232 } | |
233 | |
234 if (SetForegroundWindow(window) == 0) { | |
235 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
236 "SetForegroundWindow() failed"); | |
237 return 0; | |
238 } | |
239 | |
240 if (TrackPopupMenu(ngx_menu, TPM_RIGHTBUTTON, | |
241 mouse.x, mouse.y, 0, window, NULL) == 0) | |
242 { | |
243 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
244 "TrackPopupMenu() failed"); | |
245 return 0; | |
246 } | |
247 } | |
248 | |
249 return 0; | |
250 | |
251 case WM_COMMAND: | |
252 if (wparam == NGX_WM_ABOUT) { | |
253 ngx_message_box("nginx", MB_OK, 0, | |
254 NGINX_VER CRLF "(C) 2002-2004 Igor Sysoev"); | |
255 return 0; | |
256 } | |
257 | |
258 if (wparam == NGX_WM_EXIT) { | |
259 if (ngx_system_tray_icon(window, NIM_DELETE, NULL, NULL) | |
260 == NGX_ERROR) | |
261 { | |
262 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, | |
263 "Shell_NotifyIcon(NIM_DELETE) failed"); | |
264 } | |
265 } | |
266 | |
267 PostQuitMessage(0); | |
268 | |
269 return 0; | |
270 | |
271 default: | |
272 return DefWindowProc(window, message, wparam, lparam); | |
273 } | |
274 } |