From: Gareth McMullin Date: Sat, 5 Nov 2011 22:44:25 +0000 (+1300) Subject: Remove IO source if callback returns FALSE. X-Git-Tag: libsigrok-0.1.0~233 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5c582d9f61fa7dad2a5cf07e1f464b6b6ffb1e28;p=libsigrok.git Remove IO source if callback returns FALSE. --- diff --git a/session.c b/session.c index bbcf5bc9..54966637 100644 --- a/session.c +++ b/session.c @@ -145,8 +145,9 @@ static void sr_session_run_poll() * or if the poll timeout out and this source * asked for that timeout. */ - sources[i].cb(fds[i].fd, fds[i].revents, - sources[i].user_data); + if (!sources[i].cb(fds[i].fd, fds[i].revents, + sources[i].user_data)) + sr_session_source_remove(sources[i].fd); } } } @@ -289,7 +290,7 @@ void sr_session_source_remove(int fd) return; new_sources = calloc(1, sizeof(struct source) * num_sources); - for (old = 0; old < num_sources; old++) + for (old = 0, new = 0; old < num_sources; old++) if (sources[old].fd != fd) memcpy(&new_sources[new++], &sources[old], sizeof(struct source));