From 3201a1ddb17ddac985fd06800628b0b54fc0a692 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 10 Oct 2015 17:49:17 +0200 Subject: improved poll() handling --- apps/dolmetschctl.c | 9 +++------ apps/midi.c | 4 ++-- apps/osc.c | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c index b8f9197..9e3b3d5 100644 --- a/apps/dolmetschctl.c +++ b/apps/dolmetschctl.c @@ -65,15 +65,12 @@ int main_loop(osc_t* o, midi_t* m) printf("main_loop running...\n"); for (;;) { int err = poll(pfds, npfds, 200); - if(err < 0) { - if(errno == EINTR) - continue; - + if(err < 0 || errno != EINTR) { error(0, errno, "poll failed"); break; } - if(err == 0) { - // timeout is reached + if(err <= 0) { + // timeout or EINTR continue; } diff --git a/apps/midi.c b/apps/midi.c index 821f353..77a6de6 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -61,8 +61,8 @@ int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds) error(0, 0, "MIDI: cannot get poll events: %s", snd_strerror(errno)); return -1; } - if(revents & (POLLERR | POLLHUP)) { - error(0, 0, "MIDI: got POLLERR or POLLHUP"); + if(pfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { + error(0, 0, "MIDI: got POLLERR, POLLHUP or POLLNVAL"); return -1; } if(!(revents & POLLIN)) diff --git a/apps/osc.c b/apps/osc.c index 0291af3..887684d 100644 --- a/apps/osc.c +++ b/apps/osc.c @@ -85,8 +85,8 @@ int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds) { assert(npfds == 1); - if(pfds[0].revents & (POLLERR | POLLHUP)) { - error(0, 0, "OSC: got POLLERR or POLLHUP"); + if(pfds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { + error(0, 0, "OSC: got POLLERR, POLLHUP or POLLNVAL"); return -1; } if(!(pfds[0].revents & POLLIN)) -- cgit v1.2.3