diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-05 16:20:43 +0300 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2016-07-07 10:08:45 +0200 |
commit | e804523613b4a4131129169643674746b388197f (patch) | |
tree | 41d4f1379c9c21706bf1aa95552ab0ebd93d8b27 | |
parent | ab9c3e0537b99ceaf30c6ad56c84ebf74ca66901 (diff) | |
download | qtlocation-mapboxgl-e804523613b4a4131129169643674746b388197f.tar.gz |
[android] Fix HTTP web server
-rw-r--r-- | test/src/mbgl/test/test.cpp | 2 | ||||
-rw-r--r-- | test/src/mbgl/test/util.cpp | 9 | ||||
-rw-r--r-- | test/src/mbgl/test/util.hpp | 4 |
3 files changed, 7 insertions, 8 deletions
diff --git a/test/src/mbgl/test/test.cpp b/test/src/mbgl/test/test.cpp index 94e3d47ac7..6949d2fb90 100644 --- a/test/src/mbgl/test/test.cpp +++ b/test/src/mbgl/test/test.cpp @@ -8,7 +8,7 @@ namespace mbgl { int runTests(int argc, char *argv[]) { #if TEST_HAS_SERVER std::cout << "Starting server\n"; - util::Thread<test::Server> server({"Webserver"}); + util::Thread<test::Server> server({"Webserver"}, true); server.invokeSync(&test::Server::start); //Sleep so we know the server actually started diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp index b6d4ebcf7f..644b848519 100644 --- a/test/src/mbgl/test/util.cpp +++ b/test/src/mbgl/test/util.cpp @@ -38,7 +38,7 @@ std::string dumpHeaders(const httplib::MultiMap& headers) { return s; } -Server::Server() { +Server::Server(bool) { svr = std::make_unique<httplib::Server>(); #pragma GCC diagnostic push @@ -70,9 +70,8 @@ Server::Server() { //TODO: Don't respond }); - int cacheCounter = 0; - svr->get("/cache", [&cacheCounter](const auto& req, auto& res) { - std::cout << "cache\n"; + svr->get("/cache", [](const auto& req, auto& res) { + static int cacheCounter; res.set_header("Cache-Control", "max-age=30"); res.set_content("Response " + std::to_string(++cacheCounter), "text/plain"); }); @@ -103,7 +102,7 @@ void Server::start() { std::cout << "Starting server on port 3000\n"; //svr->listen("localhost", 3000); //std::cout << "Stopped!!\n"; - f_ = std::async([&](){ + f_ = std::async(std::launch::async, [&](){ up_ = true; svr->listen("localhost", 3000); }); diff --git a/test/src/mbgl/test/util.hpp b/test/src/mbgl/test/util.hpp index 4beb4e9e12..f658a341f1 100644 --- a/test/src/mbgl/test/util.hpp +++ b/test/src/mbgl/test/util.hpp @@ -67,13 +67,13 @@ namespace test { class Server { public: - Server(); + Server(bool); ~Server(); void start(); private: std::unique_ptr<httplib::Server> svr; std::future<void> f_; - bool up_; + bool up_ = false; }; PremultipliedImage render(Map&); |