… | |
… | |
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 | |
|
|
39 | void inline_speed |
|
|
40 | port_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 | |
39 | static void |
58 | static void |
40 | port_modify (EV_P_ int fd, int oev, int nev) |
59 | port_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 | |
66 | static void |
73 | static void |
67 | port_poll (EV_P_ ev_tstamp timeout) |
74 | port_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 | |
111 | static int |
117 | int inline_size |
112 | port_init (EV_P_ int flags) |
118 | port_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 | |
130 | static void |
136 | void inline_size |
131 | port_destroy (EV_P) |
137 | port_destroy (EV_P) |
132 | { |
138 | { |
133 | close (backend_fd); |
|
|
134 | |
|
|
135 | ev_free (port_events); |
139 | ev_free (port_events); |
136 | } |
140 | } |
137 | |
141 | |
138 | static void |
142 | void inline_size |
139 | port_fork (EV_P) |
143 | port_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) |