最近在开发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

 

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:1 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐