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.