Skip to content

Commit

Permalink
Merge pull request #12 from tearshark/master
Browse files Browse the repository at this point in the history
io_server_inplace范例
  • Loading branch information
qicosmos authored Feb 28, 2018
2 parents 6609b3b + fcd69f1 commit 7156fa2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,37 @@ cinatra目前支持了multipart和octet-stream格式的上传。
return 0;
}

## 示例7:io_service_inplace
本代码演示如何使用io_service_inplace,然后自己控制http server的运行线程以及循环。
使用 [http://[::1]:8080/close] (IPv6) 或者 [http://127.0.0.1:8080/close] (IPv4) 来关闭http server。

#include "http_server.hpp"
using namespace cinatra;

int main() {

bool is_running = true;
http_server_<io_service_inplace> server;
server.listen("8080");

server.set_http_handler<GET, POST>("/", [](const request& req, response& res) {
res.set_status_and_content(status_type::ok, "hello world");
});

server.set_http_handler<GET, POST>("/close", [&](const request& req, response& res) {
res.set_status_and_content(status_type::ok, "will close");

is_running = false;
server.stop();
});

while(is_running)
server.poll_one();

return 0;
}


# 性能测试
## 测试用例:

Expand Down

0 comments on commit 7156fa2

Please sign in to comment.