Skip to content

Instantly share code, notes, and snippets.

@aep
Created January 29, 2012 21:10
Show Gist options
  • Save aep/1700667 to your computer and use it in GitHub Desktop.
Save aep/1700667 to your computer and use it in GitHub Desktop.
import event as libevent;
alias LibeventContinuation= Lambda[[Int, Short, Pointer[libevent.Struct_event_base]], []];
record LibeventContinuationBase
(
evbase: Pointer[libevent.Struct_event_base],
cont: LibeventContinuation
);
event_continue(a,b,c:OpaquePointer)
{
var cb = Pointer[LibeventContinuationBase](c);
cb^.cont(a,b,cb^.evbase);
destroy(cb);
}
[C] event(cont:C, fd:Int, flags:Short)
{
return (evbase)=>libevent.event_new(evbase, fd, flags,
libevent.event_callback_fn(event_continue),
OpaquePointer(allocateObject((LibeventContinuationBase(
evbase,
LibeventContinuation(cont)
)))));
}
alias EV_READ=2s;
bla()
{
return event((a,b,evbase) => {
println(readLine(stdin));
/*
return event((evbase, a,b,c) => {
println(readLine(stdin));
}, fileHandle(stdin), EV_READ);
*/
}, fileHandle(stdin), EV_READ);
}
main()
{
var evbase = libevent.event_base_new();
var ev = bla()(evbase);
while (true) {
libevent.event_add(ev, null(libevent.Struct_timeval));
libevent.event_base_dispatch(evbase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment