mirror of
https://github.com/drogonframework/drogon.git
synced 2025-10-04 00:00:50 -04:00
Add IOLoop access function. (#353)
Co-authored-by: An Tao <antao2002@gmail.com>
This commit is contained in:
parent
b733eee7e4
commit
3c15f65a7f
@ -32,6 +32,6 @@ void version::handleCommand(std::vector<std::string> ¶meters)
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ class ListenerManager : public trantor::NonCopyable
|
||||
void startListening();
|
||||
~ListenerManager();
|
||||
|
||||
trantor::EventLoop *getIOLoop(size_t id) const;
|
||||
|
||||
private:
|
||||
struct ListenerInfo
|
||||
{
|
||||
|
2
trantor
2
trantor
@ -1 +1 @@
|
||||
Subproject commit dc45be8593c8acad952b8abc38b807aeeeae6baf
|
||||
Subproject commit ef1e1d67084cd4d6f9ecdbddd1fb740eaac27e82
|
Loading…
x
Reference in New Issue
Block a user