diff options
-rw-r--r-- | amalgamate/crow_all.h | 1 | ||||
-rw-r--r-- | examples/websocket/example_ws.cpp | 7 | ||||
-rw-r--r-- | examples/websocket/templates/ws.html | 2 | ||||
-rw-r--r-- | include/crow/http_connection.h | 1 | ||||
-rw-r--r-- | include/crow/http_server.h | 17 | ||||
-rw-r--r-- | include/crow/json.h | 17 |
6 files changed, 38 insertions, 7 deletions
diff --git a/amalgamate/crow_all.h b/amalgamate/crow_all.h index 41b06ff..bc23f58 100644 --- a/amalgamate/crow_all.h +++ b/amalgamate/crow_all.h @@ -8893,6 +8893,7 @@ namespace crow {401, "HTTP/1.1 401 Unauthorized\r\n"}, {403, "HTTP/1.1 403 Forbidden\r\n"}, {404, "HTTP/1.1 404 Not Found\r\n"}, + {422, "HTTP/1.1 422 Unprocessable Entity\r\n"}, {500, "HTTP/1.1 500 Internal Server Error\r\n"}, {501, "HTTP/1.1 501 Not Implemented\r\n"}, diff --git a/examples/websocket/example_ws.cpp b/examples/websocket/example_ws.cpp index ec3603c..e3c1b85 100644 --- a/examples/websocket/example_ws.cpp +++ b/examples/websocket/example_ws.cpp @@ -33,8 +33,13 @@ int main() CROW_ROUTE(app, "/") ([]{ + char name[256]; + gethostname(name, 256); + crow::mustache::context x; + x["servername"] = name; + auto page = crow::mustache::load("ws.html"); - return page.render(); + return page.render(x); }); app.port(40080) diff --git a/examples/websocket/templates/ws.html b/examples/websocket/templates/ws.html index f6e7281..5200b8b 100644 --- a/examples/websocket/templates/ws.html +++ b/examples/websocket/templates/ws.html @@ -11,7 +11,7 @@ <textarea id="log" cols=100 rows=50> </textarea> <script> -var sock = new WebSocket("ws://i.ipkn.me:40080/ws"); +var sock = new WebSocket("ws://{{servername}}:40080/ws"); sock.onopen = ()=>{ console.log('open') } diff --git a/include/crow/http_connection.h b/include/crow/http_connection.h index 96f2d14..3ef8089 100644 --- a/include/crow/http_connection.h +++ b/include/crow/http_connection.h @@ -374,6 +374,7 @@ namespace crow {401, "HTTP/1.1 401 Unauthorized\r\n"}, {403, "HTTP/1.1 403 Forbidden\r\n"}, {404, "HTTP/1.1 404 Not Found\r\n"}, + {422, "HTTP/1.1 422 Unprocessable Entity\r\n"}, {500, "HTTP/1.1 500 Internal Server Error\r\n"}, {501, "HTTP/1.1 501 Not Implemented\r\n"}, diff --git a/include/crow/http_server.h b/include/crow/http_server.h index d5abb11..a247b12 100644 --- a/include/crow/http_server.h +++ b/include/crow/http_server.h @@ -121,12 +121,19 @@ namespace crow timer.async_wait(handler); init_count ++; - try + while(1) { - io_service_pool_[i]->run(); - } catch(std::exception& e) - { - CROW_LOG_ERROR << "Worker Crash: An uncaught exception occurred: " << e.what(); + try + { + if (io_service_pool_[i]->run() == 0) + { + // when io_service.run returns 0, there are no more works to do. + break; + } + } catch(std::exception& e) + { + CROW_LOG_ERROR << "Worker Crash: An uncaught exception occurred: " << e.what(); + } } })); diff --git a/include/crow/json.h b/include/crow/json.h index 891fedf..8b58180 100644 --- a/include/crow/json.h +++ b/include/crow/json.h @@ -1264,6 +1264,23 @@ namespace crow return *this; } + wvalue& operator=(std::vector<wvalue>&& v) + { + if (t_ != type::List) + reset(); + t_ = type::List; + if (!l) + l = std::unique_ptr<std::vector<wvalue>>(new std::vector<wvalue>{}); + l->clear(); + l->resize(v.size()); + size_t idx = 0; + for(auto& x:v) + { + (*l)[idx++] = std::move(x); + } + return *this; + } + template <typename T> wvalue& operator=(const std::vector<T>& v) { |