diff options
-rw-r--r-- | include/seq.h | 4 | ||||
-rw-r--r-- | src/seq/seq.c | 38 |
2 files changed, 28 insertions, 14 deletions
diff --git a/include/seq.h b/include/seq.h index f53b5982..d9a1fb29 100644 --- a/include/seq.h +++ b/include/seq.h @@ -324,8 +324,8 @@ extern "C" { int snd_seq_open(snd_seq_t **handle, const char *name, int streams, int mode); int snd_seq_close(snd_seq_t *handle); -int snd_seq_poll_descriptors_count(snd_seq_t *handle); -int snd_seq_poll_descriptors(snd_seq_t *handle, struct pollfd *pfds, unsigned int space); +int snd_seq_poll_descriptors_count(snd_seq_t *handle, short events); +int snd_seq_poll_descriptors(snd_seq_t *handle, struct pollfd *pfds, unsigned int space, short events); int snd_seq_nonblock(snd_seq_t *handle, int nonblock); int snd_seq_client_id(snd_seq_t *handle); int snd_seq_output_buffer_size(snd_seq_t *handle); diff --git a/src/seq/seq.c b/src/seq/seq.c index 94675e04..0ecdff7a 100644 --- a/src/seq/seq.c +++ b/src/seq/seq.c @@ -152,25 +152,39 @@ int _snd_seq_poll_descriptor(snd_seq_t *seq) return seq->poll_fd; } -int snd_seq_poll_descriptors_count(snd_seq_t *seq) +int snd_seq_poll_descriptors_count(snd_seq_t *seq, short events) { + int result = 0; assert(seq); - return 1; + if (events & POLLIN) { + assert(seq->streams & SND_SEQ_OPEN_INPUT); + result++; + } + if (events & POLLOUT) { + assert(seq->streams & SND_SEQ_OPEN_OUTPUT); + result++; + } + return result ? 1 : 0; } -int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int space) +int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int space, short events) { + short revents = 0; + assert(seq); - if (space >= 1) { - pfds->fd = seq->poll_fd; - pfds->events = 0; - if (seq->streams & SND_SEQ_OPEN_INPUT) - pfds->events |= POLLIN; - if (seq->streams & SND_SEQ_OPEN_OUTPUT) - pfds->events |= POLLOUT; - return 1; + if ((events & POLLIN) && space >= 1) { + assert(seq->streams & SND_SEQ_OPEN_INPUT); + revents |= POLLIN; } - return 0; + if ((events & POLLOUT) && space >= 1) { + assert(seq->streams & SND_SEQ_OPEN_INPUT); + revents |= POLLOUT; + } + if (!revents) + return 0; + pfds->fd = seq->poll_fd; + pfds->events = revents; + return 1; } /* |