[Haskell-cafe] Libevent FFI problems

Levi Greenspan greenspan.levi at googlemail.com
Wed Jul 23 15:28:32 EDT 2008

Dear list members,

This is my first attempt to create a FFI to libevent
(http://monkey.org/~provos/libevent/) which is an event notification
library. A simple usage example is for instance given here:
http://unx.ca/log/libevent_echosrv1c/ . In C one basically creates
struct event instances which are initialized with a callback function
and the kind of event (e.g. read) one is intested in. Optionally a
data argument can be given which will be passed to the callback
function when invoked eventually. An event dispatcher loop will invoke
the callback when the event occurs.

I have attached my first attempt at a FFI to libevent. However it
doesn't work correctly. In the client code I want to pass 99 as data
to the callback function, but what is printed out is 0. I guess there
is an issue with pointer derefencing, but I don't know.

Also I am not sure how to handle the FunPtr deallocation. Since the
FunPtr is stored in the foreign event structure I don't know when I
can free it.

I would be grateful for any advices, hints or comments. And I really
look forward to the FFI section in the "Real World Haskell" book.

Thank you very much.

- Levi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hsevent.hsc
Type: application/octet-stream
Size: 3708 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080723/7fd47e30/hsevent.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.hs
Type: text/x-haskell
Size: 1188 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080723/7fd47e30/main.bin

More information about the Haskell-Cafe mailing list