]> sigrok.org Git - libsigrok.git/blobdiff - session.c
datastore.c: Improve error handling and docs.
[libsigrok.git] / 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));