+ s->cb = cb;
+ s->cb_data = cb_data;
+ s->poll_object = poll_object;
+ session->pollfds = new_pollfds;
+ session->sources = new_sources;
+
+ if (timeout != session->source_timeout && timeout > 0
+ && (session->source_timeout == -1 || timeout < session->source_timeout))
+ session->source_timeout = timeout;
+
+ return SR_OK;
+}
+
+/**
+ * Add an event source for a file descriptor.
+ *
+ * @param fd The file descriptor.
+ * @param events Events to check for.
+ * @param timeout Max time to wait before the callback is called, ignored if 0.
+ * @param cb Callback function to add. Must not be NULL.
+ * @param cb_data Data for the callback function. Can be NULL.
+ *
+ * @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid argument.
+ * @retval SR_ERR_MALLOC Memory allocation error.
+ *
+ * @since 0.3.0
+ */
+SR_API int sr_session_source_add(struct sr_session *session, int fd,
+ int events, int timeout, sr_receive_data_callback cb, void *cb_data)
+{
+ GPollFD p;
+
+ (void) session;
+
+ p.fd = fd;
+ p.events = events;
+
+ return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)fd);
+}
+
+/**
+ * Add an event source for a GPollFD.
+ *
+ * @param pollfd The GPollFD.
+ * @param timeout Max time to wait before the callback is called, ignored if 0.
+ * @param cb Callback function to add. Must not be NULL.
+ * @param cb_data Data for the callback function. Can be NULL.
+ *
+ * @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid argument.
+ * @retval SR_ERR_MALLOC Memory allocation error.
+ *
+ * @since 0.3.0
+ */
+SR_API int sr_session_source_add_pollfd(struct sr_session *session,
+ GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
+ void *cb_data)
+{
+ (void) session;
+
+ return _sr_session_source_add(session, pollfd, timeout, cb,
+ cb_data, (gintptr)pollfd);
+}
+
+/**
+ * Add an event source for a GIOChannel.
+ *
+ * @param channel The GIOChannel.
+ * @param events Events to poll on.
+ * @param timeout Max time to wait before the callback is called, ignored if 0.
+ * @param cb Callback function to add. Must not be NULL.
+ * @param cb_data Data for the callback function. Can be NULL.
+ *
+ * @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid argument.
+ * @retval SR_ERR_MALLOC Memory allocation error.
+ *
+ * @since 0.3.0
+ */
+SR_API int sr_session_source_add_channel(struct sr_session *session,
+ GIOChannel *channel, int events, int timeout,
+ sr_receive_data_callback cb, void *cb_data)
+{
+ GPollFD p;