[Haskell-cafe] Libevent FFI problems

Levi Greenspan greenspan.levi at googlemail.com
Fri Jul 25 15:24:29 EDT 2008

Thanks Adam. It took me some time to realize what you recognized
immediately - xptr is useless. Instead I now bind the additional value
which might be provided on event creation in a closure since the C
code never has to deal with it.

And yes, there are many functions missing. For now I just need the
event notification to detect file descritor (or socket) changes.

Regarding your remark, that the RTS multiplexes IO already I am usure
how this works out in practice. The reason I write this wrapper is
that I want a network server which can handle thousands of
connections. And to not require a permanent thread for each I would
like to use something like select in C or Selector in Java. I haven't
found something like this in Haskell, hence the libevent wrapper. If
you have any information how to write something like this without this
wrapper I would be more than happy.

Finally the code still leaks FunPtrs as so far I never free them and
honestly I don't know when to do this. Any ideas?

For reference I have attached a newer version of the wrapper code
(removed the TimeVal stuff since I don't need it).

Thanks again,

On Fri, Jul 25, 2008 at 7:21 PM, Adam Langley <agl at imperialviolet.org> wrote:
> 2008/7/23 Levi Greenspan <greenspan.levi at googlemail.com>:
>> 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.
> Generally it looks pretty good. I think I'm missing some C code
> (function "wrapper"). However, libevent is an odd choice to wrap. The
> RTS already multiplexes IO for Haskell programs. In order not to block
> the RTS, the libevent using code would have to be in its own kernel
> thread.
> Really, the RTS needs to be ported to libevent rather than an FFI wrapping.
> For your specific problem, I see you're allocating xptr, but I don't
> see that you're ever poking a value into it. Indeed, I can't see that
> createEvent ever uses 'x'.
> Hope that helps.
> --
> Adam Langley agl at imperialviolet.org http://www.imperialviolet.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hsevent.hsc
Type: application/octet-stream
Size: 4062 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080725/9306ab95/hsevent.obj

More information about the Haskell-Cafe mailing list