From dff2e0534219926cd952918cd352cfb1582ab7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 22 May 2017 21:19:01 +0200 Subject: [PATCH] simplify main, also print more information --- toREST/src/main.cxx | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/toREST/src/main.cxx b/toREST/src/main.cxx index 489ae14..327c5ec 100644 --- a/toREST/src/main.cxx +++ b/toREST/src/main.cxx @@ -87,33 +87,43 @@ int main(int argc, char *argv[]) { tr::ws::on_close(session, connection, status, reason); }; + { + std::thread http_thread([&http_server]() { + http_server.start(); + }); - std::thread http_thread([&http_server]() { - http_server.start(); - }); + std::cout << "HTTP/1.1 server listening on port " << config.http_port << std::endl; - std::cout << "HTTP/1.1 server listening on port " << config.http_port << std::endl; + std::thread ws_thread([&ws_server]() { + ws_server.start(); + }); - std::thread ws_thread([&ws_server]() { - ws_server.start(); - }); + std::cout << "HTTP/1.1 websocket server listening on port " << config.ws_port << std::endl; - std::cout << "HTTP/1.1 websocket server listening on port " << config.ws_port << std::endl; + std::string input; - std::string input; - while (input != "q") { - std::getline(std::cin, input); - if (input == "q") { - std::cout << "Stopping server..." << std::endl; - http_server.stop(); // TODO check if throws - ws_server.stop(); - std::cout << "Server stopped" << std::endl; - break; + while (input != "q") { + std::getline(std::cin, input); } + + std::cout << "stopping http server..." << std::endl; + http_server.stop(); + std::cout << "stopping ws server..." << std::endl; + ws_server.stop(); + + http_thread.join(); + std::cout << "the http server was stopped." << std::endl; + ws_thread.join(); + std::cout << "the ws server was stopped." << std::endl; + } + + std::cout << "stopping torrents..." << std::endl; + + { + auto session_proxy = session.abort(); } - http_thread.join(); - ws_thread.join(); + std::cout << "the torrent session was stopped." << std::endl; return 0; };