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.25 by root, Fri Nov 23 05:13:49 2007 UTC vs.
Revision 1.26 by root, Fri Nov 23 19:13:33 2007 UTC

40 ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */ 40 ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */
41 ev.events = 41 ev.events =
42 (nev & EV_READ ? EPOLLIN : 0) 42 (nev & EV_READ ? EPOLLIN : 0)
43 | (nev & EV_WRITE ? EPOLLOUT : 0); 43 | (nev & EV_WRITE ? EPOLLOUT : 0);
44 44
45 if (epoll_ctl (epoll_fd, mode, fd, &ev)) 45 if (epoll_ctl (backend_fd, mode, fd, &ev))
46 if (errno != ENOENT /* on ENOENT the fd went away, so try to do the right thing */ 46 if (errno != ENOENT /* on ENOENT the fd went away, so try to do the right thing */
47 || (nev && epoll_ctl (epoll_fd, EPOLL_CTL_ADD, fd, &ev))) 47 || (nev && epoll_ctl (backend_fd, EPOLL_CTL_ADD, fd, &ev)))
48 fd_kill (EV_A_ fd); 48 fd_kill (EV_A_ fd);
49} 49}
50 50
51static void 51static void
52epoll_poll (EV_P_ ev_tstamp timeout) 52epoll_poll (EV_P_ ev_tstamp timeout)
53{ 53{
54 int i; 54 int i;
55 int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); 55 int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.));
56 56
57 if (eventcnt < 0) 57 if (eventcnt < 0)
58 { 58 {
59 if (errno != EINTR) 59 if (errno != EINTR)
60 syserr ("(libev) epoll_wait"); 60 syserr ("(libev) epoll_wait");
80} 80}
81 81
82static int 82static int
83epoll_init (EV_P_ int flags) 83epoll_init (EV_P_ int flags)
84{ 84{
85 epoll_fd = epoll_create (256); 85 backend_fd = epoll_create (256);
86 86
87 if (epoll_fd < 0) 87 if (backend_fd < 0)
88 return 0; 88 return 0;
89 89
90 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC); 90 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
91 91
92 backend_fudge = 1e-3; /* needed to compensate for epoll returning early */ 92 backend_fudge = 1e-3; /* needed to compensate for epoll returning early */
93 backend_modify = epoll_modify; 93 backend_modify = epoll_modify;
94 backend_poll = epoll_poll; 94 backend_poll = epoll_poll;
95 95
100} 100}
101 101
102static void 102static void
103epoll_destroy (EV_P) 103epoll_destroy (EV_P)
104{ 104{
105 close (epoll_fd); 105 close (backend_fd);
106 106
107 ev_free (epoll_events); 107 ev_free (epoll_events);
108} 108}
109 109
110static void 110static void
111epoll_fork (EV_P) 111epoll_fork (EV_P)
112{ 112{
113 close (epoll_fd); 113 close (backend_fd);
114 114
115 while ((epoll_fd = epoll_create (256)) < 0) 115 while ((backend_fd = epoll_create (256)) < 0)
116 syserr ("(libev) epoll_create"); 116 syserr ("(libev) epoll_create");
117 117
118 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC); 118 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
119 119
120 fd_rearm_all (EV_A); 120 fd_rearm_all (EV_A);
121} 121}
122 122

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines