I'm using libevent2 in my application to host a http server. I cant find a built-in way to compress the output.
These are the options I'm considering:
(Both read the supported compression formats from the Accept-Encoding header)
Is there some easier way I'm overlooking, or is this pretty much it?
I use this little trick to obtain the file descriptor of an evhttp_connection, which is right next to the pointer you want. It's a nasty hack, but it's simple, and easier that having to rebuild libevent. It has been tested under x86_64 and runs fine.
static void
send_document_cb(struct evhttp_request *req, void *arg)
{
// ....
struct evhttp_connection *this_connection;
this_connection = evhttp_request_get_connection(req);
int *tricky;
tricky = (((int *)this_connection) + 4);
int fd = *tricky;
printf("fd: %i\n", fd);
// ....
}
Looking at the structure definition (beneath), it appears the bufev you want should be accessible using (((void *)this_connection) + 8) or something very similar.
struct evhttp_connection {
TAILQ_ENTRY(evhttp_connection) next;
evutil_socket_t fd;
struct bufferevent *bufev;
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With