comparison src/event/modules/ngx_iocp_module.c @ 114:ac69ab96328d

nginx-0.0.1-2003-07-07-10:11:50 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 07 Jul 2003 06:11:50 +0000
parents 6dfda4cf5200
children ef8c87afcfc5
comparison
equal deleted inserted replaced
113:d7f606e25b99 114:ac69ab96328d
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 #include <ngx_iocp_module.h> 10 #include <ngx_iocp_module.h>
11 11
12 12
13 static int ngx_iocp_init(ngx_log_t *log); 13 static int ngx_iocp_init(ngx_cycle_t *cycle);
14 static void ngx_iocp_done(ngx_log_t *log); 14 static void ngx_iocp_done(ngx_cycle_t *cycle);
15 static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key); 15 static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key);
16 static int ngx_iocp_del_connection(ngx_connection_t *c); 16 static int ngx_iocp_del_connection(ngx_connection_t *c);
17 static int ngx_iocp_process_events(ngx_log_t *log); 17 static int ngx_iocp_process_events(ngx_log_t *log);
18 static void *ngx_iocp_create_conf(ngx_pool_t *pool); 18 static void *ngx_iocp_create_conf(ngx_cycle_t *cycle);
19 static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf); 19 static char *ngx_iocp_init_conf(ngx_cycle_t *cycle, void *conf);
20 20
21 21
22 static ngx_str_t iocp_name = ngx_string("iocp"); 22 static ngx_str_t iocp_name = ngx_string("iocp");
23 23
24 static ngx_command_t ngx_iocp_commands[] = { 24 static ngx_command_t ngx_iocp_commands[] = {
70 ngx_module_t ngx_iocp_module = { 70 ngx_module_t ngx_iocp_module = {
71 NGX_MODULE, 71 NGX_MODULE,
72 &ngx_iocp_module_ctx, /* module context */ 72 &ngx_iocp_module_ctx, /* module context */
73 ngx_iocp_commands, /* module directives */ 73 ngx_iocp_commands, /* module directives */
74 NGX_EVENT_MODULE, /* module type */ 74 NGX_EVENT_MODULE, /* module type */
75 NULL /* init module */ 75 NULL, /* init module */
76 NULL /* init child */
76 }; 77 };
77 78
78 79
79 static HANDLE iocp; 80 static HANDLE iocp;
80 81
81 82
82 static int ngx_iocp_init(ngx_log_t *log) 83 static int ngx_iocp_init(ngx_cycle_t *cycle)
83 { 84 {
84 ngx_iocp_conf_t *cf; 85 ngx_iocp_conf_t *cf;
85 86
86 cf = ngx_event_get_conf(ngx_iocp_module); 87 cf = ngx_event_get_conf(cycle->conf_ctx, ngx_iocp_module);
87
88 iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, cf->threads);
89 88
90 if (iocp == NULL) { 89 if (iocp == NULL) {
91 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 90 iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0,
91 cf->threads);
92 }
93
94 if (iocp == NULL) {
95 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
92 "CreateIoCompletionPort() failed"); 96 "CreateIoCompletionPort() failed");
93 return NGX_ERROR; 97 return NGX_ERROR;
94 } 98 }
95 99
96 if (ngx_event_timer_init(log) == NGX_ERROR) { 100 if (ngx_event_timer_init(cycle) == NGX_ERROR) {
97 return NGX_ERROR; 101 return NGX_ERROR;
98 } 102 }
103
104 ngx_io = ngx_os_io;
99 105
100 ngx_event_actions = ngx_iocp_module_ctx.actions; 106 ngx_event_actions = ngx_iocp_module_ctx.actions;
101 107
102 ngx_event_flags = NGX_HAVE_AIO_EVENT|NGX_HAVE_IOCP_EVENT; 108 ngx_event_flags = NGX_HAVE_AIO_EVENT|NGX_HAVE_IOCP_EVENT;
103 109
104 return NGX_OK; 110 return NGX_OK;
105 } 111 }
106 112
107 113
108 static void ngx_iocp_done(ngx_log_t *log) 114 static void ngx_iocp_done(ngx_cycle_t *cycle)
109 { 115 {
110 if (CloseHandle(iocp) == -1) { 116 if (CloseHandle(iocp) == -1) {
111 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 117 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
112 "iocp CloseHandle() failed"); 118 "iocp CloseHandle() failed");
113 } 119 }
114 120
115 ngx_event_timer_done(log); 121 iocp = NULL;
122
123 ngx_event_timer_done(cycle);
116 } 124 }
117 125
118 126
119 static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key) 127 static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
120 { 128 {
175 183
176 ngx_log_debug(log, "iocp: %d, %d, %d:%08x" _ rc _ bytes _ key _ ovlp); 184 ngx_log_debug(log, "iocp: %d, %d, %d:%08x" _ rc _ bytes _ key _ ovlp);
177 185
178 if (rc == 0) { 186 if (rc == 0) {
179 err = ngx_errno; 187 err = ngx_errno;
180 188 } else {
189 err = 0;
190 }
191
192 if (timer != INFINITE) {
193 delta = ngx_msec() - delta;
194 ngx_event_expire_timers(delta);
195 }
196
197 if (err) {
181 if (ovlp == NULL) { 198 if (ovlp == NULL) {
182 if (err != WAIT_TIMEOUT) { 199 if (err != WAIT_TIMEOUT) {
183 ngx_log_error(NGX_LOG_ALERT, log, err, 200 ngx_log_error(NGX_LOG_ALERT, log, err,
184 "GetQueuedCompletionStatus() failed"); 201 "GetQueuedCompletionStatus() failed");
185 202
187 } 204 }
188 205
189 } else { 206 } else {
190 ovlp->error = err; 207 ovlp->error = err;
191 } 208 }
192 }
193
194 if (timer != INFINITE) {
195 delta = ngx_msec() - delta;
196 ngx_event_expire_timers(delta);
197 } 209 }
198 210
199 if (ovlp) { 211 if (ovlp) {
200 ev = ovlp->event; 212 ev = ovlp->event;
201 213
222 234
223 return NGX_OK; 235 return NGX_OK;
224 } 236 }
225 237
226 238
227 static void *ngx_iocp_create_conf(ngx_pool_t *pool) 239 static void *ngx_iocp_create_conf(ngx_cycle_t *cycle)
228 { 240 {
229 ngx_iocp_conf_t *cf; 241 ngx_iocp_conf_t *cf;
230 242
231 ngx_test_null(cf, ngx_palloc(pool, sizeof(ngx_iocp_conf_t)), 243 ngx_test_null(cf, ngx_palloc(cycle->pool, sizeof(ngx_iocp_conf_t)),
232 NGX_CONF_ERROR); 244 NGX_CONF_ERROR);
233 245
234 cf->threads = NGX_CONF_UNSET; 246 cf->threads = NGX_CONF_UNSET;
235 cf->acceptex = NGX_CONF_UNSET; 247 cf->acceptex = NGX_CONF_UNSET;
236 cf->acceptex_read = NGX_CONF_UNSET; 248 cf->acceptex_read = NGX_CONF_UNSET;
237 249
238 return cf; 250 return cf;
239 } 251 }
240 252
241 253
242 static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf) 254 static char *ngx_iocp_init_conf(ngx_cycle_t *cycle, void *conf)
243 { 255 {
244 ngx_iocp_conf_t *cf = conf; 256 ngx_iocp_conf_t *cf = conf;
245 257
246 ngx_conf_init_value(cf->threads, 0); 258 ngx_conf_init_value(cf->threads, 0);
247 ngx_conf_init_value(cf->acceptex, 10); 259 ngx_conf_init_value(cf->acceptex, 10);