libevent将使用IOCP设置的问题

小鸟向前飞 2017-08-30 04:41:31
libevent使用IOCP,但是访问没有相应了。对比了libevent的bench_http.c的例子,没看出有什么差别。
请高手指点一下。

代码如下:


void GenCB(struct evhttp_request* req, void* args);

int _tmain(int argc, _TCHAR* argv[])
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
assert(false);
return -1;
}

short http_port = 8081;
char* http_addr = "127.0.0.1";

evthread_use_windows_threads();

struct event_config* cfg = event_config_new();
event_config_set_flag(cfg, EVENT_BASE_FLAG_STARTUP_IOCP);

//struct event_base * base = event_base_new();
struct event_base* base = event_base_new_with_config(cfg);

struct evhttp * http_server = evhttp_new(base);
if (!http_server)
{
return -1;
}

int ret = evhttp_bind_socket(http_server, http_addr, http_port);
if (ret != 0)
{
return -1;
}

evhttp_set_gencb(http_server, GenCB, NULL);

printf("http server start OK! \n");

event_base_dispatch(base);

evhttp_free(http_server);

WSACleanup();

return 0;
}


void GenCB(struct evhttp_request* req, void* args)
{
struct evbuffer *buf = evbuffer_new();

evbuffer_add_printf(buf, "Server Responsed. Requested: %s\n", evhttp_request_get_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);

evbuffer_free(buf);
}

...全文
185 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧