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.18 by root, Sun Nov 4 22:03:17 2007 UTC vs.
Revision 1.20 by root, Tue Nov 6 00:10:04 2007 UTC

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 (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)))
46 fd_kill (EV_A_ fd); 48 fd_kill (EV_A_ fd);
47} 49}
48 50
49static void 51static void
50epoll_poll (EV_P_ ev_tstamp timeout) 52epoll_poll (EV_P_ ev_tstamp timeout)
51{ 53{
54 int i;
52 int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.)); 55 int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.));
53 int i;
54 56
55 if (eventcnt < 0) 57 if (eventcnt < 0)
58 {
59 if (errno != EINTR)
60 syserr ();
61
56 return; 62 return;
63 }
57 64
58 for (i = 0; i < eventcnt; ++i) 65 for (i = 0; i < eventcnt; ++i)
59 fd_event ( 66 fd_event (
60 EV_A_ 67 EV_A_
61 epoll_events [i].data.u64, 68 epoll_events [i].data.u64,
64 ); 71 );
65 72
66 /* if the receive array was full, increase its size */ 73 /* if the receive array was full, increase its size */
67 if (expect_false (eventcnt == epoll_eventmax)) 74 if (expect_false (eventcnt == epoll_eventmax))
68 { 75 {
69 free (epoll_events); 76 ev_free (epoll_events);
70 epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1); 77 epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1);
71 epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); 78 epoll_events = ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
72 } 79 }
73} 80}
74 81
75static int 82static int
76epoll_init (EV_P_ int flags) 83epoll_init (EV_P_ int flags)
85 method_fudge = 1e-3; /* needed to compensate for epoll returning early */ 92 method_fudge = 1e-3; /* needed to compensate for epoll returning early */
86 method_modify = epoll_modify; 93 method_modify = epoll_modify;
87 method_poll = epoll_poll; 94 method_poll = epoll_poll;
88 95
89 epoll_eventmax = 64; /* intiial number of events receivable per poll */ 96 epoll_eventmax = 64; /* intiial number of events receivable per poll */
90 epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); 97 epoll_events = ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
91 98
92 return EVMETHOD_EPOLL; 99 return EVMETHOD_EPOLL;
93} 100}
94 101
95static void 102static void
96epoll_destroy (EV_P) 103epoll_destroy (EV_P)
97{ 104{
98 close (epoll_fd); 105 close (epoll_fd);
99 106
100 free (epoll_events); 107 ev_free (epoll_events);
101} 108}
102 109
103static void 110static void
104epoll_fork (EV_P) 111epoll_fork (EV_P)
105{ 112{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines