Reformat source code in libnghttp2_asio.rst

This commit is contained in:
Tatsuhiro Tsujikawa 2014-11-30 21:22:06 +09:00
parent f2cd057e89
commit 30499005f8
1 changed files with 53 additions and 73 deletions

View File

@ -36,15 +36,11 @@ HTTP/2 server looks like this:
using namespace nghttp2::asio_http2; using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server; using namespace nghttp2::asio_http2::server;
int main(int argc, char* argv[]) int main(int argc, char *argv[]) {
{
http2 server; http2 server;
server.listen server.listen("*", 3000, [](const std::shared_ptr<request> &req,
("*", 3000, const std::shared_ptr<response> &res) {
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
res->write_head(200); res->write_head(200);
res->end("hello, world"); res->end("hello, world");
}); });
@ -78,18 +74,14 @@ SSL/TLS.
using namespace nghttp2::asio_http2; using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server; using namespace nghttp2::asio_http2::server;
int main(int argc, char* argv[]) int main(int argc, char *argv[]) {
{
http2 server; http2 server;
server.tls("server.key", "server.crt"); server.tls("server.key", "server.crt");
server.listen server.listen("*", 3000, [](const std::shared_ptr<request> &req,
("*", 3000, const std::shared_ptr<response> &res) {
[](const std::shared_ptr<request>& req, if (req->path() == "/" || req->path() == "/index.html") {
const std::shared_ptr<response>& res)
{
if(req->path() == "/" || req->path() == "/index.html") {
res->write_head(200); res->write_head(200);
res->end(file_reader("index.html")); res->end(file_reader("index.html"));
} else { } else {
@ -124,18 +116,14 @@ Server push is also supported.
using namespace nghttp2::asio_http2; using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server; using namespace nghttp2::asio_http2::server;
int main(int argc, char* argv[]) int main(int argc, char *argv[]) {
{
http2 server; http2 server;
server.tls("server.key", "server.crt"); server.tls("server.key", "server.crt");
server.listen server.listen("*", 3000, [](const std::shared_ptr<request> &req,
("*", 3000, const std::shared_ptr<response> &res) {
[](const std::shared_ptr<request>& req, if (req->path() == "/") {
const std::shared_ptr<response>& res)
{
if(req->path() == "/") {
req->push("GET", "/my.css"); req->push("GET", "/my.css");
res->write_head(200); res->write_head(200);
@ -144,7 +132,7 @@ Server push is also supported.
return; return;
} }
if(req->path() == "/my.css") { if (req->path() == "/my.css") {
res->write_head(200); res->write_head(200);
res->end(file_reader("my.css")); res->end(file_reader("my.css"));
@ -197,20 +185,14 @@ blocking task there. The example follows:
using namespace nghttp2::asio_http2; using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server; using namespace nghttp2::asio_http2::server;
int main(int argc, char* argv[]) int main(int argc, char *argv[]) {
{
http2 server; http2 server;
server.num_concurrent_tasks(16); server.num_concurrent_tasks(16);
server.listen server.listen("*", 3000, [](const std::shared_ptr<request> &req,
("*", 3000, const std::shared_ptr<response> &res) {
[](const std::shared_ptr<request>& req, req->run_task([res](channel &channel) {
const std::shared_ptr<response>& res)
{
req->run_task
([res](channel& channel)
{
// executed in different thread than the thread where // executed in different thread than the thread where
// request callback was executed. // request callback was executed.
@ -219,9 +201,7 @@ blocking task there. The example follows:
sleep(1); sleep(1);
channel.post channel.post([res]() {
([res]()
{
// executed in the same thread where request callback // executed in the same thread where request callback
// was executed. // was executed.
res->write_head(200); res->write_head(200);