]> sigrok.org Git - libsigrok.git/commitdiff
Remove IO source if callback returns FALSE.
authorGareth McMullin <redacted>
Sat, 5 Nov 2011 22:44:25 +0000 (11:44 +1300)
committerGareth McMullin <redacted>
Sat, 5 Nov 2011 22:44:25 +0000 (11:44 +1300)
session.c

index bbcf5bc923172328f5b7be322f7172c3304861aa..549666375ad5923e5889de906740f10ce7880daa 100644 (file)
--- 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));