[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] intercept http accept?



If you provide write-callback on bufferevent_setcb(), I think you should get the callback on accept since the write buffer is empty and lower than the watermark. Is that something changed in libevent v2?

And also, I think you could explicitly call the callback chain on new connection.
Here's a sample code for your idea.
https://github.com/wolkykim/libasyncd/blob/master/src/ad_server.c#L631

Libasyncd explicitly do this to clearly give the INIT status to user callbacks. So in this case, user callback get 2 calls on accept. One with INIT flag and the other with WRITE flag.

Hope it helps.



On Fri, May 16, 2014 at 11:00 AM, Mark Ellzey <mthomas@xxxxxxxxxx> wrote:
On Mon, May 12, 2014 at 12:23:42PM -0700, Scott Dorr wrote:
> In libevent 2.0.21, I'm not seeing a way to get a callback triggered on accept of an http connection.  Looking through the libevent code, I don't see a way to do that, either -- or I'm missing it completely. :)
>
> Is there a way to get a callback triggered on accept of an http connection using the evhttp API?  Or is having your callback triggered post/accept/read/parse the only option? (other than using the generic libevent API to accept TCP network events and then slide over to using the http helper funcs after the fact)
>
> Thanks!

If you use libevhtp you can set the following callbacks for pre and post
accept:

void evhtp_set_pre_accept_cb(evhtp_t * htp, evhtp_pre_accept_cb cb, void * arg);
void evhtp_set_post_accept_cb(evhtp_t * htp, evhtp_post_accept_cb cb, void * arg);

https://github.com/ellzey/libevhtp

And I urge others to start testing evhtp2: https://github.com/ellzey/libevhtp/tree/libevhtp2
This is the final step before getting merged into libevent.

(psst, websocket support)
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.