libevent for qt网络模块,直接替换qt的select模型,支持epoll,select,pool.使用非常简单,无需修改以前的代码结构

9 篇文章 1 订阅
5 篇文章 0 订阅

最近在开发im服务器,需要大并发链接。QT默认的是使用select模型的,这种轮询方式非常慢。在高并发连接,我们需要epoll才能发挥linux服务器的性能.而且使用简单,整个服务端代码架构无需修改,设置QT的分发事件就可以使用了,只要在main里面添加 :


int main(int argc, char *argv[])
{


  #ifdef Q_OS_LINUX
    QCoreApplication::setEventDispatcher(new EventDispatcherLibEvent);
   // qInstallMessageHandler(customMessageHandler);
  #endif


  QCoreApplication a(argc, argv);


  auto *ser=new ConfigServer;
  ser->startServer();


  return a.exec();
}


 


在.pro文件添加

linux{
    LIBS += -levent_core


    SOURCES += ../common/eventdispatcher_libevent/eventdispatcher_libevent.cpp \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_config.cpp \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_p.cpp \
    ../common/eventdispatcher_libevent/socknot_p.cpp \
    ../common/eventdispatcher_libevent/tco_eventfd.cpp \
    ../common/eventdispatcher_libevent/tco_pipe.cpp \
    ../common/eventdispatcher_libevent/tco.cpp \
    ../common/eventdispatcher_libevent/timers_p.cpp


    HEADERS += ../common/eventdispatcher_libevent/common.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_config.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_config_p.h \
    ../common/eventdispatcher_libevent/eventdispatcher_libevent_p.h \
    ../common/eventdispatcher_libevent/libevent2-emul.h \
    ../common/eventdispatcher_libevent/qt4compat.h \
    ../common/eventdispatcher_libevent/tco.h \
    ../common/eventdispatcher_libevent/wsainit.h


    }
可以直接跨平台了使用了
附上qt libevent源码下载地址:http://download.csdn.net/detail/rushroom/7968573

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值