Changeset 3469:3082508bf5a4 in roaraudio
- Timestamp:
- 02/14/10 01:21:26 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroarpulse/mainloop.c
r3468 r3469 38 38 39 39 #include <libroarpulse/libroarpulse.h> 40 #include <poll.h> 40 41 41 42 #define MAX_IO_EVENTS 8 … … 55 56 pa_poll_func poll_func; 56 57 void * poll_userdata; 58 int poll_timeout; 57 59 int quit; 58 60 int quitval; 59 61 pa_io_event io_event[MAX_IO_EVENTS]; 62 struct pollfd pollfd[MAX_IO_EVENTS]; 63 nfds_t pollfds; 60 64 }; 61 65 … … 153 157 poll, or -1 for blocking behaviour. .*/ 154 158 int pa_mainloop_prepare(pa_mainloop *m, int timeout) { 155 if ( m == NULL ) 156 return -1; 157 158 m->quit = 1; 159 short events; 160 int i; 161 162 if ( m == NULL ) 163 return -1; 159 164 160 165 if ( m->quit ) 161 166 return -2; 162 167 163 return -1; 168 m->pollfds = 0; 169 170 for (i = 0; i < MAX_IO_EVENTS; i++) { 171 if ( m->io_event[i].used ) { 172 events = 0; 173 174 if ( m->io_event[i].events & PA_IO_EVENT_INPUT ) 175 events |= POLLIN; 176 177 if ( m->io_event[i].events & PA_IO_EVENT_OUTPUT ) 178 events |= POLLOUT; 179 180 if ( m->io_event[i].events & PA_IO_EVENT_HANGUP ) 181 events |= POLLHUP; 182 183 if ( m->io_event[i].events & PA_IO_EVENT_ERROR ) 184 events |= POLLERR; 185 186 if ( events == 0 ) 187 continue; 188 189 m->pollfd[m->pollfds].fd = m->io_event[i].fd; 190 m->pollfd[m->pollfds].events = events; 191 m->pollfds++; 192 } 193 } 194 195 m->poll_timeout = timeout; 196 197 return 0; 164 198 } 165 199 166 200 /** Execute the previously prepared poll. Returns a negative value on error.*/ 167 201 int pa_mainloop_poll(pa_mainloop *m) { 202 int ret; 203 168 204 if ( m == NULL ) 169 205 return -1; … … 172 208 return -2; 173 209 174 return -1; 210 if ( m->poll_func != NULL ) { 211 ret = m->poll_func(m->pollfd, m->pollfds, m->poll_timeout, m->poll_userdata); 212 } else { 213 ret = poll(m->pollfd, m->pollfds, m->poll_timeout); 214 } 215 216 return ret; 175 217 } 176 218 … … 178 220 a negative value on error. On success returns the number of source dispatched. */ 179 221 int pa_mainloop_dispatch(pa_mainloop *m) { 222 pa_io_event_flags_t events; 223 int count = 0; 224 225 int i, h; 226 180 227 if ( m == NULL ) 181 228 return -1; … … 184 231 return -2; 185 232 186 return -1; 233 for (i = 0; i < m->pollfds; i++) { 234 if ( m->pollfd[i].revents != 0 ) { 235 for (h = 0; h < MAX_IO_EVENTS; h++) { 236 if ( m->io_event[h].fd == m->pollfd[i].fd ) { 237 events = PA_IO_EVENT_NULL; 238 239 if ( m->pollfd[i].revents & POLLIN ) 240 events |= PA_IO_EVENT_INPUT; 241 242 if ( m->pollfd[i].revents & POLLOUT ) 243 events |= PA_IO_EVENT_OUTPUT; 244 245 if ( m->pollfd[i].revents & POLLHUP ) 246 events |= PA_IO_EVENT_HANGUP; 247 248 if ( m->pollfd[i].revents & POLLERR ) 249 events |= PA_IO_EVENT_ERROR; 250 251 if ( m->io_event[h].cb != NULL ) 252 m->io_event[h].cb(&(m->api), &(m->io_event[h]), m->pollfd[i].fd, events, m->io_event[h].userdata); 253 254 count++; 255 } 256 } 257 } 258 } 259 260 return count; 187 261 } 188 262
Note: See TracChangeset
for help on using the changeset viewer.