+SR_PRIV int sr_session_source_poll_remove(struct sr_session *session,
+ gintptr poll_object, gintptr fd)
+{
+ struct source *source;
+ unsigned int i;
+ int fd_index, k;
+
+ source = NULL;
+ fd_index = 0;
+
+ /* Look up existing event source.
+ */
+ for (i = 0; i < session->sources->len; ++i) {
+ source = &g_array_index(session->sources, struct source, i);
+ if (source->poll_object == poll_object)
+ break;
+ fd_index += source->num_fds;
+ }
+ if (!source) {
+ sr_err("Cannot remove poll FD %" G_GINTPTR_FORMAT
+ " from non-existing event source %" G_GINTPTR_FORMAT
+ ".", fd, poll_object);
+ return SR_ERR;
+ }
+ /* Look up the FD in the poll set.
+ */
+ for (k = 0; k < source->num_fds; ++k)
+ if (g_array_index(session->pollfds, GPollFD, fd_index + k)
+ .fd == fd) {
+
+ g_array_remove_index(session->pollfds, fd_index + k);
+ --source->num_fds;
+
+ sr_dbg("Removed poll FD %" G_GINTPTR_FORMAT
+ " from event source %" G_GINTPTR_FORMAT ".",
+ fd, poll_object);
+ return SR_OK;
+ }
+
+ sr_err("Cannot remove non-existing poll FD %" G_GINTPTR_FORMAT
+ " from event source %" G_GINTPTR_FORMAT ".",
+ fd, poll_object);
+
+ return SR_ERR;
+}
+