【发布时间】:2014-09-03 03:42:41
【问题描述】:
我用libevent2.1.1写了一个简单的http服务器,我想我应该在http_server_callback中发布evhttp_request和evhttp_request_free。但是当我运行它时,发生了错误。请告诉我为什么,我应该怎么做。
void http_server_callback (struct evhttp_request *req, void *arg)
{
evhttp_send_reply (req, HTTP_OK, "OK", NULL);
evhttp_request_free(req);
}
int http_server_run (void)
{
struct event_base *base;
struct evhttp *http;
struct evhttp_bound_socket *handle;
base = event_base_new ();
if (! base)
{
fprintf (stderr, "Couldn't create an event_base: exiting\n");
return 1;
}
http = evhttp_new (base);
if (! http)
{
fprintf (stderr, "couldn't create evhttp. Exiting.\n");
return 1;
}
evhttp_set_gencb (http, http_server_callback, NULL);
handle = evhttp_bind_socket_with_handle (http, "127.0.0.1", 8888);
if (! handle)
{
fprintf (stderr, "couldn't bind to port 8888. Exiting.\n");
return 1;
}
event_base_dispatch (base);
return 0;
}
int main (void)
{
WSADATA WSAData;
WSAStartup (0x101, &WSAData);
http_server_run();
return 0;
}
提前致谢
【问题讨论】:
-
显示完整代码和错误详情。
-
谢谢,jfly!我修改了问题,并发布了完整的代码和错误图。