Created
January 29, 2012 21:10
-
-
Save aep/1700667 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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