在libevent库中,处理HTTP请求时经常需要在回调函数中管理evhttp_request对象的生命周期。确保在适当的时候释放这些对象是非常重要的,以避免内存泄漏。基于您的要求和提示,我将详细解释如何在libevent的回调函数中调用evhttp_request_free来释放evhttp_request对象,并包含相关的代码片段。 1. 确认libevent的回调函数中正确使...
#include <event.h> #include <assert.h> #include <event2/http.h> static struct evhttp_request *resp = NULL; static struct event_base *base; static void request_done(struct evhttp_request *req, void *arg) { evhttp_request_own(req); resp = req; } void rest_process(enum evhttp_cmd_ty...
Maybe I'm missing something but as far as I can tell there is no way to use evhttp_request_set_header_cb() for incoming connections. You can set request callbacks on an evhttp using either evhttp_set_cb() or evhttp_set_gencb(). These cal...
I opened a new thread to process the http request in the callback function, and used the evhttp_send related function or the replay function to reply to the client in this new thread. Sometimes I run into this problem, usually when the client's request is sent fast. I want to know if...