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

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

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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文件添加

 
 
 
 
 

Vim

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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源码下载地址:qt_libevent.zip

http://love.junzimu.com/archives/2657

libevent for qt网络模块的更多相关文章

  1. libevent for qt的讨论

    一直对Qt官方的QtNetwork模块抱有遗憾,Qt自带的网络模块用的是select模型,无法支持高并发的服务器开发.最近在网上看到有个libevent for qt的东西,它直接替换了Qt的sele ...

  2. Qt 网络模块如何使用?

    1.网络模块介绍 类名 说明 中文 QAbstractNetworkCache The interface for cache implementations 缓存实现的接口 QNetworkCach ...

  3. Qt网络模块如何使用(表格)

    1.网络模块介绍 类名 说明 中文 QAbstractNetworkCache The interface for cache implementations 缓存实现的接口 QNetworkCach ...

  4. GeoServer-REST应用:基于Qt网络编程一键同步发布空间数据和样式至GeoServer

    @ 目录 简介 配置 步骤   1.引入Qt网络模块   2.创建网络管理.网络响应.网络请求   3.创建工作空间   4.创建数据存储并上传数据   5.上传样式文件   6.图层发布   6.图 ...

  5. Primecoin在windows上的部署和启动服务

     Primecoin在windows上的部署和启动服务: 一.从官方获得Primecoin的windows版安装包: 二.一路像安装客户端一样的安装: 三.安装成功后它会自动弹出客户端运行,同步数据, ...

  6. bitcoind

    Bitcoin Core Daemon version v0.15.1.0-g7b57bc998f Usage: bitcoind [options] Start Bitcoin Core Daemo ...

  7. Qt中加载Libevent静态库(通过reimp和rs两条语句将lib转为a)

    文章来源:http://blog.sina.com.cn/s/blog_731bf4c90102wnpr.html 本文仅是个人经验总结,若有错误欢迎指教! 最近要做一个跨平台的项目,同时也涉及到网络 ...

  8. Qt 工程 pro文件

    工作中,感觉pro文件的有些内容真不太懂,现系统性的学习一下.于此备录,分享共勉. 为了更好的理解,先创建一个简单的工程作为实践. [1]创建一个pro文件 1.1 新建proDemo工程.步骤如下: ...

  9. Qt之Threads和QObjects

    简述 QThread继承自QObject,它发射信号(signals)以表明线程执行开始或结束,并提供了一些槽函数(slots). 更有趣的是,QObjects可以在多线程中使用,发射信号以在其它线程 ...

随机推荐

  1. PowerShell 中的目录文件管理

    前面的一篇文章我们说了部分在PS中进行文件浏览的基本概念,说到了几个虚拟驱动器的概念.并没有深入的描述相关的命令,这里我们进一步对这一知识点进行描述. 2.1 管理当前工作路径/位置 在日常管理中经常 ...

  2. 107个常用Javascript语句

    1.document.write( " "); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document- >html- >(head,body ...

  3. 单目录下多文件 makefile编写

    makefile很久就接触过了,但是一直没怎么深入的去学习和总结:在项目中我也只是看看makefile或者修改部分语句,全部自己动手写的话还真没有:知识在于沉淀,这句说的非常好,所以现在把自己理解的东 ...

  4. [Linux] killall 、kill 、pkill 命令详解

    killall 命令 Linux系统中的killall命令用于杀死指定名字的进程(kill processes by name).我们可以使用kill命令杀死指定进程PID的进程,如果要找到我们需要杀 ...

  5. 第13讲- Android之消息提示Notification

    第13讲 Android之消息提示Notification .Notification Notification可以理解为通知的意思一般用来显示广播信息,通知可以显示到系统的上方的状态栏(status ...

  6. hdu 5245 Joyful(期望的计算,好题)

    Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to pain ...

  7. redis知识

    http://www.cnblogs.com/moon521/p/5301895.html 菜鸟教程:http://www.runoob.com/redis/redis-tutorial.html

  8. AFN的二次封装

    http://www.cnblogs.com/sxwangjiadong/p/4970751.html

  9. 为github帐号添加SSH keys

    为github帐号添加SSH keys 2012-05-26 00:05 34279人阅读 评论(6) 收藏 举报 ssh文本编辑gitvim工具up 使用git clone命令从github上同步g ...

  10. Oracle 中的Pivoting Insert用法

    1.标准Insert --单表单行插入   语法:   INSERT INTO table [(column1,column2,...)] VALUE (value1,value2,...)      ...