1 ! Copyright (C) 2011 Anton Gorenko.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types classes.struct continuations glib.ffi
4 io.backend.unix.multiplexers io.thread kernel libc literals locals
8 : prepare ( source timeout -- ? )
11 : check ( source -- ? )
12 poll_fds>> 0 g_slist_nth_data GPollFD memory>struct
15 : dispatch ( source callback user-data -- ? )
17 0 mx get-global wait-for-events
20 : <funcs> ( -- funcs )
21 GSourceFuncs malloc-struct
22 [ prepare ] GSourceFuncsPrepareFunc >>prepare
23 [ check ] GSourceFuncsCheckFunc >>check
24 [ dispatch ] GSourceFuncsDispatchFunc >>dispatch ;
26 CONSTANT: poll-fd-events
36 : <poll-fd> ( -- poll-fd )
37 GPollFD malloc-struct &free
38 mx get-global fd>> >>fd
39 poll-fd-events >>events ;
41 :: with-event-loop ( quot -- )
44 GSource heap-size g_source_new &g_source_unref :> source
45 source <poll-fd> g_source_add_poll
46 source f g_source_attach drop
49 source g_source_destroy