Make all listeners share IO threads in the MacOS system
This commit is contained in:
parent
ec276b4948
commit
7d7537b562
|
@ -390,12 +390,14 @@ void HttpAppFrameworkImpl::run()
|
|||
}
|
||||
}
|
||||
#else
|
||||
auto loopThreadPtr =
|
||||
std::make_shared<EventLoopThread>("DrogonListeningLoop");
|
||||
loopThreads.push_back(loopThreadPtr);
|
||||
auto ioLoopThreadPoolPtr =
|
||||
std::make_shared<EventLoopThreadPool>(_threadNum);
|
||||
for (auto const &listener : _listeners)
|
||||
{
|
||||
LOG_TRACE << "thread num=" << _threadNum;
|
||||
auto loopThreadPtr =
|
||||
std::make_shared<EventLoopThread>("DrogonListeningLoop");
|
||||
loopThreads.push_back(loopThreadPtr);
|
||||
auto ip = std::get<0>(listener);
|
||||
bool isIpv6 = ip.find(":") == std::string::npos ? false : true;
|
||||
auto serverPtr = std::make_shared<HttpServer>(
|
||||
|
@ -420,7 +422,7 @@ void HttpAppFrameworkImpl::run()
|
|||
serverPtr->enableSSL(cert, key);
|
||||
#endif
|
||||
}
|
||||
serverPtr->setIoLoopNum(_threadNum);
|
||||
serverPtr->setIoLoopThreadPool(ioLoopThreadPoolPtr);
|
||||
serverPtr->setHttpAsyncCallback(
|
||||
std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2));
|
||||
serverPtr->setNewWebsocketCallback(std::bind(
|
||||
|
@ -429,13 +431,13 @@ void HttpAppFrameworkImpl::run()
|
|||
std::bind(&HttpAppFrameworkImpl::onConnection, this, _1));
|
||||
serverPtr->kickoffIdleConnections(_idleConnectionTimeout);
|
||||
serverPtr->start();
|
||||
auto serverIoLoops = serverPtr->getIoLoops();
|
||||
for (auto serverIoLoop : serverIoLoops)
|
||||
{
|
||||
ioLoops.push_back(serverIoLoop);
|
||||
}
|
||||
servers.push_back(serverPtr);
|
||||
}
|
||||
auto serverIoLoops = ioLoopThreadPoolPtr->getLoops();
|
||||
for (auto serverIoLoop : serverIoLoops)
|
||||
{
|
||||
ioLoops.push_back(serverIoLoop);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if USE_ORM
|
||||
|
|
|
@ -64,6 +64,11 @@ class HttpServer : trantor::NonCopyable
|
|||
{
|
||||
_connectionCallback = cb;
|
||||
}
|
||||
void setIoLoopThreadPool(
|
||||
const std::shared_ptr<trantor::EventLoopThreadPool> &pool)
|
||||
{
|
||||
_server.setIoLoopThreadPool(pool);
|
||||
}
|
||||
void setIoLoopNum(int numThreads)
|
||||
{
|
||||
_server.setIoLoopNum(numThreads);
|
||||
|
|
|
@ -100,6 +100,13 @@ MysqlConnection::MysqlConnection(trantor::EventLoop *loop,
|
|||
0);
|
||||
// LOG_DEBUG << ret;
|
||||
auto fd = mysql_get_socket(_mysqlPtr.get());
|
||||
if (fd < 0)
|
||||
{
|
||||
LOG_FATAL << "Socket fd < 0, Usually this is because the number of "
|
||||
"files opened by the program exceeds the system "
|
||||
"limit. Please use the ulimit command to check.";
|
||||
exit(-1);
|
||||
}
|
||||
_channelPtr =
|
||||
std::unique_ptr<trantor::Channel>(new trantor::Channel(loop, fd));
|
||||
_channelPtr->setCloseCallback([=]() {
|
||||
|
|
|
@ -45,7 +45,13 @@ PgConnection::PgConnection(trantor::EventLoop *loop,
|
|||
_channel(loop, PQsocket(_connPtr.get()))
|
||||
{
|
||||
PQsetnonblocking(_connPtr.get(), 1);
|
||||
// assert(PQisnonblocking(_connPtr.get()));
|
||||
if (_channel.fd() < 0)
|
||||
{
|
||||
LOG_FATAL << "Socket fd < 0, Usually this is because the number of "
|
||||
"files opened by the program exceeds the system "
|
||||
"limit. Please use the ulimit command to check.";
|
||||
exit(-1);
|
||||
}
|
||||
_channel.setReadCallback([=]() {
|
||||
if (_status != ConnectStatus_Ok)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue