]> git.llucax.com Git - software/ev.d.git/blob - test.d
Bugfix: explicit cast functions returning bool.
[software/ev.d.git] / test.d
1 /+
2  + D Programming Language "bindings" to libev
3  + <http://software.schmorp.de/pkg/libev.html> test program.
4  +
5  + Written by Leandro Lucarella (2008).
6  +
7  + Placed under BOLA license <http://auriga.wearlab.de/~alb/bola/> which is
8  + basically public domain.
9  +
10  +/
11
12 import io = std.stdio;
13 import ev.c;
14
15 extern (C)
16 {
17         static void stdin_cb(ev_loop_t* loop, ev_io *w, int revents)
18         {
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
24         }
25         static void timeout_cb(ev_loop_t* loop, ev_timer *w, int revents)
26         {
27                 io.writefln("timeout");
28                 ev_unloop(loop, EVUNLOOP_ONE); // leave one loop call
29         }
30 }
31
32 void main()
33 {
34         ev_io    stdin_watcher;
35         ev_timer timeout_watcher;
36
37         auto loop = ev_default_loop();
38
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);
42
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);
46
47         /* loop till timeout or data ready */
48         ev_loop(loop, 0);
49 }
50