Discussion:
intercept http accept?
(too old to reply)
Scott Dorr
2014-05-12 19:23:42 UTC
Permalink
Raw Message
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!


- scott
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.
Mark Ellzey
2014-05-16 18:00:52 UTC
Permalink
Raw Message
Post by Scott Dorr
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 ***@freehaven.net with
unsubscribe libevent-users in the body.
Seungyoung Kim
2014-05-16 19:57:17 UTC
Permalink
Raw Message
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.
Post by Scott Dorr
Post by Scott Dorr
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. :)
Post by Scott Dorr
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)
Post by Scott Dorr
Thanks!
If you use libevhtp you can set the following callbacks for pre and post
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
https://github.com/ellzey/libevhtp/tree/libevhtp2
This is the final step before getting merged into libevent.
(psst, websocket support)
***********************************************************************
unsubscribe libevent-users in the body.
Loading...