comparison src/event/modules/ngx_epoll_module.c @ 258:733dffa1fe97

nginx-0.0.2-2004-02-11-10:19:26 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Feb 2004 07:19:26 +0000
parents 70e1c7d2b83d
children d30f2c39caae
comparison
equal deleted inserted replaced
257:70e1c7d2b83d 258:733dffa1fe97
109 { 109 {
110 ngx_epoll_add_event, /* add an event */ 110 ngx_epoll_add_event, /* add an event */
111 ngx_epoll_del_event, /* delete an event */ 111 ngx_epoll_del_event, /* delete an event */
112 ngx_epoll_add_event, /* enable an event */ 112 ngx_epoll_add_event, /* enable an event */
113 ngx_epoll_del_event, /* disable an event */ 113 ngx_epoll_del_event, /* disable an event */
114 NULL, /* add an connection */ 114 ngx_epoll_add_connection, /* add an connection */
115 NULL, /* delete an connection */ 115 ngx_epoll_del_connection, /* delete an connection */
116 ngx_epoll_process_events, /* process the events */ 116 ngx_epoll_process_events, /* process the events */
117 ngx_epoll_init, /* init the events */ 117 ngx_epoll_init, /* init the events */
118 ngx_epoll_done, /* done the events */ 118 ngx_epoll_done, /* done the events */
119 } 119 }
120 }; 120 };
165 165
166 ngx_io = ngx_os_io; 166 ngx_io = ngx_os_io;
167 167
168 ngx_event_actions = ngx_epoll_module_ctx.actions; 168 ngx_event_actions = ngx_epoll_module_ctx.actions;
169 169
170 #if (HAVE_CLEAR_EVENT) 170 ngx_event_flags = NGX_USE_EDGE_EVENT;
171 ngx_event_flags = NGX_USE_CLEAR_EVENT;
172 #else
173 ngx_event_flags = NGX_USE_LEVEL_EVENT;
174 #endif
175 171
176 return NGX_OK; 172 return NGX_OK;
177 } 173 }
178 174
179 175
193 } 189 }
194 190
195 191
196 static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags) 192 static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags)
197 { 193 {
198 int op, prev; 194 struct epoll_event ee;
199 ngx_event_t *e;
200 ngx_connection_t *c; 195 ngx_connection_t *c;
196
197 c = ev->data;
198
199 #if (NGX_READ_EVENT != EPOLLIN) || (NGX_WRITE_EVENT != EPOLLOUT)
200 if (event == NGX_READ_EVENT) {
201 event = EPOLLIN;
202
203 } else {
204 event = EPOLLOUT;
205 }
206 #endif
207
208 ee.events = event|EPOLLET;
209 ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
210
211 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
212 "epoll add event: fd:%d ev:%08X", c->fd, ee.events);
213
214 if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) {
215 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
216 "epoll_ctl(EPOLL_CTL_MOD, %d) failed", c->fd);
217 return NGX_ERROR;
218 }
219
220 ev->active = 1;
221
222 return NGX_OK;
223 }
224
225
226 static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
227 {
201 struct epoll_event ee; 228 struct epoll_event ee;
229 ngx_connection_t *c;
202 230
203 c = ev->data; 231 c = ev->data;
204 232
205 if (event == NGX_READ_EVENT) { 233 ee.events = 0;
206 e = c->write; 234 ee.data.ptr = NULL;
207 prev = EPOLLOUT; 235
208 #if (NGX_READ_EVENT != EPOLLIN) 236 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
209 event = EPOLLIN; 237 "epoll del event: fd:%d", c->fd);
210 #endif 238
211 239 if (epoll_ctl(ep, EPOLL_CTL_DEL, c->fd, &ee) == -1) {
212 } else { 240 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
213 e = c->read; 241 "epoll_ctl(EPOLL_CTL_MOD, %d) failed", c->fd);
214 prev = EPOLLIN;
215 #if (NGX_WRITE_EVENT != EPOLLOUT)
216 event = EPOLLOUT;
217 #endif
218 }
219
220 if (e->active) {
221 op = EPOLL_CTL_MOD;
222 event |= prev;
223
224 } else {
225 op = EPOLL_CTL_ADD;
226 }
227
228 ee.events = event | flags;
229 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
230
231 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
232 "epoll add event: fd:%d op:%d ev:%08X",
233 c->fd, op, ee.events);
234
235 if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
236 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
237 "epoll_ctl(%d, %d) failed", op, c->fd);
238 return NGX_ERROR; 242 return NGX_ERROR;
239 } 243 }
240 244
241 ev->active = 1;
242 #if 0
243 ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0;
244 #endif
245
246 return NGX_OK;
247 }
248
249
250 static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
251 {
252 int op, prev;
253 ngx_event_t *e;
254 ngx_connection_t *c;
255 struct epoll_event ee;
256
257 /*
258 * when the file descriptor is closed the epoll automatically deletes
259 * it from its queue so we do not need to delete explicity the event
260 * before the closing the file descriptor.
261 */
262
263 if (flags & NGX_CLOSE_EVENT) {
264 ev->active = 0;
265 return NGX_OK;
266 }
267
268 c = ev->data;
269
270 if (event == NGX_READ_EVENT) {
271 e = c->write;
272 prev = EPOLLOUT;
273
274 } else {
275 e = c->read;
276 prev = EPOLLIN;
277 }
278
279 if (e->active) {
280 op = EPOLL_CTL_MOD;
281 ee.events = prev | flags;
282 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
283
284 } else {
285 op = EPOLL_CTL_DEL;
286 ee.events = 0;
287 ee.data.ptr = NULL;
288 }
289
290 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
291 "epoll del event: fd:%d op:%d ev:%08X",
292 c->fd, op, ee.events);
293
294 if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
295 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
296 "epoll_ctl(%d, %d) failed", op, c->fd);
297 return NGX_ERROR;
298 }
299
300 ev->active = 0; 245 ev->active = 0;
301 246
302 return NGX_OK; 247 return NGX_OK;
303 } 248 }
304 249
305 250
306 #if 0
307 static int ngx_epoll_add_connection(ngx_connection_t *c) 251 static int ngx_epoll_add_connection(ngx_connection_t *c)
308 { 252 {
309 struct epoll_event ee; 253 struct epoll_event ee;
310 254
311 ee.events = EPOLLIN|EPOLLOUT|EPOLLET; 255 ee.events = EPOLLIN|EPOLLOUT|EPOLLET;
332 c->read->active = 0; 276 c->read->active = 0;
333 c->write->active = 0; 277 c->write->active = 0;
334 278
335 return NGX_OK; 279 return NGX_OK;
336 } 280 }
337 #endif
338 281
339 282
340 int ngx_epoll_process_events(ngx_log_t *log) 283 int ngx_epoll_process_events(ngx_log_t *log)
341 { 284 {
342 int events; 285 int events;