comparison src/event/modules/ngx_epoll_module.c @ 246:6753e8cdaa2c

nginx-0.0.1-2004-01-30-20:39:00 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 30 Jan 2004 17:39:00 +0000
parents e6c005b66b3a
children 008276b9e061
comparison
equal deleted inserted replaced
245:e6c005b66b3a 246:6753e8cdaa2c
67 } ngx_epoll_conf_t; 67 } ngx_epoll_conf_t;
68 68
69 69
70 static int ngx_epoll_init(ngx_cycle_t *cycle); 70 static int ngx_epoll_init(ngx_cycle_t *cycle);
71 static void ngx_epoll_done(ngx_cycle_t *cycle); 71 static void ngx_epoll_done(ngx_cycle_t *cycle);
72 static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags);
73 static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags);
72 static int ngx_epoll_add_connection(ngx_connection_t *c); 74 static int ngx_epoll_add_connection(ngx_connection_t *c);
73 static int ngx_epoll_del_connection(ngx_connection_t *c); 75 static int ngx_epoll_del_connection(ngx_connection_t *c);
74 static int ngx_epoll_process_events(ngx_log_t *log); 76 static int ngx_epoll_process_events(ngx_log_t *log);
75 77
76 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle); 78 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle);
100 &epoll_name, 102 &epoll_name,
101 ngx_epoll_create_conf, /* create configuration */ 103 ngx_epoll_create_conf, /* create configuration */
102 ngx_epoll_init_conf, /* init configuration */ 104 ngx_epoll_init_conf, /* init configuration */
103 105
104 { 106 {
105 NULL, /* add an event */ 107 ngx_epoll_add_event, /* add an event */
106 NULL, /* delete an event */ 108 ngx_epoll_del_event, /* delete an event */
107 NULL, /* enable an event */ 109 ngx_epoll_add_event, /* enable an event */
108 NULL, /* disable an event */ 110 ngx_epoll_del_event, /* disable an event */
109 ngx_epoll_add_connection, /* add an connection */ 111 ngx_epoll_add_connection, /* add an connection */
110 ngx_epoll_del_connection, /* delete an connection */ 112 ngx_epoll_del_connection, /* delete an connection */
111 ngx_epoll_process_events, /* process the events */ 113 ngx_epoll_process_events, /* process the events */
112 ngx_epoll_init, /* init the events */ 114 ngx_epoll_init, /* init the events */
113 ngx_epoll_done, /* done the events */ 115 ngx_epoll_done, /* done the events */
180 event_list = NULL; 182 event_list = NULL;
181 nevents = 0; 183 nevents = 0;
182 } 184 }
183 185
184 186
187 static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags)
188 {
189 struct epoll_event e;
190 ngx_connection_t *c;
191
192 c = ev->data;
193
194 #if (NGX_READ_EVENT != EPOLLIN) || (NGX_WRITE_EVENT != EPOLLOUT)
195 if (event == NGX_READ_EVENT) {
196 event = EPOLLIN;
197
198 } else {
199 event = EPOLLOUT;
200 }
201 #endif
202
203 e.events = event;
204 e.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
205
206 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
207 "epoll add event: fd:%d ev:%04X", c->fd, e.events);
208
209 if (epoll_ctl(ep, EPOLL_CTL_MOD, c->fd, &e) == -1) {
210 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
211 "epoll_ctl(EPOLL_CTL_MOD, %d) failed", c->fd);
212 return NGX_ERROR;
213 }
214
215 return NGX_OK;
216 }
217
218
219 static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
220 {
221 struct epoll_event e;
222 ngx_connection_t *c;
223
224 c = ev->data;
225
226 #if (NGX_READ_EVENT != EPOLLIN) || (NGX_WRITE_EVENT != EPOLLOUT)
227 if (event == NGX_READ_EVENT) {
228 event = EPOLLIN;
229
230 } else {
231 event = EPOLLOUT;
232 }
233 #endif
234
235 e.events = event;
236 e.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
237
238 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
239 "epoll del event: fd:%d ev:%04X", c->fd, e.events);
240
241 if (epoll_ctl(ep, EPOLL_CTL_MOD, c->fd, &e) == -1) {
242 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
243 "epoll_ctl(EPOLL_CTL_MOD, %d) failed", c->fd);
244 return NGX_ERROR;
245 }
246
247 return NGX_OK;
248 }
249
250
185 static int ngx_epoll_add_connection(ngx_connection_t *c) 251 static int ngx_epoll_add_connection(ngx_connection_t *c)
186 { 252 {
187 struct epoll_event ev; 253 struct epoll_event ev;
188 254
189 ev.events = EPOLLIN|EPOLLOUT; 255 ev.events = EPOLLIN|EPOLLOUT;
192 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 258 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
193 "epoll add connection: fd:%d ev:%04X", c->fd, ev.events); 259 "epoll add connection: fd:%d ev:%04X", c->fd, ev.events);
194 260
195 if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ev) == -1) { 261 if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ev) == -1) {
196 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, 262 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
197 "epoll_ctl(#%d) failed", c->fd); 263 "epoll_ctl(EPOLL_CTL_ADD, %d) failed", c->fd);
198 return NGX_ERROR; 264 return NGX_ERROR;
199 } 265 }
266
267 c->read->active = 1;
268 c->write->active = 1;
200 269
201 return NGX_OK; 270 return NGX_OK;
202 } 271 }
203 272
204 273
304 373
305 c->write->ready = 1; 374 c->write->ready = 1;
306 c->write->event_handler(c->write); 375 c->write->event_handler(c->write);
307 } 376 }
308 377
309 if (event_list[i].events & (EPOLLERR|EPOLLHUP|EPOLLMSG)) { 378 if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
310 ngx_log_error(NGX_LOG_ERR, log, 0, 379 ngx_log_error(NGX_LOG_ALERT, log, 0,
311 "epoll_wait() error on fd:%d ev:%d", 380 "epoll_wait() error on fd:%d ev:%d",
312 c->fd, event_list[i].events); 381 c->fd, event_list[i].events);
313 } 382 continue;
383 }
384
385 if (event_list[i].events & ~(EPOLLIN|EPOLLOUT)) {
386 ngx_log_error(NGX_LOG_ALERT, log, 0,
387 "epoll_wait() returned strange events on fd:%d ev:%d",
388 c->fd, event_list[i].events);
389 }
390
314 } 391 }
315 392
316 if (timer != (ngx_msec_t) -1 && delta) { 393 if (timer != (ngx_msec_t) -1 && delta) {
317 ngx_event_expire_timers((ngx_msec_t) delta); 394 ngx_event_expire_timers((ngx_msec_t) delta);
318 } 395 }