Add IOLoop access function. (#353)

Co-authored-by: An Tao <antao2002@gmail.com>
This commit is contained in:
ihmc3jn09hk 2020-02-16 16:48:35 +08:00 committed by GitHub
parent b733eee7e4
commit 3c15f65a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 4 deletions

View File

@ -32,6 +32,6 @@ void version::handleCommand(std::vector<std::string> &parameters)
std::cout << "A utility for drogon" << std::endl;
std::cout << "Version: " << DROGON_VERSION << std::endl;
std::cout << "Git commit: " << DROGON_VERSION_SHA1 << std::endl;
std::cout << "Compile config: " << COMPILATION_FLAGS << " " << INCLUDING_DIRS
<< std::endl;
std::cout << "Compile config: " << COMPILATION_FLAGS << " "
<< INCLUDING_DIRS << std::endl;
}

View File

@ -1,4 +1,4 @@
#!/bin/sh
find lib orm_lib examples drogon_ctl -name *.h -o -name *.cc -exec dos2unix {} \;
#find lib orm_lib examples drogon_ctl -name *.h -o -name *.cc -exec dos2unix {} \;
find lib orm_lib examples drogon_ctl -name *.h -o -name *.cc|xargs clang-format -i -style=file

View File

@ -103,6 +103,16 @@ class HttpAppFramework : public trantor::NonCopyable
*/
virtual trantor::EventLoop *getLoop() const = 0;
/// Get an IO loop with id. E.g. 0 <= id < #Total thread-loops
/**
* @note
* The event loop is one of the network IO loops. Use the loop
* for events/actions rather then the main thread.
* REMAKRS : Function assumed the number of threads will not exceed 2^32.
* Change to long long for alien computers.
*/
virtual trantor::EventLoop *getIOLoop(size_t id) const = 0;
/// Set custom 404 page
/**
* @param resp is the object set to 404 response

View File

@ -716,6 +716,12 @@ trantor::EventLoop *HttpAppFrameworkImpl::getLoop() const
return &loop;
}
trantor::EventLoop *HttpAppFrameworkImpl::getIOLoop(size_t id) const
{
assert(listenerManagerPtr_);
return listenerManagerPtr_->getIOLoop(id);
}
HttpAppFramework &HttpAppFramework::instance()
{
return HttpAppFrameworkImpl::instance();

View File

@ -332,6 +332,8 @@ class HttpAppFrameworkImpl : public HttpAppFramework
virtual trantor::EventLoop *getLoop() const override;
virtual trantor::EventLoop *getIOLoop(size_t id) const override;
virtual void quit() override;
virtual HttpAppFramework &setServerHeaderField(

View File

@ -211,3 +211,27 @@ ListenerManager::~ListenerManager()
(void)f.get();
}
}
trantor::EventLoop *ListenerManager::getIOLoop(size_t id) const
{
#ifdef __linux__
if (id >= listeningloopThreads_.size())
{
LOG_TRACE << "Loop id (" << id << ") out of range [0-"
<< listeningloopThreads_.size() << ").";
id %= listeningloopThreads_.size();
LOG_TRACE << "Rounded to : " << id;
}
assert(listeningloopThreads_[id]);
return listeningloopThreads_[id]->getLoop();
#else
if (id >= ioLoopThreadPoolPtr_->size())
{
LOG_TRACE << "Loop id (" << id << ") out of range [0-"
<< listeningloopThreads_.size() << ").";
id %= ioLoopThreadPoolPtr_->size();
LOG_TRACE << "Rounded to : " << id;
}
return ioLoopThreadPoolPtr_->getLoop(id);
#endif
}

View File

@ -46,6 +46,8 @@ class ListenerManager : public trantor::NonCopyable
void startListening();
~ListenerManager();
trantor::EventLoop *getIOLoop(size_t id) const;
private:
struct ListenerInfo
{

@ -1 +1 @@
Subproject commit dc45be8593c8acad952b8abc38b807aeeeae6baf
Subproject commit ef1e1d67084cd4d6f9ecdbddd1fb740eaac27e82