… | |
… | |
40 | #endif |
40 | #endif |
41 | |
41 | |
42 | #include <string.h> |
42 | #include <string.h> |
43 | #include <inttypes.h> |
43 | #include <inttypes.h> |
44 | |
44 | |
45 | static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo; |
|
|
46 | static int vec_max; |
|
|
47 | |
|
|
48 | static void |
45 | static void |
49 | select_modify (int fd, int oev, int nev) |
46 | select_modify (EV_P_ int fd, int oev, int nev) |
50 | { |
47 | { |
51 | int offs = fd >> 3; |
48 | int offs = fd >> 3; |
52 | int mask = 1 << (fd & 7); |
49 | int mask = 1 << (fd & 7); |
|
|
50 | |
|
|
51 | if (oev == nev) |
|
|
52 | return; |
53 | |
53 | |
54 | if (vec_max < (fd >> 5) + 1) |
54 | if (vec_max < (fd >> 5) + 1) |
55 | { |
55 | { |
56 | int new_max = (fd >> 5) + 1; |
56 | int new_max = (fd >> 5) + 1; |
57 | |
57 | |
… | |
… | |
73 | if (!(nev & EV_WRITE)) |
73 | if (!(nev & EV_WRITE)) |
74 | vec_wi [offs] &= ~mask; |
74 | vec_wi [offs] &= ~mask; |
75 | } |
75 | } |
76 | |
76 | |
77 | static void |
77 | static void |
78 | select_poll (ev_tstamp timeout) |
78 | select_poll (EV_P_ ev_tstamp timeout) |
79 | { |
79 | { |
80 | struct timeval tv; |
80 | struct timeval tv; |
81 | int res; |
81 | int res; |
82 | |
82 | |
83 | memcpy (vec_ro, vec_ri, vec_max * 4); |
83 | memcpy (vec_ro, vec_ri, vec_max * 4); |
… | |
… | |
108 | int events = 0; |
108 | int events = 0; |
109 | events |= byte_r & (1 << bit) ? EV_READ : 0; |
109 | events |= byte_r & (1 << bit) ? EV_READ : 0; |
110 | events |= byte_w & (1 << bit) ? EV_WRITE : 0; |
110 | events |= byte_w & (1 << bit) ? EV_WRITE : 0; |
111 | |
111 | |
112 | if (events) |
112 | if (events) |
113 | fd_event (idx * 8 + bit, events); |
113 | fd_event (EV_A_ idx * 8 + bit, events); |
114 | } |
114 | } |
115 | } |
115 | } |
116 | } |
116 | } |
117 | } |
117 | } |
118 | else if (res < 0) |
118 | else if (res < 0) |
119 | { |
119 | { |
120 | if (errno == EBADF) |
120 | if (errno == EBADF) |
121 | fd_ebadf (); |
121 | fd_ebadf (EV_A); |
122 | else if (errno == ENOMEM) |
122 | else if (errno == ENOMEM) |
123 | fd_enomem (); |
123 | fd_enomem (EV_A); |
124 | } |
124 | } |
125 | } |
125 | } |
126 | |
126 | |
127 | static void |
127 | static int |
128 | select_init (int flags) |
128 | select_init (EV_P_ int flags) |
129 | { |
129 | { |
130 | ev_method = EVMETHOD_SELECT; |
|
|
131 | method_fudge = 1e-2; /* needed to compensate for select returning early, very conservative */ |
130 | method_fudge = 1e-2; /* needed to compensate for select returning early, very conservative */ |
132 | method_modify = select_modify; |
131 | method_modify = select_modify; |
133 | method_poll = select_poll; |
132 | method_poll = select_poll; |
|
|
133 | |
|
|
134 | vec_max = 0; |
|
|
135 | vec_ri = 0; |
|
|
136 | vec_ri = 0; |
|
|
137 | vec_wo = 0; |
|
|
138 | vec_wo = 0; |
|
|
139 | |
|
|
140 | return EVMETHOD_SELECT; |
134 | } |
141 | } |
135 | |
142 | |
|
|
143 | static void |
|
|
144 | select_destroy (EV_P) |
|
|
145 | { |
|
|
146 | free (vec_ri); |
|
|
147 | free (vec_ro); |
|
|
148 | free (vec_wi); |
|
|
149 | free (vec_wo); |
|
|
150 | } |
|
|
151 | |
|
|
152 | |