Feature #5714 ยป 0001-Server-Support-for-running-the-server-in-the-main-th.patch
src/Wt/WIOService | ||
---|---|---|
*/
|
||
void start();
|
||
/*! \brief Starts the I/O service in the main thread.
|
||
*/
|
||
void start_mt();
|
||
/*! \brief Stops the I/O service.
|
||
*
|
||
* This will stop the internal thread pool. The method will block until
|
src/Wt/WIOService.C | ||
---|---|---|
}
|
||
}
|
||
void WIOService::start_mt()
|
||
{
|
||
if(!impl_->work_)
|
||
{
|
||
impl_->work_ = new boost::asio::io_service::work(*this);
|
||
run();
|
||
}
|
||
}
|
||
void WIOService::stop()
|
||
{
|
||
delete impl_->work_;
|
src/Wt/WServer | ||
---|---|---|
* \sa isRunning(), stop()
|
||
*/
|
||
WTCONNECTOR_API bool start();
|
||
|
||
/*! \brief Sets whatever a server should be run in the main thread.
|
||
*/
|
||
WT_API void setrunInMainThread(bool Enable);
|
||
/*! \brief Stops the server.
|
||
*
|
||
* All active application sessions are terminated cleanly, and the
|
||
... | ... | |
WT_API static void terminate();
|
||
#endif // WT_WIN32
|
||
WT_API bool runInMainThread() const;
|
||
private:
|
||
WebController *webController_;
|
||
... | ... | |
WIOService *ioService_;
|
||
bool dedicatedProcessEnabled_;
|
||
bool runInMainThreadEnabled;
|
||
struct Impl;
|
||
Impl *impl_;
|
src/Wt/WServer.C | ||
---|---|---|
ownsIOService_ = true;
|
||
dedicatedProcessEnabled_ = false;
|
||
runInMainThreadEnabled = false;
|
||
ioService_ = 0;
|
||
webController_ = 0;
|
||
configuration_ = 0;
|
||
... | ... | |
LOG_INFO("initializing " << description_);
|
||
}
|
||
void WServer::setrunInMainThread(bool Enable)
|
||
{
|
||
runInMainThreadEnabled = Enable;
|
||
}
|
||
bool WServer::runInMainThread() const
|
||
{
|
||
return runInMainThreadEnabled;
|
||
}
|
||
Configuration& WServer::configuration()
|
||
{
|
||
if (!configuration_) {
|
||
... | ... | |
void WServer::scheduleStop()
|
||
{
|
||
#ifdef WT_THREADED
|
||
if(runInMainThread())
|
||
{
|
||
if(!stopCallback_.empty())
|
||
stopCallback_();
|
||
}
|
||
else
|
||
{
|
||
#ifndef WT_WIN32
|
||
kill(getpid(), SIGTERM);
|
||
#else // WT_WIN32
|
||
terminate();
|
||
#endif // WT_WIN32
|
||
}
|
||
#else // !WT_THREADED
|
||
if (!stopCallback_.empty())
|
||
stopCallback_();
|
src/http/WServer.C | ||
---|---|---|
LOG_WARN("No boost thread support, running in main thread.");
|
||
#endif // WT_THREADED
|
||
webController_->start();
|
||
webController_->start();
|
||
ioService().start();
|
||
if(runInMainThread())
|
||
{
|
||
ioService().start_mt();
|
||
delete impl_->server_;
|
||
impl_->server_ = 0;
|
||
ioService().stop();
|
||
}
|
||
else
|
||
ioService().start();
|
||
|
||
#ifndef WT_THREADED
|
||
delete impl_->server_;
|
||
impl_->server_ = 0;
|
||
... | ... | |
return false;
|
||
#else
|
||
return true;
|
||
return runInMainThread() ? false : true;
|
||
#endif // WT_THREADED
|
||
} catch (asio_system_error& e) {
|
||
... | ... | |
#ifdef WT_THREADED
|
||
try {
|
||
// Stop the Wt application server (cleaning up all sessions).
|
||
webController_->shutdown();
|
||
// Stop the Wt application server (cleaning up all sessions).
|
||
webController_->shutdown();
|
||
LOG_INFO("Shutdown: stopping web server.");
|
||
LOG_INFO("Shutdown: stopping web server.");
|
||
// Stop the server.
|
||
impl_->server_->stop();
|
||
ioService().stop();
|
||
ioService().stop();
|
||
delete impl_->server_;
|
||
impl_->server_ = 0;
|
||
if(!runInMainThread())
|
||
{
|
||
delete impl_->server_;
|
||
impl_->server_ = 0;
|
||
}
|
||
} catch (asio_system_error& e) {
|
||
throw Exception(std::string("Error (asio): ") + e.what());
|
||
} catch (std::exception& e) {
|
src/web/WebController.C | ||
---|---|---|
}
|
||
#ifdef WT_THREADED
|
||
while (zombieSessions_ > 0) {
|
||
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
||
if(!server_.runInMainThread())
|
||
{
|
||
while(zombieSessions_ > 0)
|
||
{
|
||
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
||
}
|
||
}
|
||
#endif
|
||
}
|