ev.d is both a low and high level libev bindings for the D Programming Language .
All modules are placed in the ev
package.
Note
libev should be compiled with EV_MULTIPLICITY=1
to work with ev.d.
ev.c
)¶The low level bindings directly expose the C API, without any specific D magic. You can almost port a simple C libev example changing a few lines of code, for example:
import ev.c;
// ....
void main()
{
ev_io stdin_watcher;
auto loop = ev_default_loop();
/* initialise an io watcher, then start it */
ev_io_init(&stdin_watcher, &stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
ev_io_start(loop, &stdin_watcher);
/* loop till timeout or data ready */
ev_loop(loop, 0);
}
For a complete example see ctest.d.
ev.d
)¶The high level API adds some D sugar on top of the low level API, providing a more D-ish experience.
You can use delegates to handle events and is a little more object oriented.
Here is a very simple example:
import std.stdio;
import ev.d;
void main()
{
(new Timer(5.5,
(Timer w, int revents)
{
writefln("timeout, revents = ", revents);
w.loop.unloop(Unloop.ONE); // example syntax
}
)).start;
loop.loop;
}
For a complete example see dtest.d.
You can disable specific watchers types at compile-time (this should be in sync with libev watchers support).
To do that, use version EV_ENABLE_SELECT
and then select the specific
watchers you want to enable.
For example: gdc -fversion=EV_ENABLE_SELECT -fversion=EV_STAT_ENABLE
to
enable only the ev_stat
extra watcher.
There are no proper releases yet, but mainly because the code is so simple, not because the code is not working or stable enough. You can get the code from the Git repository (you can get a tarball there too, if you don’t have Git installed).
If you have any problems/comments/suggestions, you can contact me directly at luca@llucax.com. If at any time there is enough people interested in ev.d I might open a mailing list for it, but for now it seems overkill to do so =).
ev.d is placed under the BOLA License which is basically Public Domain.