ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_epoll.c
(Generate patch)

Comparing libev/ev_epoll.c (file contents):
Revision 1.42 by root, Wed Oct 29 10:24:23 2008 UTC vs.
Revision 1.49 by root, Tue Nov 24 06:37:23 2009 UTC

1/* 1/*
2 * libev epoll fd activity backend 2 * libev epoll fd activity backend
3 * 3 *
4 * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
68 /* 68 /*
69 * we handle EPOLL_CTL_DEL by ignoring it here 69 * we handle EPOLL_CTL_DEL by ignoring it here
70 * on the assumption that the fd is gone anyways 70 * on the assumption that the fd is gone anyways
71 * if that is wrong, we have to handle the spurious 71 * if that is wrong, we have to handle the spurious
72 * event in epoll_poll. 72 * event in epoll_poll.
73 * the fd is later added, we try to ADD it, and, if that 73 * if the fd is added again, we try to ADD it, and, if that
74 * fails, we assume it still has the same eventmask. 74 * fails, we assume it still has the same eventmask.
75 */ 75 */
76 if (!nev) 76 if (!nev)
77 return; 77 return;
78 78
117 117
118static void 118static void
119epoll_poll (EV_P_ ev_tstamp timeout) 119epoll_poll (EV_P_ ev_tstamp timeout)
120{ 120{
121 int i; 121 int i;
122 int eventcnt;
123
124 /* epoll wait times cannot be larger than (LONG_MAX - 999UL) / HZ msecs, which is below */
125 /* the default libev max wait time, however. */
126 EV_RELEASE_CB;
122 int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); 127 eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.));
128 EV_ACQUIRE_CB;
123 129
124 if (expect_false (eventcnt < 0)) 130 if (expect_false (eventcnt < 0))
125 { 131 {
126 if (errno != EINTR) 132 if (errno != EINTR)
127 ev_syserr ("(libev) epoll_wait"); 133 ev_syserr ("(libev) epoll_wait");
153 /* we received an event but are not interested in it, try mod or del */ 159 /* we received an event but are not interested in it, try mod or del */
154 /* I don't think we ever need MOD, but let's handle it anyways */ 160 /* I don't think we ever need MOD, but let's handle it anyways */
155 ev->events = (want & EV_READ ? EPOLLIN : 0) 161 ev->events = (want & EV_READ ? EPOLLIN : 0)
156 | (want & EV_WRITE ? EPOLLOUT : 0); 162 | (want & EV_WRITE ? EPOLLOUT : 0);
157 163
164 /* pre-2.6.9 kernels require a non-null pointer with EPOLL_CTL_DEL, */
165 /* which is fortunately easy to do for us. */
158 if (epoll_ctl (backend_fd, want ? EPOLL_CTL_MOD : EPOLL_CTL_DEL, fd, ev)) 166 if (epoll_ctl (backend_fd, want ? EPOLL_CTL_MOD : EPOLL_CTL_DEL, fd, ev))
159 { 167 {
160 postfork = 1; /* an error occured, recreate kernel state */ 168 postfork = 1; /* an error occured, recreate kernel state */
161 continue; 169 continue;
162 } 170 }
175} 183}
176 184
177int inline_size 185int inline_size
178epoll_init (EV_P_ int flags) 186epoll_init (EV_P_ int flags)
179{ 187{
188#ifdef EPOLL_CLOEXEC
189 backend_fd = epoll_create1 (EPOLL_CLOEXEC);
190
191 if (backend_fd <= 0)
192#endif
180 backend_fd = epoll_create (256); 193 backend_fd = epoll_create (256);
181 194
182 if (backend_fd < 0) 195 if (backend_fd < 0)
183 return 0; 196 return 0;
184 197
185 fcntl (backend_fd, F_SETFD, FD_CLOEXEC); 198 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines