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.16 by root, Sun Nov 4 18:29:44 2007 UTC vs.
Revision 1.24 by root, Fri Nov 23 05:00:45 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 epoll_ctl (epoll_fd, mode, fd, &ev); 45 if (epoll_ctl (epoll_fd, mode, fd, &ev))
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)))
48 fd_kill (EV_A_ fd);
46} 49}
47 50
48static void 51static void
49epoll_poll (EV_P_ ev_tstamp timeout) 52epoll_poll (EV_P_ ev_tstamp timeout)
50{ 53{
51 int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.));
52 int i; 54 int i;
55 int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.));
53 56
54 if (eventcnt < 0) 57 if (eventcnt < 0)
58 {
59 if (errno != EINTR)
60 syserr ("(libev) epoll_wait");
61
55 return; 62 return;
63 }
56 64
57 for (i = 0; i < eventcnt; ++i) 65 for (i = 0; i < eventcnt; ++i)
58 fd_event ( 66 fd_event (
59 EV_A_ 67 EV_A_
60 epoll_events [i].data.u64, 68 epoll_events [i].data.u64,
63 ); 71 );
64 72
65 /* if the receive array was full, increase its size */ 73 /* if the receive array was full, increase its size */
66 if (expect_false (eventcnt == epoll_eventmax)) 74 if (expect_false (eventcnt == epoll_eventmax))
67 { 75 {
68 free (epoll_events); 76 ev_free (epoll_events);
69 epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1); 77 epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1);
70 epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); 78 epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
71 } 79 }
72} 80}
73 81
74static int 82static int
75epoll_init (EV_P_ int flags) 83epoll_init (EV_P_ int flags)
84 method_fudge = 1e-3; /* needed to compensate for epoll returning early */ 92 method_fudge = 1e-3; /* needed to compensate for epoll returning early */
85 method_modify = epoll_modify; 93 method_modify = epoll_modify;
86 method_poll = epoll_poll; 94 method_poll = epoll_poll;
87 95
88 epoll_eventmax = 64; /* intiial number of events receivable per poll */ 96 epoll_eventmax = 64; /* intiial number of events receivable per poll */
89 epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); 97 epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
90 98
91 return EVMETHOD_EPOLL; 99 return EVBACKEND_EPOLL;
92} 100}
93 101
94static void 102static void
95epoll_destroy (EV_P) 103epoll_destroy (EV_P)
96{ 104{
97 close (epoll_fd); 105 close (epoll_fd);
98 106
99 free (epoll_events); 107 ev_free (epoll_events);
100} 108}
101 109
102static void 110static void
103epoll_fork (EV_P) 111epoll_fork (EV_P)
104{ 112{
113 close (epoll_fd);
114
105 epoll_fd = epoll_create (256); 115 while ((epoll_fd = epoll_create (256)) < 0)
116 syserr ("(libev) epoll_create");
117
106 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC); 118 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC);
107 119
108 fd_rearm_all (EV_A); 120 fd_rearm_all (EV_A);
109} 121}
110 122

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines