Add the quit() method to HttpAppFramework

This commit is contained in:
an-tao 2018-11-17 00:10:15 +08:00
parent 2f6448e6b2
commit 6698929a70
3 changed files with 46 additions and 13 deletions

View File

@ -61,7 +61,35 @@ inline std::string getGitCommit()
class HttpAppFramework : public trantor::NonCopyable
{
public:
///Get the instance of HttpAppFramework
/**
* HttpAppFramework works at singleton mode, so any calling of this
* method will get the same instance;
* Calling drogon::HttpAppFramework::instance()
* can be replaced by a simple interface -- drogon::app()
*/
static HttpAppFramework &instance();
///Run the event loop
/**
* Calling this method will start the event loop which drive the network;
* The thread calling this method must be the first thread to call instance() method;
* Usually the thread calling this method is main thread of the application;
*/
virtual void run() = 0;
///Quit the event loop
/**
* Calling this method will result in stopping all network IO in the
* framework and interrupting the blocking of the run() method. Usually,
* after calling this method, the application will exit.
*
* NOTE:
* This method can be called in any thread and anywhere.
* This method should not be called before calling run().
*/
virtual void quit() = 0;
virtual void setThreadNum(size_t threadNum) = 0;
virtual void setSSLFiles(const std::string &certPath,
const std::string &keyPath) = 0;
@ -70,7 +98,7 @@ class HttpAppFramework : public trantor::NonCopyable
bool useSSL = false,
const std::string &certFile = "",
const std::string &keyFile = "") = 0;
virtual void run() = 0;
virtual ~HttpAppFramework();
virtual void registerWebSocketController(const std::string &pathName,
const std::string &crtlName,
@ -81,8 +109,8 @@ class HttpAppFramework : public trantor::NonCopyable
const std::vector<any> &filtersAndMethods = std::vector<any>()) = 0;
template <typename FUNCTION>
void registerHttpMethod(const std::string &pathPattern,
FUNCTION &&function,
const std::vector<any> &filtersAndMethods = std::vector<any>())
FUNCTION &&function,
const std::vector<any> &filtersAndMethods = std::vector<any>())
{
LOG_TRACE << "pathPattern:" << pathPattern;
HttpBinderBasePtr binder;
@ -154,9 +182,9 @@ class HttpAppFramework : public trantor::NonCopyable
private:
virtual void registerHttpController(const std::string &pathPattern,
const HttpBinderBasePtr &binder,
const std::vector<HttpMethod> &validMethods = std::vector<HttpMethod>(),
const std::vector<std::string> &filters = std::vector<std::string>()) = 0;
const HttpBinderBasePtr &binder,
const std::vector<HttpMethod> &validMethods = std::vector<HttpMethod>(),
const std::vector<std::string> &filters = std::vector<std::string>()) = 0;
};
inline HttpAppFramework &app()

View File

@ -85,6 +85,11 @@ class HttpAppFrameworkImpl : public HttpAppFramework
}
trantor::EventLoop *loop();
virtual void quit() override
{
assert(_loop.isRunning());
_loop.quit();
}
#if USE_POSTGRESQL
virtual orm::DbClientPtr getDbClient(const std::string &name = "default") override;
virtual void createDbClient(const std::string &dbType,
@ -98,9 +103,9 @@ class HttpAppFrameworkImpl : public HttpAppFramework
#endif
private:
virtual void registerHttpController(const std::string &pathPattern,
const HttpBinderBasePtr &binder,
const std::vector<HttpMethod> &validMethods = std::vector<HttpMethod>(),
const std::vector<std::string> &filters = std::vector<std::string>()) override;
const HttpBinderBasePtr &binder,
const std::vector<HttpMethod> &validMethods = std::vector<HttpMethod>(),
const std::vector<std::string> &filters = std::vector<std::string>()) override;
std::vector<std::tuple<std::string, uint16_t, bool, std::string, std::string>> _listeners;
void onAsyncRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback);
@ -112,9 +117,9 @@ class HttpAppFrameworkImpl : public HttpAppFramework
void onConnection(const TcpConnectionPtr &conn);
void readSendFile(const std::string &filePath, const HttpRequestPtr &req, const HttpResponsePtr &resp);
void addHttpPath(const std::string &path,
const HttpBinderBasePtr &binder,
const std::vector<HttpMethod> &validMethods,
const std::vector<std::string> &filters);
const HttpBinderBasePtr &binder,
const std::vector<HttpMethod> &validMethods,
const std::vector<std::string> &filters);
void initRegex();
//if uuid package found,we can use a uuid string as session id;
//set _sessionTimeout=0 to make location session valid forever based on cookies;

@ -1 +1 @@
Subproject commit fe51026dd655621885555aa2eaa155122cadc813
Subproject commit 33cd9c748e5b462714f8d35f29ecb78c2046594a