2 + D Programming Language "bindings" to libev
3 + <http://software.schmorp.de/pkg/libev.html> test program.
5 + Written by Leandro Lucarella (2008).
7 + Placed under BOLA license <http://auriga.wearlab.de/~alb/bola/> which is
8 + basically public domain.
12 import io = std.stdio;
17 static void stdin_cb(ev_loop_t* loop, ev_io *w, int revents)
19 io.writefln("stdin ready");
20 char[] ln = io.readln();
21 io.writef("read %d bytes: %s", ln.length, ln);
22 ev_io_stop(loop, w); // just a syntax example
23 ev_unloop(loop, EVUNLOOP_ALL); // leave all loop calls
25 static void timeout_cb(ev_loop_t* loop, ev_timer *w, int revents)
27 io.writefln("timeout");
28 ev_unloop(loop, EVUNLOOP_ONE); // leave one loop call
35 ev_timer timeout_watcher;
37 auto loop = ev_default_loop();
39 /* initialise an io watcher, then start it */
40 ev_io_init(&stdin_watcher, &stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
41 ev_io_start(loop, &stdin_watcher);
43 /* simple non-repeating 5.5 second timeout */
44 ev_timer_init(&timeout_watcher, &timeout_cb, 1.5, 0.0);
45 ev_timer_start(loop, &timeout_watcher);
47 /* loop till timeout or data ready */