Mercurial > hg > nginx
annotate src/event/modules/ngx_poll_module.c @ 1510:2abedb6c0f29 stable-0.5
r1404 merge:
auto redirect lost arguments
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 22 Sep 2007 19:10:53 +0000 |
parents | 80112026a9c2 |
children | f69d1aab6a0f |
rev | line source |
---|---|
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
1 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
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 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
4 */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
5 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
563 | 12 static ngx_int_t ngx_poll_init(ngx_cycle_t *cycle, ngx_msec_t timer); |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
13 static void ngx_poll_done(ngx_cycle_t *cycle); |
356
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
14 static ngx_int_t ngx_poll_add_event(ngx_event_t *ev, int event, u_int flags); |
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
15 static ngx_int_t ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags); |
563 | 16 static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, |
17 ngx_uint_t flags); | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
18 static char *ngx_poll_init_conf(ngx_cycle_t *cycle, void *conf); |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
19 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
20 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 static struct pollfd *event_list; |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
179
diff
changeset
|
22 static int nevents; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
24 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
25 static ngx_str_t poll_name = ngx_string("poll"); |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
26 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
27 ngx_event_module_t ngx_poll_module_ctx = { |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
28 &poll_name, |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
29 NULL, /* create configuration */ |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
30 ngx_poll_init_conf, /* init configuration */ |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
32 { |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
33 ngx_poll_add_event, /* add an event */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
34 ngx_poll_del_event, /* delete an event */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
35 ngx_poll_add_event, /* enable an event */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
36 ngx_poll_del_event, /* disable an event */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
37 NULL, /* add an connection */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
38 NULL, /* delete an connection */ |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
39 NULL, /* process the changes */ |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
40 ngx_poll_process_events, /* process the events */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
41 ngx_poll_init, /* init the events */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
42 ngx_poll_done /* done the events */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
43 } |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
44 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
45 }; |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
46 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
47 ngx_module_t ngx_poll_module = { |
509 | 48 NGX_MODULE_V1, |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
49 &ngx_poll_module_ctx, /* module context */ |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
50 NULL, /* module directives */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
51 NGX_EVENT_MODULE, /* module type */ |
541 | 52 NULL, /* init master */ |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
53 NULL, /* init module */ |
541 | 54 NULL, /* init process */ |
55 NULL, /* init thread */ | |
56 NULL, /* exit thread */ | |
57 NULL, /* exit process */ | |
58 NULL, /* exit master */ | |
59 NGX_MODULE_V1_PADDING | |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
60 }; |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
61 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
62 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
63 |
499 | 64 static ngx_int_t |
563 | 65 ngx_poll_init(ngx_cycle_t *cycle, ngx_msec_t timer) |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 { |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
67 struct pollfd *list; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
68 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
69 if (event_list == NULL) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
70 nevents = 0; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
71 } |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
72 |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
313
diff
changeset
|
73 if (ngx_process == NGX_PROCESS_WORKER |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
313
diff
changeset
|
74 || cycle->old_cycle == NULL |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
75 || cycle->old_cycle->connection_n < cycle->connection_n) |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
76 { |
501 | 77 list = ngx_alloc(sizeof(struct pollfd) * cycle->connection_n, |
78 cycle->log); | |
79 if (list == NULL) { | |
80 return NGX_ERROR; | |
81 } | |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
82 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
83 if (event_list) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
84 ngx_memcpy(list, event_list, sizeof(ngx_event_t *) * nevents); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
85 ngx_free(event_list); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
86 } |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
87 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
88 event_list = list; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
89 } |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
91 ngx_io = ngx_os_io; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
92 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
93 ngx_event_actions = ngx_poll_module_ctx.actions; |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
94 |
563 | 95 ngx_event_flags = NGX_USE_LEVEL_EVENT|NGX_USE_FD_EVENT; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 return NGX_OK; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
100 |
499 | 101 static void |
102 ngx_poll_done(ngx_cycle_t *cycle) | |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
103 { |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
104 ngx_free(event_list); |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
105 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
106 event_list = NULL; |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
107 } |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
108 |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
109 |
499 | 110 static ngx_int_t |
111 ngx_poll_add_event(ngx_event_t *ev, int event, u_int flags) | |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 { |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
113 ngx_event_t *e; |
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
114 ngx_connection_t *c; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
116 c = ev->data; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 |
315
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
118 ev->active = 1; |
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
119 |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
120 if (ev->index != NGX_INVALID_INDEX) { |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
121 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
122 "poll event fd:%d ev:%d is already set", c->fd, event); |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
123 return NGX_OK; |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
124 } |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
125 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 if (event == NGX_READ_EVENT) { |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 e = c->write; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 #if (NGX_READ_EVENT != POLLIN) |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 event = POLLIN; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 #endif |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 } else { |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 e = c->read; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 #if (NGX_WRITE_EVENT != POLLOUT) |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 event = POLLOUT; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 #endif |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
139 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
140 "poll add event: fd:%d ev:%d", c->fd, event); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 if (e == NULL || e->index == NGX_INVALID_INDEX) { |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 event_list[nevents].fd = c->fd; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 event_list[nevents].events = event; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 event_list[nevents].revents = 0; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 ev->index = nevents; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 nevents++; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 } else { |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
151 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
152 "poll add index: %d", e->index); |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
153 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 event_list[e->index].events |= event; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 ev->index = e->index; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 return NGX_OK; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
161 |
499 | 162 static ngx_int_t |
163 ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags) | |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 { |
563 | 165 ngx_event_t *e; |
166 ngx_connection_t *c; | |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
168 c = ev->data; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
170 ev->active = 0; |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
171 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
172 if (ev->index == NGX_INVALID_INDEX) { |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
173 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
174 "poll event fd:%d ev:%d is already deleted", |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
175 c->fd, event); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 return NGX_OK; |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
177 } |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 if (event == NGX_READ_EVENT) { |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 e = c->write; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 #if (NGX_READ_EVENT != POLLIN) |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 event = POLLIN; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 #endif |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 } else { |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 e = c->read; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 #if (NGX_WRITE_EVENT != POLLOUT) |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 event = POLLOUT; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 #endif |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
192 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
193 "poll del event: fd:%d ev:%d", c->fd, event); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 if (e == NULL || e->index == NGX_INVALID_INDEX) { |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
196 nevents--; |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
197 |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
198 if (ev->index < (u_int) nevents) { |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
199 |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
200 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
201 "index: copy event %d to %d", nevents, ev->index); |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
202 |
37
9fe40e51d4a3
nginx-0.0.1-2002-12-23-21:22:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
36
diff
changeset
|
203 event_list[ev->index] = event_list[nevents]; |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
204 |
543 | 205 c = ngx_cycle->files[event_list[nevents].fd]; |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
206 |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
207 if (c->fd == -1) { |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
208 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
209 "unexpected last event"); |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
210 |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
211 } else { |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
212 if (c->read->index == (u_int) nevents) { |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
213 c->read->index = ev->index; |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
214 } |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
215 |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
216 if (c->write->index == (u_int) nevents) { |
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
217 c->write->index = ev->index; |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
218 } |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
219 } |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 } else { |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
223 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
259
d30f2c39caae
nginx-0.0.2-2004-02-12-23:57:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
224 "poll del index: %d", e->index); |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
225 |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 event_list[e->index].events &= ~event; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 ev->index = NGX_INVALID_INDEX; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 return NGX_OK; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
233 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
234 |
499 | 235 static ngx_int_t |
563 | 236 ngx_poll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
237 { |
483 | 238 int ready, revents; |
557 | 239 ngx_err_t err; |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
240 ngx_int_t i, nready; |
563 | 241 ngx_uint_t found, level; |
242 ngx_event_t *ev, **queue; | |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
243 ngx_connection_t *c; |
356
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
244 |
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
245 /* NGX_TIMER_INFINITE == INFTIM */ |
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
246 |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
247 #if (NGX_DEBUG0) |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
248 if (cycle->log->log_level & NGX_LOG_DEBUG_ALL) { |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
249 for (i = 0; i < nevents; i++) { |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
250 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 251 "poll: %d: fd:%d ev:%04Xd", |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
252 i, event_list[i].fd, event_list[i].events); |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
253 } |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
254 } |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
255 #endif |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
256 |
557 | 257 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll timer: %M", timer); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
258 |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
179
diff
changeset
|
259 ready = poll(event_list, (u_int) nevents, (int) timer); |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
260 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
261 if (ready == -1) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
262 err = ngx_errno; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
263 } else { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
264 err = 0; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 |
563 | 267 if (flags & NGX_UPDATE_TIME) { |
268 ngx_time_update(0, 0); | |
269 } | |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
270 |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
271 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
252
diff
changeset
|
272 "poll ready %d of %d", ready, nevents); |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
273 |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
274 if (err) { |
563 | 275 if (err == NGX_EINTR) { |
276 | |
277 if (ngx_event_timer_alarm) { | |
278 ngx_event_timer_alarm = 0; | |
279 return NGX_OK; | |
280 } | |
577 | 281 |
563 | 282 level = NGX_LOG_INFO; |
577 | 283 |
284 } else { | |
563 | 285 level = NGX_LOG_ALERT; |
286 } | |
287 | |
288 ngx_log_error(level, cycle->log, err, "poll() failed"); | |
246
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
289 return NGX_ERROR; |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
290 } |
6753e8cdaa2c
nginx-0.0.1-2004-01-30-20:39:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
291 |
567 | 292 if (ready == 0) { |
293 if (timer != NGX_TIMER_INFINITE) { | |
294 return NGX_OK; | |
295 } | |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
296 |
567 | 297 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
298 "poll() returned no events without timeout"); | |
299 return NGX_ERROR; | |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
300 } |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
301 |
563 | 302 ngx_mutex_lock(ngx_posted_events_mutex); |
303 | |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
304 nready = 0; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
305 |
38
2ffaa35fba42
nginx-0.0.1-2002-12-24-10:09:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
37
diff
changeset
|
306 for (i = 0; i < nevents && ready; i++) { |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
307 |
483 | 308 revents = event_list[i].revents; |
309 | |
563 | 310 #if 1 |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
311 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 312 "poll: %d: fd:%d ev:%04Xd rev:%04Xd", |
483 | 313 i, event_list[i].fd, event_list[i].events, revents); |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
314 #else |
483 | 315 if (revents) { |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
316 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 317 "poll: %d: fd:%d ev:%04Xd rev:%04Xd", |
483 | 318 i, event_list[i].fd, event_list[i].events, revents); |
252
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
319 } |
84b1c672ec5a
nginx-0.0.2-2004-02-05-19:58:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
251
diff
changeset
|
320 #endif |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
321 |
483 | 322 if (revents & POLLNVAL) { |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
323 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
461 | 324 "poll() error fd:%d ev:%04Xd rev:%04Xd", |
483 | 325 event_list[i].fd, event_list[i].events, revents); |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
326 } |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
327 |
483 | 328 if (revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) { |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
329 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
461 | 330 "strange poll() events fd:%d ev:%04Xd rev:%04Xd", |
483 | 331 event_list[i].fd, event_list[i].events, revents); |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
332 } |
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
333 |
251
c31c40540318
nginx-0.0.2-2004-02-04-23:30:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
250
diff
changeset
|
334 if (event_list[i].fd == -1) { |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
335 /* |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
313
diff
changeset
|
336 * the disabled event, a workaround for our possible bug, |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
313
diff
changeset
|
337 * see the comment below |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
338 */ |
251
c31c40540318
nginx-0.0.2-2004-02-04-23:30:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
250
diff
changeset
|
339 continue; |
c31c40540318
nginx-0.0.2-2004-02-04-23:30:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
250
diff
changeset
|
340 } |
c31c40540318
nginx-0.0.2-2004-02-04-23:30:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
250
diff
changeset
|
341 |
543 | 342 c = ngx_cycle->files[event_list[i].fd]; |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
343 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
344 if (c->fd == -1) { |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
345 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unexpected event"); |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
346 |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
347 /* |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
348 * it is certainly our fault and it should be investigated, |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
349 * in the meantime we disable this event to avoid a CPU spinning |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
350 */ |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
351 |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
352 if (i == nevents - 1) { |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
353 nevents--; |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
354 } else { |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
355 event_list[i].fd = -1; |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
356 } |
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
357 |
247
008276b9e061
nginx-0.0.1-2004-02-01-11:10:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
246
diff
changeset
|
358 continue; |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
359 } |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
360 |
483 | 361 if ((revents & (POLLERR|POLLHUP|POLLNVAL)) |
362 && (revents & (POLLIN|POLLOUT)) == 0) | |
363 { | |
364 /* | |
365 * if the error events were returned without POLLIN or POLLOUT, | |
366 * then add these flags to handle the events at least in one | |
367 * active handler | |
368 */ | |
369 | |
370 revents |= POLLIN|POLLOUT; | |
371 } | |
372 | |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
373 found = 0; |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
374 |
483 | 375 if (revents & POLLIN) { |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
376 found = 1; |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
377 |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
378 ev = c->read; |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
379 |
563 | 380 if ((flags & NGX_POST_THREAD_EVENTS) && !ev->accept) { |
381 ev->posted_ready = 1; | |
382 | |
383 } else { | |
384 ev->ready = 1; | |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
385 } |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
386 |
563 | 387 queue = (ngx_event_t **) (ev->accept ? &ngx_posted_accept_events: |
388 &ngx_posted_events); | |
577 | 389 ngx_locked_post_event(ev, queue); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
390 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
391 |
483 | 392 if (revents & POLLOUT) { |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
393 found = 1; |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
394 ev = c->write; |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
395 |
563 | 396 if (flags & NGX_POST_THREAD_EVENTS) { |
397 ev->posted_ready = 1; | |
398 | |
399 } else { | |
400 ev->ready = 1; | |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
401 } |
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
402 |
563 | 403 ngx_locked_post_event(ev, &ngx_posted_events); |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
404 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
405 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
406 if (found) { |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
407 ready--; |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
408 continue; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
409 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
410 } |
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
411 |
563 | 412 ngx_mutex_unlock(ngx_posted_events_mutex); |
313
98f1a8028067
nginx-0.0.3-2004-04-13-19:08:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
413 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
414 if (ready != 0) { |
305
4b1a3a4acc60
nginx-0.0.3-2004-04-02-19:13:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
415 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "poll ready != events"); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
416 } |
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
417 |
261
bdd631bf1a1c
nginx-0.0.2-2004-02-18-00:11:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
259
diff
changeset
|
418 return nready; |
36
c14d7232b11f
nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
419 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
420 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
421 |
499 | 422 static char * |
423 ngx_poll_init_conf(ngx_cycle_t *cycle, void *conf) | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
424 { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
425 ngx_event_conf_t *ecf; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
426 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
427 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
428 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
429 if (ecf->use != ngx_poll_module.ctx_index) { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
430 return NGX_CONF_OK; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
431 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
432 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
433 #if (NGX_THREADS) |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
434 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
435 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
436 "poll() is not supported in the threaded mode"); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
437 return NGX_CONF_ERROR; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
438 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
439 #else |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
440 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
441 return NGX_CONF_OK; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
442 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
443 #endif |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
444 } |