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

Comparing libev/ev_port.c (file contents):
Revision 1.6 by root, Mon Nov 26 08:06:15 2007 UTC vs.
Revision 1.9 by root, Fri Dec 14 18:04:31 2007 UTC

34#include <poll.h> 34#include <poll.h>
35#include <port.h> 35#include <port.h>
36#include <string.h> 36#include <string.h>
37#include <errno.h> 37#include <errno.h>
38 38
39void inline_speed
40port_associate_and_check (EV_P_ int fd, int ev)
41{
42 if (0 >
43 port_associate (
44 backend_fd, PORT_SOURCE_FD, fd,
45 (ev & EV_READ ? POLLIN : 0)
46 | (ev & EV_WRITE ? POLLOUT : 0),
47 0
48 )
49 )
50 {
51 if (errno == EBADFD)
52 fd_kill (EV_A_ fd);
53 else
54 syserr ("(libev) port_associate");
55 }
56}
57
39static void 58static void
40port_modify (EV_P_ int fd, int oev, int nev) 59port_modify (EV_P_ int fd, int oev, int nev)
41{ 60{
42 /* we need to reassociate no matter what, as closes are 61 /* we need to reassociate no matter what, as closes are
43 * once more silently being discarded. 62 * once more silently being discarded.
45 if (!nev) 64 if (!nev)
46 { 65 {
47 if (oev) 66 if (oev)
48 port_dissociate (backend_fd, PORT_SOURCE_FD, fd); 67 port_dissociate (backend_fd, PORT_SOURCE_FD, fd);
49 } 68 }
50 else if (0 >
51 port_associate (
52 backend_fd, PORT_SOURCE_FD, fd,
53 (nev & EV_READ ? POLLIN : 0)
54 | (nev & EV_WRITE ? POLLOUT : 0),
55 0
56 )
57 )
58 {
59 if (errno == EBADFD)
60 fd_kill (EV_A_ fd);
61 else 69 else
62 syserr ("(libev) port_associate"); 70 port_associate_and_check (EV_A_ fd, nev);
63 }
64} 71}
65 72
66static void 73static void
67port_poll (EV_P_ ev_tstamp timeout) 74port_poll (EV_P_ ev_tstamp timeout)
68{ 75{
93 fd, 100 fd,
94 (port_events [i].portev_events & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) 101 (port_events [i].portev_events & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
95 | (port_events [i].portev_events & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) 102 | (port_events [i].portev_events & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
96 ); 103 );
97 104
98 anfds [fd].events = 0; /* event received == disassociated */ 105 port_associate_and_check (EV_A_ fd, anfds [fd].events);
99 fd_change (EV_A_ fd); /* need to reify later */
100 } 106 }
101 } 107 }
102 108
103 if (expect_false (nget == port_eventmax)) 109 if (expect_false (nget == port_eventmax))
104 { 110 {
105 ev_free (port_events); 111 ev_free (port_events);
106 port_eventmax = array_roundsize (port_event_t, port_eventmax << 1); 112 port_eventmax = array_nextsize (sizeof (port_event_t), port_eventmax, port_eventmax + 1);
107 port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax); 113 port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
108 } 114 }
109} 115}
110 116
111static int 117int inline_size
112port_init (EV_P_ int flags) 118port_init (EV_P_ int flags)
113{ 119{
114 /* Initalize the kernel queue */ 120 /* Initalize the kernel queue */
115 if ((backend_fd = port_create ()) < 0) 121 if ((backend_fd = port_create ()) < 0)
116 return 0; 122 return 0;
125 port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax); 131 port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
126 132
127 return EVBACKEND_PORT; 133 return EVBACKEND_PORT;
128} 134}
129 135
130static void 136void inline_size
131port_destroy (EV_P) 137port_destroy (EV_P)
132{ 138{
133 close (backend_fd);
134
135 ev_free (port_events); 139 ev_free (port_events);
136} 140}
137 141
138static void 142void inline_size
139port_fork (EV_P) 143port_fork (EV_P)
140{ 144{
141 close (backend_fd); 145 close (backend_fd);
142 146
143 while ((backend_fd = port_create ()) < 0) 147 while ((backend_fd = port_create ()) < 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines