博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
libevent for qt网络模块,直接替换qt的select模型,支持epoll,select,pool.使用非常简单,无需修改以前的代码结构
阅读量:2238 次
发布时间:2019-05-09

本文共 1595 字,大约阅读时间需要 5 分钟。

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

[cpp] 
  1. int main(int argc, char *argv[])  
  2. {  
  3.   
  4.   
  5.   #ifdef Q_OS_LINUX  
  6.     QCoreApplication::setEventDispatcher(new EventDispatcherLibEvent);  
  7.    // qInstallMessageHandler(customMessageHandler);  
  8.   #endif  
  9.   
  10.   
  11.   QCoreApplication a(argc, argv);  
  12.   
  13.   
  14.   auto *ser=new ConfigServer;  
  15.   ser->startServer();  
  16.   
  17.   
  18.   return a.exec();  
  19. }  

 
 
 
在.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

转载地址:http://xpabb.baihongyu.com/

你可能感兴趣的文章
【Linux】了解根目录下每个文件的作用
查看>>
【Linux】进程的理解(一)
查看>>
【Linux】进程的理解(二)
查看>>
【C语言】深度理解函数的调用(栈帧)
查看>>
【Linux】进程的理解(三)
查看>>
【C++】带头节点的双向线链表的实现
查看>>
【C++】STL -- Vector容器的用法
查看>>
【Linux】Linux中的0644 和 0755的权限
查看>>
【数据结构】有关二叉树的面试题
查看>>
【Linux】内核态和用户态
查看>>
【Linux】HTTP的理解
查看>>
【Linux】HTTPS的理解
查看>>
【操作系统】大小端问题
查看>>
Git上传代码时碰到的问题及解决方法
查看>>
【Linux】vim的简单配置
查看>>
【C++】智能指针
查看>>
【C++】const修饰的成员函数
查看>>
【C++】面向对象的三大特性
查看>>
【C++】智能指针(后续)
查看>>
【C】堆区和栈区的区别
查看>>