Modify some comments

This commit is contained in:
antao 2019-03-06 15:57:05 +08:00
parent 2e24d8c7f5
commit b39dd52a87
21 changed files with 92 additions and 85 deletions

View File

@ -9,24 +9,24 @@
Drogon's main application platform is Linux. It also supports Mac OS and FreeBSD. Currently, it does not support windows. Its main features are as follows:
* The network layer uses a NIO framework based on epoll (kqueue under MacOS/FreeBSD) to provide high-concurrency, high-performance network IO;
* Full asynchronous programming mode;
* Use a NIO network lib based on epoll (kqueue under MacOS/FreeBSD) to provide high-concurrency, high-performance network IO, For details, please visit the [benchmarks](https://github.com/an-tao/drogon/wiki/benchmarks) page for more details;
* Provide a completely asynchronous programming mode;
* Support Http1.0/1.1 (server side and client side);
* Based on template, a simple reflection mechanism is implemented to completely decouple the main program framework, controller and view.
* Support for cookies and built-in sessions;
* Based on template, a simple reflection mechanism is implemented to completely decouple the main program framework, controllers and views.
* Support cookies and built-in sessions;
* Support back-end rendering, the controller generates the data to the view to generate the Html page, the view is described by a "JSP-like" CSP file, the C++ code is embedded into the Html page by the CSP tag, and the drogon command-line tool automatically generates the C++ code file for compilation;
* Support view page dynamic loading (dynamic compilation and loading at runtime);
* A very convenient and flexible path to controller handler mapping scheme;
* Support filter chain to facilitate the execution of unified logic (such as login verification, Http Method constraint verification, etc.) before the controller;
* Provide a convenient and flexible routing solution from the path to the controller handler;
* Support filter chains to facilitate the execution of unified logic (such as login verification, Http Method constraint verification, etc.) before controllers;
* Support https (based on OpenSSL);
* Support WebSocket (server side);
* Support JSON format request and response, very friendly to the Restful API application development;
* Support file download and upload;
* Support gzip compression transmission;
* Provides a lightweight command line tool, drogon_ctl, to simplify the creation of various classes in Drogon and the generation of view code;
* Asynchronous database read and write based on NIO, currently supports PostgreSQL and MySQL (MariaDB) database;
* Asynchronously read and write sqlite3 database based on the thread pool, providing the same interfaces as above databases;
* Convenient lightweight ORM implementation that supports regular object-to-database bidirectional mapping;
* Support pipelining;
* Provide a lightweight command line tool, drogon_ctl, to simplify the creation of various classes in Drogon and the generation of view code;
* Support NIO-based asynchronously reading and writing database (PostgreSQL and MySQL(MariaDB) database);
* Support asynchronously reading and writing sqlite3 database based on thread pool;
* Provide a convenient lightweight ORM implementation that supports for regular object-to-database bidirectional mapping;
### For more information, please visit the [wiki](https://github.com/an-tao/drogon/wiki)
### For more information, please visit the [wiki](https://github.com/an-tao/drogon/wiki) site

View File

@ -24,6 +24,7 @@ Drogon的主要应用平台是Linux也支持Mac OS、FreeBSD目前还不
* 支持Json格式请求和应答, 对Restful API应用开发非常友好;
* 支持文件下载和上传,支持sendfile系统调用
* 支持gzip压缩传输
* 支持pipelining
* 提供一个轻量的命令行工具drogon_ctl帮助简化各种类的创建和视图代码的生成过程
* 基于NIO实现的异步数据库读写目前支持PostgreSQL和MySQL(MariaDB)数据库;
* 基于线程池实现sqlite3数据库的异步读写提供与上文数据库相同的接口

View File

@ -1,22 +1,22 @@
#!/bin/bash
#building drogon
#build drogon
function build_drogon() {
#Update the submodule and initialize
git submodule update --init
#Saving current directory
#Save current directory
current_dir="${PWD}"
#The folder we will build
#The folder in which we will build drogon
build_dir='./build'
if [ -d $build_dir ]; then
echo "Deleted folder: ${build_dir}"
rm -rf $build_dir
fi
#Creating building folder
#Create building folder
echo "Created building folder: ${build_dir}"
mkdir $build_dir
@ -41,7 +41,7 @@ function build_drogon() {
echo "Installing ..."
sudo make install
#Reback current directory
#Go back to the current directory
cd $current_dir
#Ok!
}

View File

@ -50,7 +50,7 @@
],*/
"app": {
//threads_num: The number of IO threads,1 by default, if the value is set to 0, the number of threads
//will be the number of processors.
//is the number of processors.
"threads_num": 1,
//enable_session: False by default
"enable_session": true,
@ -59,7 +59,7 @@
"document_root": "./",
//upload_path: The path to save the uploaded file. "uploads" by default.
//If the path isn't prefixed with /, ./ or ../,
//it will be relative path of document_root path
//it is relative path of document_root path
"upload_path": "uploads",
/* file_types:
* HTTP download file types,The file types supported by drogon
@ -84,22 +84,22 @@
"max_connections": 100000,
//max_connections_per_ip: Max connections number per clinet,0 by default which means no limit
"max_connections_per_ip": 0,
//Load_dynamic_views: False by default, when set to true, drogon will
//compile and load dynamically "CSP View Files" in directories defined
//Load_dynamic_views: False by default, when set to true, drogon
//compiles and loads dynamically "CSP View Files" in directories defined
//by "dynamic_views_path"
"load_dynamic_views":false,
//dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
//it will be relative path of document_root path
//it is relative path of document_root path
"dynamic_views_path":["./views"],
//log: Set log output, drogon output logs to stdout by default
"log": {
//log_path: Log file path,empty by default,in which case,log will output to the stdout
//log_path: Log file path,empty by default,in which case,logs are output to the stdout
//"log_path": "./",
//logfile_base_name: Log file base name,empty by default which means drogon will name logfile as
//logfile_base_name: Log file base name,empty by default which means drogon names logfile as
//drogon.log ...
"logfile_base_name": "",
//log_size_limit: 100000000 bytes by default,
//When the log file size reaches "log_size_limit", the log file will be switched.
//When the log file size reaches "log_size_limit", the log file is switched.
"log_size_limit": 100000000,
//log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
//The TRACE level is only valid when built in DEBUG mode.
@ -109,10 +109,10 @@
"run_as_daemon": false,
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
"relaunch_on_error": false,
//use_sendfile: True by default, if ture, the program will
//use sendfile() system-call to send static file to the client;
//use_sendfile: True by default, if ture, the program
//uses sendfile() system-call to send static files to clients;
"use_sendfile": true,
//use_gzip: True by default,use gzip to compress the response body's content;
//use_gzip: True by default, use gzip to compress the response body's content;
"use_gzip": true,
//static_files_cache_time: 5 (seconds) by default,the time in which static file response is cached,
//0 means cache forever, the negative value means no cache
@ -137,7 +137,7 @@
//enable_fast_db_client: Defaults to false
"enable_fast_db_client": false,
//server_header_field: Set the 'server' header field in each response sent by drogon,
//empty string by default with which the 'server' header field will be "Server: drogon/version string\r\n"
//empty string by default with which the 'server' header field is set to "Server: drogon/version string\r\n"
"server_header_field": ""
}
}

View File

@ -206,10 +206,10 @@ void create_controller::newHttpControllerHeaderFile(std::ofstream &file, const s
file << indent << "METHOD_LIST_BEGIN\n";
file << indent << "//use METHOD_ADD to add your custom processing function here;\n";
file << indent << "//METHOD_ADD(" << class_name << "::get,\"/get/{2}/{1}\",Get);"
"//path will be "
"//path is "
<< namepace_path << class_name << "/get/{arg2}/{arg1}\n";
file << indent << "//METHOD_ADD(" << class_name << "::your_method_name,\"/{1}/{2}/list\",Get);"
"//path will be "
"//path is "
<< namepace_path << class_name << "/{arg1}/{arg2}/list\n";
file << indent << "\n";
file << indent << "METHOD_LIST_END\n";

View File

@ -50,7 +50,7 @@
],*/
"app": {
//threads_num: The number of IO threads,1 by default, if the value is set to 0, the number of threads
//will be the number of processors.
//is the number of processors.
"threads_num": 1,
//enable_session: False by default
"enable_session": true,
@ -59,7 +59,7 @@
"document_root": "./",
//upload_path: The path to save the uploaded file. "uploads" by default.
//If the path isn't prefixed with /, ./ or ../,
//it will be relative path of document_root path
//it is relative path of document_root path
"upload_path": "uploads",
/* file_types:
* HTTP download file types,The file types supported by drogon
@ -84,22 +84,22 @@
"max_connections": 100000,
//max_connections_per_ip: Max connections number per clinet,0 by default which means no limit
"max_connections_per_ip": 0,
//Load_dynamic_views: False by default, when set to true, drogon will
//compile and load dynamically "CSP View Files" in directories defined
//Load_dynamic_views: False by default, when set to true, drogon
//compiles and loads dynamically "CSP View Files" in directories defined
//by "dynamic_views_path"
"load_dynamic_views":false,
//dynamic_views_path: If the path isn't prefixed with /, ./ or ../,
//it will be relative path of document_root path
//it is relative path of document_root path
"dynamic_views_path":["./views"],
//log: Set log output, drogon output logs to stdout by default
"log": {
//log_path: Log file path,empty by default,in which case,log will output to the stdout
//log_path: Log file path,empty by default,in which case,logs are output to the stdout
//"log_path": "./",
//logfile_base_name: Log file base name,empty by default which means drogon will name logfile as
//logfile_base_name: Log file base name,empty by default which means drogon names logfile as
//drogon.log ...
"logfile_base_name": "",
//log_size_limit: 100000000 bytes by default,
//When the log file size reaches "log_size_limit", the log file will be switched.
//When the log file size reaches "log_size_limit", the log file is switched.
"log_size_limit": 100000000,
//log_level: "DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
//The TRACE level is only valid when built in DEBUG mode.
@ -109,10 +109,10 @@
"run_as_daemon": false,
//relaunch_on_error: False by default, if true, the program will be restart by the parent after exiting;
"relaunch_on_error": false,
//use_sendfile: True by default, if ture, the program will
//use sendfile() system-call to send static file to the client;
//use_sendfile: True by default, if ture, the program
//uses sendfile() system-call to send static files to clients;
"use_sendfile": true,
//use_gzip: True by default,use gzip to compress the response body's content;
//use_gzip: True by default, use gzip to compress the response body's content;
"use_gzip": true,
//static_files_cache_time: 5 (seconds) by default,the time in which static file response is cached,
//0 means cache forever, the negative value means no cache
@ -137,7 +137,7 @@
//enable_fast_db_client: Defaults to false
"enable_fast_db_client": false,
//server_header_field: Set the 'server' header field in each response sent by drogon,
//empty string by default with which the 'server' header field will be "Server: drogon/version string\r\n"
//empty string by default with which the 'server' header field is set to "Server: drogon/version string\r\n"
"server_header_field": ""
}
}

View File

@ -8,7 +8,7 @@ class Attachment : public drogon::HttpController<Attachment>
public:
METHOD_LIST_BEGIN
//use METHOD_ADD to add your custom processing function here;
METHOD_ADD(Attachment::get, "", Get); //Path will be '/api/attachment'
METHOD_ADD(Attachment::get, "", Get); //Path is '/api/attachment'
METHOD_ADD(Attachment::upload, "/upload", Post);
METHOD_ADD(Attachment::download, "/download", Get);
METHOD_LIST_END

View File

@ -12,8 +12,8 @@ class ApiTest : public drogon::HttpController<ApiTest>
//use METHOD_ADD to add your custom processing function here;
METHOD_ADD(ApiTest::rootGet, "", "TimeFilter", Get, "drogon::LocalHostFilter", "drogon::InnerIpFilter");
METHOD_ADD(ApiTest::rootPost, "", Post);
METHOD_ADD(ApiTest::get, "/get/{2}/{1}", Get); //path will be /api/v1/apitest/get/{arg2}/{arg1}
METHOD_ADD(ApiTest::your_method_name, "/{1}/List?P2={2}", Get); //path will be /api/v1/apitest/{arg1}/list
METHOD_ADD(ApiTest::get, "/get/{2}/{1}", Get); //path is /api/v1/apitest/get/{arg2}/{arg1}
METHOD_ADD(ApiTest::your_method_name, "/{1}/List?P2={2}", Get); //path is /api/v1/apitest/{arg1}/list
METHOD_ADD(ApiTest::staticApi, "/static", Get, Post);
METHOD_ADD(ApiTest::get2, "/get/{1}", Get);
METHOD_ADD(ApiTest::jsonTest, "/json", Post);

View File

@ -63,8 +63,8 @@ class Test : public HttpController<Test>
{
public:
METHOD_LIST_BEGIN
METHOD_ADD(Test::get, "get/{2}/{1}", Get); //path will be /api/v1/test/get/{arg2}/{arg1}
METHOD_ADD(Test::list, "/{2}/info", Get); //path will be /api/v1/test/{arg2}/info
METHOD_ADD(Test::get, "get/{2}/{1}", Get); //path is /api/v1/test/get/{arg2}/{arg1}
METHOD_ADD(Test::list, "/{2}/info", Get); //path is /api/v1/test/{arg2}/info
METHOD_LIST_END
void get(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int p1, int p2) const
{

View File

@ -61,7 +61,7 @@ class HttpAppFramework : public trantor::NonCopyable
///Get the instance of HttpAppFramework
/**
* HttpAppFramework works at singleton mode, so any calling of this
* method will get the same instance;
* method gets the same instance;
* Calling drogon::HttpAppFramework::instance()
* can be replaced by a simple interface -- drogon::app()
*/
@ -69,7 +69,7 @@ class HttpAppFramework : public trantor::NonCopyable
///Run the event loop
/**
* Calling this method will start the IO event loops and the main loop of the application;
* Calling this method starts the IO event loops and the main loop of the application;
* Usually, the thread that calls this method is the main thread of the application;
* If the loop() method is called before this method, it must be called from the thread
* that first calls the loop () method.
@ -82,7 +82,7 @@ class HttpAppFramework : public trantor::NonCopyable
///Quit the event loop
/**
* Calling this method will result in stopping all network IO in the
* Calling this method results 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.
*

View File

@ -41,11 +41,11 @@ typedef std::shared_ptr<HttpClient> HttpClientPtr;
* HttpClient implementation object uses the HttpAppFramework's event loop by default,
* so you should call app().run() to make the client work.
* Each HttpClient object establishes a persistent connection with the server.
* If the connection is broken, the client will attempt to reconnect
* If the connection is broken, the client attempts to reconnect
* when calling the sendRequest method.
*
* Using the static mathod newHttpClient(...) to get shared_ptr of the object implementing
* the class, the shared_ptr will be retained in the framework until all response callbacks
* the class, the shared_ptr is retained in the framework until all response callbacks
* are invoked without fear of accidental deconstruction.
*
* TODO:SSL server verification
@ -55,19 +55,19 @@ class HttpClient : public trantor::NonCopyable
public:
/// Send a request asynchronously to the server
/**
* The response from the http server will be obtained
* The response from the http server is obtained
* in the callback function.
*/
virtual void sendRequest(const HttpRequestPtr &req, const HttpReqCallback &callback) = 0;
virtual void sendRequest(const HttpRequestPtr &req, HttpReqCallback &&callback) = 0;
/// Use ip and port to connect to server
/**
* If useSSL is set to true, the client will
* connect to the server using https.
* If useSSL is set to true, the client
* connects to the server using https.
*
* If the loop parameter is set to nullptr, the client will
* use the HttpAppFramework's event loop, otherwise it will
* run in the loop identified by the parameter.
* If the loop parameter is set to nullptr, the client
* uses the HttpAppFramework's event loop, otherwise it
* runs in the loop identified by the parameter.
*/
static HttpClientPtr newHttpClient(const std::string &ip,
uint16_t port,
@ -85,9 +85,9 @@ class HttpClient : public trantor::NonCopyable
* https://127.0.0.1:8080/
* http://127.0.0.1
*
* If the loop parameter is set to nullptr, the client will
* use the HttpAppFramework's event loop, otherwise it will
* run in the loop identified by the parameter.
* If the loop parameter is set to nullptr, the client
* uses the HttpAppFramework's event loop, otherwise it
* runs in the loop identified by the parameter.
*
* NOTE:
* Don't add path and parameters in hostString, the request path

View File

@ -118,22 +118,26 @@ class HttpRequest
/// Create a normal request with http method Get and version Http1.1.
static HttpRequestPtr newHttpRequest();
/// Create a http request with:
/// Method: Get
/// Version: Http1.1
/// Content type: application/json, the @param data will be serialized into the content of the request.
/// Content type: application/json, the @param data is serialized into the content of the request.
static HttpRequestPtr newHttpJsonRequest(const Json::Value &data);
/// Create a http request with:
/// Method: Post
/// Version: Http1.1
/// Content type: application/x-www-form-urlencoded
static HttpRequestPtr newHttpFormPostRequest();
/// Create a http file upload request with:
/// Method: Post
/// Version: Http1.1
/// Content type: multipart/form-data
/// The @param files represents pload files which will be transferred to the server via the multipart/form-data format
/// The @param files represents pload files which are transferred to the server via the multipart/form-data format
static HttpRequestPtr newFileUploadRequest(const std::vector<UploadFile> &files);
virtual ~HttpRequest() {}
};

View File

@ -46,8 +46,9 @@ class HttpResponse
/// Set the http version, http1.0 or http1.1
virtual void setVersion(const Version v) = 0;
/// If @param on is false, the connection will keep alive on the condition that the client request has a
// 'keep-alive' head, otherwise it will be closed. It's false by default when the reponse is created.
/// If @param on is false, the connection keeps alive on the condition that the client request has a
// 'keep-alive' head, otherwise it is closed immediately after sending the last byte of the response.
// It's false by default when the response is created.
virtual void setCloseConnection(bool on) = 0;
/// Get the status set by the setCloseConnetion() method.
@ -63,7 +64,8 @@ class HttpResponse
/// Get the response content type.
virtual ContentType getContentTypeCode() = 0;
/// Get the header string identified by the @param key. If there is no the header, the @param defaultVal will be retured.
/// Get the header string identified by the @param key.
/// If there is no the header, the @param defaultVal is retured.
/// The @param key is case insensitive
virtual const std::string &getHeader(const std::string &key, const std::string &defaultVal = std::string()) const = 0;
virtual const std::string &getHeader(std::string &&key, const std::string &defaultVal = std::string()) const = 0;
@ -76,7 +78,8 @@ class HttpResponse
virtual void addCookie(const std::string &key, const std::string &value) = 0;
virtual void addCookie(const Cookie &cookie) = 0;
/// Get the cookie identified by the @param key. If there is no the cookie, the @param defaultCookie will be retured.
/// Get the cookie identified by the @param key. If there is no the cookie,
/// If there is no the cookie, the @param defaultCookie is retured.
virtual const Cookie &getCookie(const std::string &key, const Cookie &defaultCookie = Cookie()) const = 0;
/// Get all cookies.
@ -103,8 +106,8 @@ class HttpResponse
/// Get the expiration time of the response.
virtual ssize_t expiredTime() const = 0;
/// Get the json object from the server response. If the response is not in json format,
/// then a empty shared_ptr will be retured.
/// Get the json object from the server response.
/// If the response is not in json format, then a empty shared_ptr is be retured.
virtual const std::shared_ptr<Json::Value> getJsonObject() const = 0;
/// The following methods are a series of factory methods that help users create response objects.
@ -125,7 +128,7 @@ class HttpResponse
/**
* @param fullPath is the full path to the file.
* If @param attachmentFileName is not empty, the browser does not open the file, but saves it as an attachment.
* If the @param type is CT_NONE, the content type will be set by drogon based on the file extension.
* If the @param type is CT_NONE, the content type is set by drogon based on the file extension.
*/
static HttpResponsePtr newFileResponse(const std::string &fullPath, const std::string &attachmentFileName = "", ContentType type = CT_NONE);

View File

@ -60,7 +60,7 @@ class HttpViewData
_viewData[key] = obj;
}
/// Insert an item identified by the @param key into the data set; The item will be converted to a string.
/// Insert an item identified by the @param key into the data set; The item is converted to a string.
template <typename T>
void insertAsString(const std::string &key, T &&val)
{

View File

@ -47,7 +47,7 @@ class HttpFile
/**
* If the @param path is prefixed with "/", "./" or "../", or the @param path is
* "." or "..", the full path is @param path+"/"+this->getFileName(), otherwise
* the file will be saved as app().getUploadPath()+"/"+@param path+"/"+this->getFileName()
* the file is saved as app().getUploadPath()+"/"+@param path+"/"+this->getFileName()
*/
int save(const std::string &path) const;
@ -55,7 +55,7 @@ class HttpFile
/**
* If the @param filename isn't prefixed with "/", "./" or "../", the full path is
* app().getUploadPath()+"/"+@param filename, otherwise
* the file will be saved as @param filename
* the file is saved as @param filename
*/
int saveAs(const std::string &filename) const;

View File

@ -24,7 +24,7 @@ class UploadFile
/**
* @param filePath: The file location on local host, including file name.
* @param fileName: The file name provided to the server. If it is empty by default, the file name in the @param filePath
* will be provided to the server.
* is provided to the server.
* @param itemName: The item name on the browser form.
*/
explicit UploadFile(const std::string &filePath, const std::string &fileName = "", const std::string &itemName = "file")

View File

@ -52,7 +52,7 @@ void HttpControllersRouter::addHttpPath(const std::string &path,
const std::vector<HttpMethod> &validMethods,
const std::vector<std::string> &filters)
{
//path will be like /api/v1/service/method/{1}/{2}/xxx...
//Path is like /api/v1/service/method/{1}/{2}/xxx...
std::vector<size_t> places;
std::string tmpPath = path;
std::string paras = "";

View File

@ -28,13 +28,12 @@ void WebSocketConnectionImpl::send(const char *msg, uint64_t len)
auto conn = _tcpConn.lock();
if (conn)
{
//format the frame
//Format the frame
std::string bytesFormatted;
bytesFormatted.resize(len + 10);
bytesFormatted[0] = char(129);
int indexStartRawData = -1;
// set here - it will be set now:
if (len <= 125)
{

View File

@ -57,10 +57,10 @@ class ArrayParser
/// Parse the next step in the array.
/** Returns what it found. If the juncture is @c string_value, the string
* will contain the value. Otherwise, it will be empty.
*
* Call this until the @c juncture it returns is @c done.
*/
* will contain the value. Otherwise, it will be empty.
*
* Call this until the @c juncture it returns is @c done.
*/
std::pair<juncture, std::string> getNext();
private:

View File

@ -143,7 +143,7 @@ class DbClient : public trantor::NonCopyable
* NOTE:
* The callback only indicates the result of the 'commit' command, which is the last
* step of the transaction. If the transaction has been automatically or manually rolled back,
* the callback will not be executed.
* the callback will never be executed.
* You can also use the setCommitCallback() method of a transaction object to set the callback.
*/
virtual std::shared_ptr<Transaction> newTransaction(const std::function<void(bool)> &commitCallback = nullptr) = 0;

View File

@ -35,7 +35,7 @@ const char *PostgreSQLResultImpl::columnName(row_size_type number) const
assert(N);
return N;
}
throw "nullptr result"; //The program will not execute here
throw "nullptr result"; //The program will never execute here
}
Result::size_type PostgreSQLResultImpl::affectedRows() const noexcept
{
@ -54,7 +54,7 @@ Result::row_size_type PostgreSQLResultImpl::columnNumber(const char colName[]) c
throw std::string("there is no column named ") + colName; // TODO throw detail exception here;
return N;
}
throw "nullptr result"; //The program will not execute here
throw "nullptr result"; //The program will never execute here
}
const char *PostgreSQLResultImpl::getValue(size_type row, row_size_type column) const
{