The libevent for Qt network module directly replaces the select model of QT. It supports epoll, select, and pool. It is very easy to use and does not need to modify the previous code structure.

Source: Internet
Author: User
Tags epoll

Im servers are being developed recently and require high-concurrency connections. Qt uses the select model by default. This round robin mode is very slow. For highly concurrent connections, we need epoll to take advantage of the performance of the Linux server. in addition, it is easy to use, and the entire server code architecture does not need to be modified. You can set the QT distribution event, as long as you add the following in 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();}


 
 
 
Add

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


    }
It can be used directly across platforms.
Attached QT libevent source code: http://download.csdn.net/detail/rushroom/7968573
 
 

The libevent for Qt network module directly replaces the select model of QT. It supports epoll, select, and pool. It is very easy to use and does not need to modify the previous code structure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.