On Fri, Nov 23, 2007 at 04:03:52PM +0100, Nicolas Favre-Félix <[EMAIL PROTECTED]> wrote: > > libevent doesn't support forking (unless you force it to use select or > > poll) and continue using it in the child. > > > > That's actually what I'm doing at the moment, calling listen(), then fork(). > Each child adds a callback for EV_READ on the socket and runs its event > loop.
I hope you also initialise libevent only in the child, too (or indeed use fork or select), as kqueue etc. will not work in the child processes. > It tries to accept() on it when the callback function is executed, and > handles the client. This has been tested quite heavily without problem... > Could there be one? No, not if you only touch libevent in one process that doesn't fork (e.g. in each child). The only problem I see with your approach is that it scales badly, as all processes got woken up that way and then fight for the new connection. But thats not really a problem unless you want high performance, and is a correct approach, which is most important. If you can block when idling (as opposed to having to handle events) you could also just call accept() in each child - on the more prestigious kernels (e.g. freebsd and linux) this will only wake up one process, but of course doesn't allow event handling. > Thank you for your precisions. I don't have an event loop in the parent, so > this is not a problem. Ah, your mentioning of pre-fork and having a problem made me think that were experiencinging problems with that, my bad :) > > I'd like to integrate HTTP support - using evhttp. > this was my main question... Is it possible to give evhttp a bound socket to > monitor? Not with the public API. It is also not sure wether this is what you want, you want to handle a request on a socket you already accepted (unless you want evhttp to do its accepting). If you are logging, libevent will also flood you with false warning messages because it doesn't expect accept not returning a new connection). evhttp internally calls evhttp_get_request, but obviously needs a webserver to be created already. Looking at the code, this could do what you want: struct evhttp *http = evhttp_new_object (); while (fd == accept) evutil_make_socket_nonblocking (fd); evhttp_get_request(http, fd, sockaddr, addrlen); This is of course not prototyped in evhttp.h and undocumented, but it seems quite fashionable to work around the limitations of the public libevent API by calling those private (but non-static) functions. YMMV. > I checked http.c but couldn't find any exported function doing this. If this > isn't implemented, would it be OK to submit a patch to add this feature? Well, they are "exported", just not "declared", if you will :) -- The choice of a Deliantra, the free code+content MORPG -----==- _GNU_ http://www.deliantra.net ----==-- _ generation ---==---(_)__ __ ____ __ Marc Lehmann --==---/ / _ \/ // /\ \/ / [EMAIL PROTECTED] -=====/_/_//_/\_,_/ /_/\_\ _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users