mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Reimplemented run().
This commit is contained in:
parent
3f45e92835
commit
eab0802df2
@ -97,8 +97,8 @@ env_base.Prepend(CPPPATH=["#"])
|
|||||||
env_base.Prepend(CPPPATH=["#libs"])
|
env_base.Prepend(CPPPATH=["#libs"])
|
||||||
env_base.Prepend(LINKFLAGS=["-lpthread"])
|
env_base.Prepend(LINKFLAGS=["-lpthread"])
|
||||||
|
|
||||||
env_base.Append(CXX=["-o3"])
|
#env_base.Append(CXX=["-o3"])
|
||||||
#env_base.Append(CXX=["-g"])
|
env_base.Append(CXX=["-g"])
|
||||||
#env_base.Append(CXX=["-g2"])
|
#env_base.Append(CXX=["-g2"])
|
||||||
#env_base.Append(CXX=["-fno-rtti"])
|
#env_base.Append(CXX=["-fno-rtti"])
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ HttpAppFrameworkImpl::HttpAppFrameworkImpl() :
|
|||||||
uploadPath_(rootPath_ + "uploads") {
|
uploadPath_(rootPath_ + "uploads") {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static std::function<void()> f = [] {
|
static std::function<void()> f = [] {
|
||||||
LOG_TRACE << "Initialize the main event loop in the main thread";
|
LOG_TRACE << "Initialize the main event loop in the main thread";
|
||||||
};
|
};
|
||||||
@ -90,6 +91,7 @@ static std::function<void()> f = [] {
|
|||||||
drogon::InitBeforeMainFunction drogon::HttpAppFrameworkImpl::initFirst_([]() {
|
drogon::InitBeforeMainFunction drogon::HttpAppFrameworkImpl::initFirst_([]() {
|
||||||
HttpAppFrameworkImpl::instance().getLoop()->runInLoop(f);
|
HttpAppFrameworkImpl::instance().getLoop()->runInLoop(f);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
namespace drogon {
|
namespace drogon {
|
||||||
std::string getVersion() {
|
std::string getVersion() {
|
||||||
@ -462,7 +464,7 @@ void HttpAppFrameworkImpl::run() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Create all listeners.
|
// Create all listeners.
|
||||||
auto ioLoops = listenerManagerPtr_->createListeners(
|
auto ioLoops = listenerManagerPtr_->createListeners(getLoop(),
|
||||||
std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2),
|
std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2),
|
||||||
std::bind(&HttpAppFrameworkImpl::onNewWebsockRequest, this, _1, _2, _3),
|
std::bind(&HttpAppFrameworkImpl::onNewWebsockRequest, this, _1, _2, _3),
|
||||||
std::bind(&HttpAppFrameworkImpl::onConnection, this, _1),
|
std::bind(&HttpAppFrameworkImpl::onConnection, this, _1),
|
||||||
@ -736,8 +738,9 @@ void HttpAppFrameworkImpl::onAsyncRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
trantor::EventLoop *HttpAppFrameworkImpl::getLoop() const {
|
trantor::EventLoop *HttpAppFrameworkImpl::getLoop() const {
|
||||||
static trantor::EventLoop loop;
|
//static trantor::EventLoop loop;
|
||||||
return &loop;
|
//return &loop;]
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
trantor::EventLoop *HttpAppFrameworkImpl::getIOLoop(size_t id) const {
|
trantor::EventLoop *HttpAppFrameworkImpl::getIOLoop(size_t id) const {
|
||||||
|
@ -32,12 +32,13 @@ void defaultExceptionHandler(const std::exception &,
|
|||||||
const HttpRequestPtr &,
|
const HttpRequestPtr &,
|
||||||
std::function<void(const HttpResponsePtr &)> &&);
|
std::function<void(const HttpResponsePtr &)> &&);
|
||||||
|
|
||||||
|
/*
|
||||||
struct InitBeforeMainFunction {
|
struct InitBeforeMainFunction {
|
||||||
explicit InitBeforeMainFunction(const std::function<void()> &func) {
|
explicit InitBeforeMainFunction(const std::function<void()> &func) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
class HttpAppFrameworkImpl final : public HttpAppFramework {
|
class HttpAppFrameworkImpl final : public HttpAppFramework {
|
||||||
public:
|
public:
|
||||||
HttpAppFrameworkImpl();
|
HttpAppFrameworkImpl();
|
||||||
@ -533,7 +534,7 @@ private:
|
|||||||
HttpResponsePtr custom404_;
|
HttpResponsePtr custom404_;
|
||||||
std::function<HttpResponsePtr(HttpStatusCode)> customErrorHandler_ =
|
std::function<HttpResponsePtr(HttpStatusCode)> customErrorHandler_ =
|
||||||
&defaultErrorHandler;
|
&defaultErrorHandler;
|
||||||
static InitBeforeMainFunction initFirst_;
|
//static InitBeforeMainFunction initFirst_;
|
||||||
bool enableServerHeader_{ true };
|
bool enableServerHeader_{ true };
|
||||||
bool enableDateHeader_{ true };
|
bool enableDateHeader_{ true };
|
||||||
bool reusePort_{ false };
|
bool reusePort_{ false };
|
||||||
|
@ -159,6 +159,7 @@ HttpServer::HttpServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
HttpServer::~HttpServer() {
|
HttpServer::~HttpServer() {
|
||||||
|
LOG_WARN << "HttpServer desxtr";
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpServer::start() {
|
void HttpServer::start() {
|
||||||
|
@ -65,7 +65,7 @@ void ListenerManager::addListener(
|
|||||||
ip, port, useSSL, certFile, keyFile, useOldTLS, sslConfCmds);
|
ip, port, useSSL, certFile, keyFile, useOldTLS, sslConfCmds);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<trantor::EventLoop *> ListenerManager::createListeners(
|
std::vector<trantor::EventLoop *> ListenerManager::createListeners(trantor::EventLoop *event_loop,
|
||||||
const HttpAsyncCallback &httpCallback,
|
const HttpAsyncCallback &httpCallback,
|
||||||
const WebSocketNewAsyncCallback &webSocketCallback,
|
const WebSocketNewAsyncCallback &webSocketCallback,
|
||||||
const ConnectionCallback &connectionCallback,
|
const ConnectionCallback &connectionCallback,
|
||||||
@ -86,43 +86,53 @@ std::vector<trantor::EventLoop *> ListenerManager::createListeners(
|
|||||||
std::function<void(const HttpRequestPtr &, const HttpResponsePtr &)> >
|
std::function<void(const HttpRequestPtr &, const HttpResponsePtr &)> >
|
||||||
&preSendingAdvices) {
|
&preSendingAdvices) {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
|
|
||||||
for (size_t i = 0; i < threadNum; ++i) {
|
for (size_t i = 0; i < threadNum; ++i) {
|
||||||
|
|
||||||
LOG_TRACE << "thread num=" << threadNum;
|
LOG_TRACE << "thread num=" << threadNum;
|
||||||
|
|
||||||
auto loopThreadPtr = std::make_shared<EventLoopThread>("DrogonIoLoop");
|
auto loopThreadPtr = std::make_shared<EventLoopThread>("DrogonIoLoop");
|
||||||
|
|
||||||
listeningloopThreads_.push_back(loopThreadPtr);
|
listeningloopThreads_.push_back(loopThreadPtr);
|
||||||
ioLoops_.push_back(loopThreadPtr->getLoop());
|
ioLoops_.push_back(loopThreadPtr->getLoop());
|
||||||
|
|
||||||
for (auto const &listener : listeners_) {
|
for (auto const &listener : listeners_) {
|
||||||
|
|
||||||
auto const &ip = listener.ip_;
|
auto const &ip = listener.ip_;
|
||||||
bool isIpv6 = ip.find(':') == std::string::npos ? false : true;
|
bool isIpv6 = ip.find(':') == std::string::npos ? false : true;
|
||||||
std::shared_ptr<HttpServer> serverPtr;
|
std::shared_ptr<HttpServer> serverPtr;
|
||||||
InetAddress listenAddress(ip, listener.port_, isIpv6);
|
InetAddress listenAddress(ip, listener.port_, isIpv6);
|
||||||
|
|
||||||
if (listenAddress.isUnspecified()) {
|
if (listenAddress.isUnspecified()) {
|
||||||
LOG_FATAL << "Failed to parse IP address '" << ip
|
LOG_FATAL << "Failed to parse IP address '" << ip
|
||||||
<< "'. (Note: FQDN/domain names/hostnames are not "
|
<< "'. (Note: FQDN/domain names/hostnames are not "
|
||||||
"supported. Including 'localhost')";
|
"supported. Including 'localhost')";
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0 && !app().reusePort()) {
|
if (i == 0 && !app().reusePort()) {
|
||||||
DrogonFileLocker lock;
|
DrogonFileLocker lock;
|
||||||
// Check whether the port is in use.
|
// Check whether the port is in use.
|
||||||
TcpServer server(HttpAppFrameworkImpl::instance().getLoop(),
|
TcpServer server(event_loop,
|
||||||
std::move(listenAddress),
|
std::move(listenAddress),
|
||||||
"drogonPortTest",
|
"drogonPortTest",
|
||||||
true,
|
true,
|
||||||
false);
|
false);
|
||||||
serverPtr =
|
|
||||||
std::make_shared<HttpServer>(loopThreadPtr->getLoop(),
|
serverPtr = std::make_shared<HttpServer>(loopThreadPtr->getLoop(),
|
||||||
std::move(listenAddress),
|
std::move(listenAddress),
|
||||||
"drogon",
|
"drogon",
|
||||||
syncAdvices,
|
syncAdvices,
|
||||||
preSendingAdvices);
|
preSendingAdvices);
|
||||||
} else {
|
} else {
|
||||||
serverPtr =
|
|
||||||
std::make_shared<HttpServer>(loopThreadPtr->getLoop(),
|
serverPtr = std::make_shared<HttpServer>(loopThreadPtr->getLoop(),
|
||||||
std::move(listenAddress),
|
std::move(listenAddress),
|
||||||
"drogon",
|
"drogon",
|
||||||
syncAdvices,
|
syncAdvices,
|
||||||
preSendingAdvices);
|
preSendingAdvices);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listener.useSSL_) {
|
if (listener.useSSL_) {
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
bool useOldTLS = false,
|
bool useOldTLS = false,
|
||||||
const std::vector<std::pair<std::string, std::string> >
|
const std::vector<std::pair<std::string, std::string> >
|
||||||
&sslConfCmds = {});
|
&sslConfCmds = {});
|
||||||
std::vector<trantor::EventLoop *> createListeners(
|
std::vector<trantor::EventLoop *> createListeners(trantor::EventLoop *event_loop,
|
||||||
const HttpAsyncCallback &httpCallback,
|
const HttpAsyncCallback &httpCallback,
|
||||||
const WebSocketNewAsyncCallback &webSocketCallback,
|
const WebSocketNewAsyncCallback &webSocketCallback,
|
||||||
const trantor::ConnectionCallback &connectionCallback,
|
const trantor::ConnectionCallback &connectionCallback,
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <trantor/utils/AsyncFileLogger.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -142,6 +144,9 @@ void DWebApplication::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DWebApplication::add_listener(const std::string &ip, uint16_t port, bool useSSL, const std::string &certFile, const std::string &keyFile, bool useOldTLS, const std::vector<std::pair<std::string, std::string> > &sslConfCmds) {
|
void DWebApplication::add_listener(const std::string &ip, uint16_t port, bool useSSL, const std::string &certFile, const std::string &keyFile, bool useOldTLS, const std::vector<std::pair<std::string, std::string> > &sslConfCmds) {
|
||||||
|
assert(!_running);
|
||||||
|
|
||||||
|
_listener_manager->addListener(ip, port, useSSL, certFile, keyFile, useOldTLS, sslConfCmds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWebApplication::set_thread_num(size_t thread_num) {
|
void DWebApplication::set_thread_num(size_t thread_num) {
|
||||||
@ -164,27 +169,34 @@ void DWebApplication::set_ssl_files(const std::string &certPath, const std::stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DWebApplication::run() {
|
void DWebApplication::run() {
|
||||||
/*
|
if (!get_loop()->isInLoopThread()) {
|
||||||
if (!getLoop()->isInLoopThread()) {
|
get_loop()->moveToCurrentThread();
|
||||||
getLoop()->moveToCurrentThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_TRACE << "Start to run...";
|
LOG_TRACE << "Start to run...";
|
||||||
|
|
||||||
trantor::AsyncFileLogger asyncFileLogger;
|
trantor::AsyncFileLogger asyncFileLogger;
|
||||||
|
|
||||||
// Create dirs for cache files
|
// Create dirs for cache files
|
||||||
for (int i = 0; i < 256; ++i) {
|
for (int i = 0; i < 256; ++i) {
|
||||||
char dirName[4];
|
char dirName[4];
|
||||||
snprintf(dirName, sizeof(dirName), "%02x", i);
|
snprintf(dirName, sizeof(dirName), "%02x", i);
|
||||||
|
|
||||||
std::transform(dirName, dirName + 2, dirName, toupper);
|
std::transform(dirName, dirName + 2, dirName, toupper);
|
||||||
utils::createPath(getUploadPath() + "/tmp/" + dirName);
|
|
||||||
|
utils::createPath(get_upload_path() + "/tmp/" + dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (runAsDaemon_) {
|
if (runAsDaemon_) {
|
||||||
// go daemon!
|
// go daemon!
|
||||||
godaemon();
|
godaemon();
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
getLoop()->resetTimerQueue();
|
get_loop()->resetTimerQueue();
|
||||||
#endif
|
#endif
|
||||||
getLoop()->resetAfterFork();
|
get_loop()->resetAfterFork();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set relaunching
|
// set relaunching
|
||||||
if (relaunchOnError_) {
|
if (relaunchOnError_) {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -202,28 +214,33 @@ void DWebApplication::run() {
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
LOG_INFO << "start new process";
|
LOG_INFO << "start new process";
|
||||||
}
|
}
|
||||||
getLoop()->resetAfterFork();
|
get_loop()->resetAfterFork();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handleSigterm_) {
|
if (handleSigterm_) {
|
||||||
signal(SIGTERM, TERMFunction);
|
signal(SIGTERM, TERMFunction);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// set logger
|
// set logger
|
||||||
if (!logPath_.empty()) {
|
if (!_log_path.empty()) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (_access(logPath_.c_str(), 06) != 0)
|
if (_access(_log_path.c_str(), 06) != 0)
|
||||||
#else
|
#else
|
||||||
if (access(logPath_.c_str(), R_OK | W_OK) != 0)
|
if (access(_log_path.c_str(), R_OK | W_OK) != 0)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
LOG_ERROR << "log file path not exist";
|
LOG_ERROR << "log file path not exist";
|
||||||
abort();
|
abort();
|
||||||
} else {
|
} else {
|
||||||
std::string baseName = logfileBaseName_;
|
std::string baseName = _logfile_base_name;
|
||||||
|
|
||||||
if (baseName.empty()) {
|
if (baseName.empty()) {
|
||||||
baseName = "drogon";
|
baseName = "rcpp_fw";
|
||||||
}
|
}
|
||||||
asyncFileLogger.setFileName(baseName, ".log", logPath_);
|
|
||||||
|
asyncFileLogger.setFileName(baseName, ".log", _log_path);
|
||||||
asyncFileLogger.startLogging();
|
asyncFileLogger.startLogging();
|
||||||
|
|
||||||
trantor::Logger::setOutputFunction(
|
trantor::Logger::setOutputFunction(
|
||||||
@ -232,13 +249,17 @@ void DWebApplication::run() {
|
|||||||
},
|
},
|
||||||
[&]() { asyncFileLogger.flush(); });
|
[&]() { asyncFileLogger.flush(); });
|
||||||
|
|
||||||
asyncFileLogger.setFileSizeLimit(logfileSize_);
|
asyncFileLogger.setFileSizeLimit(_logfile_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (relaunchOnError_) {
|
if (relaunchOnError_) {
|
||||||
LOG_INFO << "Start child process";
|
LOG_INFO << "Start child process";
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (!libFilePaths_.empty()) {
|
if (!libFilePaths_.empty()) {
|
||||||
sharedLibManagerPtr_ =
|
sharedLibManagerPtr_ =
|
||||||
@ -246,33 +267,37 @@ void DWebApplication::run() {
|
|||||||
libFileOutputPath_);
|
libFileOutputPath_);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
// Create all listeners.
|
// Create all listeners.
|
||||||
auto ioLoops = listenerManagerPtr_->createListeners(
|
auto ioLoops = _listener_manager->createListeners(get_loop(),
|
||||||
std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2),
|
std::bind(&DWebApplication::on_async_request, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
std::bind(&HttpAppFrameworkImpl::onNewWebsockRequest, this, _1, _2, _3),
|
std::bind(&DWebApplication::on_new_websock_request, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
|
||||||
std::bind(&HttpAppFrameworkImpl::onConnection, this, _1),
|
std::bind(&DWebApplication::on_connection, this, std::placeholders::_1),
|
||||||
idleConnectionTimeout_,
|
_idle_connection_timeout, _ssl_cert_path, _ssl_key_path, _ssl_conf_cmds, _thread_num, _sync_advices, _pre_sending_advices);
|
||||||
sslCertPath_,
|
|
||||||
sslKeyPath_,
|
|
||||||
sslConfCmds_,
|
|
||||||
threadNum_,
|
assert(ioLoops.size() == _thread_num);
|
||||||
syncAdvices_,
|
|
||||||
preSendingAdvices_);
|
for (size_t i = 0; i < _thread_num; ++i) {
|
||||||
assert(ioLoops.size() == threadNum_);
|
|
||||||
for (size_t i = 0; i < threadNum_; ++i) {
|
|
||||||
ioLoops[i]->setIndex(i);
|
ioLoops[i]->setIndex(i);
|
||||||
}
|
}
|
||||||
getLoop()->setIndex(threadNum_);
|
|
||||||
|
get_loop()->setIndex(_thread_num);
|
||||||
|
|
||||||
// A fast database client instance should be created in the main event
|
// A fast database client instance should be created in the main event
|
||||||
// loop, so put the main loop into ioLoops.
|
// loop, so put the main loop into ioLoops.
|
||||||
ioLoops.push_back(getLoop());
|
ioLoops.push_back(get_loop());
|
||||||
|
|
||||||
if (useSession_) {
|
if (_use_session) {
|
||||||
sessionManagerPtr_ =
|
_session_manager = std::make_unique<SessionManager>(get_loop(), _session_timeout);
|
||||||
std::make_unique<SessionManager>(getLoop(), sessionTimeout_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now start runing!!
|
// now start runing!!
|
||||||
running_ = true;
|
_running = true;
|
||||||
|
|
||||||
|
/*
|
||||||
// Initialize plugins
|
// Initialize plugins
|
||||||
const auto &pluginConfig = jsonConfig_["plugins"];
|
const auto &pluginConfig = jsonConfig_["plugins"];
|
||||||
if (!pluginConfig.isNull()) {
|
if (!pluginConfig.isNull()) {
|
||||||
@ -283,23 +308,26 @@ void DWebApplication::run() {
|
|||||||
// << plugin->className();
|
// << plugin->className();
|
||||||
// TODO: new plugin
|
// TODO: new plugin
|
||||||
});
|
});
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//httpCtrlsRouterPtr_->init(ioLoops);
|
//httpCtrlsRouterPtr_->init(ioLoops);
|
||||||
//httpSimpleCtrlsRouterPtr_->init(ioLoops);
|
//httpSimpleCtrlsRouterPtr_->init(ioLoops);
|
||||||
|
|
||||||
staticFileRouterPtr_->init(ioLoops);
|
//staticFileRouterPtr_->init(ioLoops);
|
||||||
websockCtrlsRouterPtr_->init();
|
//websockCtrlsRouterPtr_->init();
|
||||||
getLoop()->queueInLoop([this]() {
|
|
||||||
|
get_loop()->queueInLoop([this]() {
|
||||||
// Let listener event loops run when everything is ready.
|
// Let listener event loops run when everything is ready.
|
||||||
listenerManagerPtr_->startListening();
|
_listener_manager->startListening();
|
||||||
for (auto &adv : beginningAdvices_) {
|
|
||||||
|
for (auto &adv : _beginning_advices) {
|
||||||
adv();
|
adv();
|
||||||
}
|
}
|
||||||
beginningAdvices_.clear();
|
|
||||||
|
_beginning_advices.clear();
|
||||||
});
|
});
|
||||||
getLoop()->loop();
|
|
||||||
*/
|
get_loop()->loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWebApplication::stop() {
|
void DWebApplication::stop() {
|
||||||
@ -448,6 +476,7 @@ void DWebApplication::set_implicit_page_enable(bool useImplicitPage) {
|
|||||||
}
|
}
|
||||||
bool DWebApplication::is_implicit_page_enabled() const {
|
bool DWebApplication::is_implicit_page_enabled() const {
|
||||||
//return staticFileRouterPtr_->isImplicitPageEnabled();
|
//return staticFileRouterPtr_->isImplicitPageEnabled();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
void DWebApplication::set_implicit_page(const std::string &implicitPageFile) {
|
void DWebApplication::set_implicit_page(const std::string &implicitPageFile) {
|
||||||
//staticFileRouterPtr_->setImplicitPage(implicitPageFile);
|
//staticFileRouterPtr_->setImplicitPage(implicitPageFile);
|
||||||
@ -455,6 +484,8 @@ void DWebApplication::set_implicit_page(const std::string &implicitPageFile) {
|
|||||||
|
|
||||||
const std::string &DWebApplication::get_implicit_page() const {
|
const std::string &DWebApplication::get_implicit_page() const {
|
||||||
//return staticFileRouterPtr_->getImplicitPage();
|
//return staticFileRouterPtr_->getImplicitPage();
|
||||||
|
static std::string s = "";
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
size_t DWebApplication::get_client_max_body_size() const {
|
size_t DWebApplication::get_client_max_body_size() const {
|
||||||
return _client_max_body_size;
|
return _client_max_body_size;
|
||||||
@ -493,9 +524,7 @@ const std::pair<unsigned int, std::string> &DWebApplication::get_float_precision
|
|||||||
}
|
}
|
||||||
|
|
||||||
trantor::EventLoop *DWebApplication::get_loop() const {
|
trantor::EventLoop *DWebApplication::get_loop() const {
|
||||||
static trantor::EventLoop loop;
|
return _loop;
|
||||||
|
|
||||||
return &loop;
|
|
||||||
}
|
}
|
||||||
trantor::EventLoop *DWebApplication::get_io_loop(size_t id) const {
|
trantor::EventLoop *DWebApplication::get_io_loop(size_t id) const {
|
||||||
assert(_listener_manager);
|
assert(_listener_manager);
|
||||||
@ -635,6 +664,8 @@ void DWebApplication::on_new_websock_request(const HttpRequestImplPtr &req, std:
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
void DWebApplication::on_connection(const trantor::TcpConnectionPtr &conn) {
|
void DWebApplication::on_connection(const trantor::TcpConnectionPtr &conn) {
|
||||||
|
LOG_INFO << "on_connection";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static std::mutex mtx;
|
static std::mutex mtx;
|
||||||
LOG_TRACE << "connect!!!" << maxConnectionNum_
|
LOG_TRACE << "connect!!!" << maxConnectionNum_
|
||||||
@ -652,7 +683,7 @@ void DWebApplication::on_connection(const trantor::TcpConnectionPtr &conn) {
|
|||||||
if (iter == connectionsNumMap_.end()) {
|
if (iter == connectionsNumMap_.end()) {
|
||||||
connectionsNumMap_[conn->peerAddr().toIp()] = 1;
|
connectionsNumMap_[conn->peerAddr().toIp()] = 1;
|
||||||
} else if (iter->second++ > maxConnectionNumPerIP_) {
|
} else if (iter->second++ > maxConnectionNumPerIP_) {
|
||||||
conn->getLoop()->queueInLoop(
|
conn->get_loop()->queueInLoop(
|
||||||
[conn]() { conn->forceClose(); });
|
[conn]() { conn->forceClose(); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -703,9 +734,10 @@ void DWebApplication::find_session_for_request(const HttpRequestImplPtr &req) {
|
|||||||
//void forward(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,const std::string &hostString,double timeout);
|
//void forward(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,const std::string &hostString,double timeout);
|
||||||
//void forward(const HttpRequestImplPtr &req,std::function<void(const HttpResponsePtr &)> &&callback,const std::string &hostString,double timeout = 0);
|
//void forward(const HttpRequestImplPtr &req,std::function<void(const HttpResponsePtr &)> &&callback,const std::string &hostString,double timeout = 0);
|
||||||
|
|
||||||
DWebApplication::DWebApplication() : _listener_manager(new ListenerManager()) {
|
DWebApplication::DWebApplication() :
|
||||||
//staticFileRouterPtr_(new StaticFileRouter{}),
|
_listener_manager(new ListenerManager()) {
|
||||||
/*
|
//staticFileRouterPtr_(new StaticFileRouter{}),
|
||||||
|
/*
|
||||||
httpCtrlsRouterPtr_(new HttpControllersRouter(*staticFileRouterPtr_,
|
httpCtrlsRouterPtr_(new HttpControllersRouter(*staticFileRouterPtr_,
|
||||||
postRoutingAdvices_,
|
postRoutingAdvices_,
|
||||||
postRoutingObservers_,
|
postRoutingObservers_,
|
||||||
@ -719,19 +751,19 @@ DWebApplication::DWebApplication() : _listener_manager(new ListenerManager()) {
|
|||||||
preHandlingAdvices_,
|
preHandlingAdvices_,
|
||||||
preHandlingObservers_,
|
preHandlingObservers_,
|
||||||
postHandlingAdvices_)),*/
|
postHandlingAdvices_)),*/
|
||||||
//websockCtrlsRouterPtr_(
|
//websockCtrlsRouterPtr_(
|
||||||
// new WebsocketControllersRouter(postRoutingAdvices_,
|
// new WebsocketControllersRouter(postRoutingAdvices_,
|
||||||
// postRoutingObservers_)),
|
// postRoutingObservers_)),
|
||||||
//listenerManagerPtr_(new ListenerManager),
|
//listenerManagerPtr_(new ListenerManager),
|
||||||
//pluginsManagerPtr_(new PluginsManager),
|
//pluginsManagerPtr_(new PluginsManager),
|
||||||
//uploadPath_(rootPath_ + "uploads") {
|
//uploadPath_(rootPath_ + "uploads") {
|
||||||
|
|
||||||
|
_loop = new trantor::EventLoop();
|
||||||
|
|
||||||
//_listener_manager = new ListenerManager();
|
//_listener_manager = new ListenerManager();
|
||||||
_upload_path = _root_path + "uploads";
|
_upload_path = _root_path + "uploads";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DWebApplication::~DWebApplication() {
|
DWebApplication::~DWebApplication() {
|
||||||
main_route_map.clear();
|
main_route_map.clear();
|
||||||
error_handler_map.clear();
|
error_handler_map.clear();
|
||||||
|
@ -11,15 +11,15 @@
|
|||||||
|
|
||||||
#include "handler_instance.h"
|
#include "handler_instance.h"
|
||||||
|
|
||||||
#include <trantor/utils/Logger.h>
|
|
||||||
#include <trantor/net/InetAddress.h>
|
#include <trantor/net/InetAddress.h>
|
||||||
#include <trantor/net/Resolver.h>
|
#include <trantor/net/Resolver.h>
|
||||||
|
#include <trantor/utils/Logger.h>
|
||||||
|
|
||||||
#include "http/HttpRequestImpl.h"
|
#include "http/HttpRequestImpl.h"
|
||||||
#include "http/HttpResponse.h"
|
#include "http/HttpResponse.h"
|
||||||
|
|
||||||
#include "./drogon/lib/src/impl_forwards.h"
|
|
||||||
#include "./drogon/lib/src/ListenerManager.h"
|
#include "./drogon/lib/src/ListenerManager.h"
|
||||||
|
#include "./drogon/lib/src/impl_forwards.h"
|
||||||
|
|
||||||
#include "http/SessionManager.h"
|
#include "http/SessionManager.h"
|
||||||
|
|
||||||
@ -51,9 +51,11 @@ public:
|
|||||||
void unregister_request_update(DRequest *request);
|
void unregister_request_update(DRequest *request);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
//-------
|
//-------
|
||||||
|
|
||||||
void add_listener(const std::string &ip, uint16_t port, bool useSSL, const std::string &certFile, const std::string &keyFile, bool useOldTLS, const std::vector<std::pair<std::string, std::string> > &sslConfCmds);
|
void add_listener(const std::string &ip, uint16_t port,
|
||||||
|
bool useSSL = false, const std::string &certFile = "", const std::string &keyFile = "", bool useOldTLS = false,
|
||||||
|
const std::vector<std::pair<std::string, std::string> > &sslConfCmds = {});
|
||||||
|
|
||||||
void set_thread_num(size_t thread_num);
|
void set_thread_num(size_t thread_num);
|
||||||
size_t get_thread_num() const;
|
size_t get_thread_num() const;
|
||||||
@ -185,11 +187,11 @@ protected:
|
|||||||
size_t _session_timeout{ 0 };
|
size_t _session_timeout{ 0 };
|
||||||
size_t _idle_connection_timeout{ 60 };
|
size_t _idle_connection_timeout{ 60 };
|
||||||
bool _use_session{ false };
|
bool _use_session{ false };
|
||||||
std::string _server_header { "server: rcpp_framework\r\n" };
|
std::string _server_header{ "server: rcpp_framework\r\n" };
|
||||||
|
|
||||||
std::string _root_path { "./" };
|
std::string _root_path{ "./" };
|
||||||
std::string _upload_path;
|
std::string _upload_path;
|
||||||
std::atomic_bool _running { false };
|
std::atomic_bool _running{ false };
|
||||||
|
|
||||||
size_t _thread_num{ 1 };
|
size_t _thread_num{ 1 };
|
||||||
|
|
||||||
@ -213,7 +215,7 @@ protected:
|
|||||||
bool _use_brotli{ false };
|
bool _use_brotli{ false };
|
||||||
bool _using_unicode_escaping{ true };
|
bool _using_unicode_escaping{ true };
|
||||||
|
|
||||||
std::pair<unsigned int, std::string> _float_precision_in_json { 0, "significant" };
|
std::pair<unsigned int, std::string> _float_precision_in_json{ 0, "significant" };
|
||||||
|
|
||||||
size_t _client_max_body_size{ 1024 * 1024 };
|
size_t _client_max_body_size{ 1024 * 1024 };
|
||||||
size_t _client_max_memory_body_size{ 64 * 1024 };
|
size_t _client_max_memory_body_size{ 64 * 1024 };
|
||||||
@ -226,6 +228,12 @@ protected:
|
|||||||
bool _enable_server_header{ true };
|
bool _enable_server_header{ true };
|
||||||
bool _enable_date_header{ true };
|
bool _enable_date_header{ true };
|
||||||
bool _reuse_port{ false };
|
bool _reuse_port{ false };
|
||||||
|
|
||||||
|
trantor::EventLoop *_loop;
|
||||||
|
|
||||||
|
std::vector<std::function<void()> > _beginning_advices;
|
||||||
|
std::vector<std::function<HttpResponsePtr(const HttpRequestPtr &)> > _sync_advices;
|
||||||
|
std::vector<std::function<void(const HttpRequestPtr &, const HttpResponsePtr &)> > _pre_sending_advices;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user