/* deliver the actual channel events to the user now without any channel locking */
ftdm_span_trigger_signals(span);
-#ifndef WIN32
+
/* figure out what event to poll each channel for. POLLPRI when the channel is down,
* POLLPRI|POLLIN|POLLOUT otherwise */
memset(poll_events, 0, sizeof(short)*span->chan_count);
for (i = 0; citer; citer = ftdm_iterator_next(citer), i++) {
ftdmchan = ftdm_iterator_current(citer);
r2chan = R2CALL(ftdmchan)->r2chan;
- poll_events[i] = POLLPRI;
+ poll_events[i] = FTDM_EVENTS;
if (openr2_chan_get_read_enabled(r2chan)) {
- poll_events[i] |= POLLIN;
+ poll_events[i] |= FTDM_READ;
}
}
-
status = ftdm_span_poll_event(span, waitms, poll_events);
-#else
- status = ftdm_span_poll_event(span, waitms, NULL);
-#endif
/* run any span timers */
ftdm_sched_run(r2data->sched);
for(i = 1; i <= span->chan_count; i++) {
ftdm_channel_t *ftdmchan = span->channels[i];
+ uint32_t chan_events = 0;
+
+ /* if the user specify which events to poll the channel for, we translate them from ftdm_wait_flag_t
+ * to events that either sangoma_waitfor_many() or poll() understands. if not, we poll for POLLPRI */
+ if (poll_events) {
+ if (poll_events[j] & FTDM_READ) {
+ chan_events = POLLIN;
+ }
+ if (poll_events[j] & FTDM_WRITE) {
+ chan_events |= POLLOUT;
+ }
+ if (poll_events[j] & FTDM_EVENTS) {
+ chan_events |= POLLPRI;
+ }
+ } else {
+ chan_events = POLLPRI;
+ }
+
#ifdef LIBSANGOMA_VERSION
if (!ftdmchan->io_data) {
continue; /* should never happen but happens when shutting down */
}
pfds[j] = ftdmchan->io_data;
- inflags[j] = poll_events ? poll_events[j] : POLLPRI;
+ inflags[j] = chan_events;
#else
memset(&pfds[j], 0, sizeof(pfds[j]));
pfds[j].fd = span->channels[i]->sockfd;
- pfds[j].events = poll_events ? poll_events[j] : POLLPRI;
+ pfds[j].events = chan_events;
#endif
/* The driver probably should be able to do this wink/flash/ringing by itself this is sort of a hack to make it work! */