+
+void iochan_handler(struct iochan *i, int event)
+{
+ static int number = 0;
+ sel_thread_t p = iochan_getdata(i);
+
+ if (event & EVENT_INPUT)
+ {
+ struct my_work_data *work;
+
+ work = sel_thread_result(p);
+
+ YAZ_CHECK(work);
+ if (work)
+ {
+ YAZ_CHECK_EQ(work->x * 2, work->y);
+ /* stop work after a couple of iterations */
+ if (work->x > 10)
+ iochan_destroy(i);
+
+ xfree(work);
+ }
+
+ }
+ if (event & EVENT_TIMEOUT)
+ {
+ struct my_work_data *work;
+
+ work = xmalloc(sizeof(*work));
+ work->x = number;
+ sel_thread_add(p, work);
+
+ work = xmalloc(sizeof(*work));
+ work->x = number+1;
+ sel_thread_add(p, work);
+
+ number += 10;
+ }
+}
+
+/** brief use the fd for something */
+static void test_for_real_work(int no_threads)
+{
+ int thread_fd;
+ sel_thread_t p = sel_thread_create(work_handler, work_destroy,
+ &thread_fd, no_threads);
+ YAZ_CHECK(p);
+ if (p)
+ {
+ iochan_man_t chan_man = iochan_man_create(10);
+ IOCHAN chan = iochan_create(thread_fd, iochan_handler,
+ EVENT_INPUT|EVENT_TIMEOUT, "test_chan");
+ iochan_settimeout(chan, 1);
+ iochan_setdata(chan, p);
+ iochan_add(chan_man, chan);
+
+ iochan_man_events(chan_man);
+ sel_thread_destroy(p);
+ iochan_man_destroy(&chan_man);
+ }
+}
+