+void session_run(void)
+{
+ GPollFD *fds, my_gpollfd;
+ int ret, i;
+
+ g_message("running session");
+ session->running = TRUE;
+ fds = NULL;
+ while (session->running) {
+ if (fds)
+ free(fds);
+
+ /* Construct g_poll()'s array. */
+ fds = malloc(sizeof(GPollFD) * num_sources);
+ for (i = 0; i < num_sources; i++) {
+#ifdef _WIN32
+ g_io_channel_win32_make_pollfd(&channels[0],
+ sources[i].events, &my_gpollfd);
+#else
+ my_gpollfd.fd = sources[i].fd;
+ my_gpollfd.events = sources[i].events;
+ fds[i] = my_gpollfd;
+#endif
+ }
+
+ ret = g_poll(fds, num_sources, source_timeout);
+
+ for (i = 0; i < num_sources; i++) {
+ if (fds[i].revents > 0 || (ret == 0
+ && source_timeout == sources[i].timeout)) {
+ /*
+ * Invoke the source's callback on an event,
+ * 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);
+ }
+ }
+ }
+ free(fds);
+
+}
+
+void session_halt(void)
+{
+
+ g_message("halting session");
+ session->running = FALSE;
+
+}
+