让Libevent 在window下 支持 IOCP

来源:互联网 发布:菜鸟程序员 编辑:程序博客网 时间:2024/06/04 18:10

   Libevent 的强大就不说了,但由于在window下使用的是 select 机制 ,除了效率低下意外还有一个讨厌的"FD_SETSIZE"限制,所以一直希望能支持IOCP,可是现在已经到2.0还是没能够支持。


    无意中在网上发现了个支持IOCP的libevent版本,是1.4.7版的。不过没关系,把其中的一个关键文件"win32iocp.c"拷贝到最新的1.4.14b版本中,并在"event.c"中修改:

.....
#ifdef HAVE_POLL
extern const struct eventop pollops;
#endif
#ifdef HAVE_EPOLL
extern const struct eventop epollops;
#endif
#ifdef HAVE_WORKING_KQUEUE
extern const struct eventop kqops;
#endif
#ifdef HAVE_DEVPOLL
extern const struct eventop devpollops;
#endif
#ifdef WIN32
#ifndef _EVENT_NOIOCP
extern const struct eventop win32iocpops;
#endif

extern const struct eventop win32ops;
#endif

.....

static const struct eventop *eventops[] = {
#ifdef HAVE_EVENT_PORTS
    &evportops,
#endif
#ifdef HAVE_WORKING_KQUEUE
    &kqops,
#endif
#ifdef HAVE_EPOLL
    &epollops,
#endif
#ifdef HAVE_DEVPOLL
    &devpollops,
#endif
#ifdef HAVE_POLL
    &pollops,
#endif
#ifdef HAVE_SELECT
    &selectops,
#endif
#ifdef WIN32

#ifndef _EVENT_NOIOCP
    &win32iocpops,
#endif


    &win32ops,
#endif
    NULL
};

....

红色部分是添加的。


这样就可以很好的支持IOCP了。

 

附: win32iocp.c 代码

 

 

 

 

 

 

原创粉丝点击