From 40f8cbdc47c6c1b12986486cc38f43472cce0f8e Mon Sep 17 00:00:00 2001 From: AdamSimpson Date: Fri, 16 Feb 2018 23:59:09 -0500 Subject: [PATCH] Don't throw in signal handler --- Builder/src/main.cpp | 22 ++++++++++------------ Client/src/main.cpp | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Builder/src/main.cpp b/Builder/src/main.cpp index 298ca15..3eba78c 100644 --- a/Builder/src/main.cpp +++ b/Builder/src/main.cpp @@ -21,7 +21,7 @@ namespace bp = boost::process; using callback_type = std::function; -ClientData read_client_data(websocket::stream &client_stream) { +ClientData read_client_data(websocket::stream &client_stream) { Logger::info("Reading client data"); Logger::info("Reading serialized client data"); @@ -39,7 +39,7 @@ ClientData read_client_data(websocket::stream &client_stream) { return client_data; } -void read_file(websocket::stream &client_stream, +void read_file(websocket::stream &client_stream, const std::string &file_name) { Logger::info("Opening " + file_name + " for writing"); std::ofstream file; @@ -97,7 +97,7 @@ std::string build_command(const ClientData &client_data) { return build_command; } -void stream_build(websocket::stream &client_stream, +void stream_build(websocket::stream &client_stream, const std::string &build_command) { Logger::info("Starting subprocess and redirecting output to pipe"); @@ -140,7 +140,7 @@ void stream_build(websocket::stream &client_stream, Logger::info("Done streaming subprocess output"); } -void write_file(websocket::stream &client_stream, +void write_file(websocket::stream &client_stream, const std::string &file_name) { Logger::info("Opening " + file_name + " for reading"); @@ -179,10 +179,15 @@ int main(int argc, char *argv[]) { boost::ignore_unused(argc, argv); asio::io_context io_context; - websocket::stream client_stream(io_context); + tcp::socket socket{io_context}; + websocket::stream client_stream{socket}; tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 8080)); try { + // Use keep alive, which hopefully detect badly disconnected clients + boost::asio::socket_base::keep_alive keep_alive(true); + socket.set_option(keep_alive); + Logger::info("Accepting an in coming websocket connection"); acceptor.accept(client_stream.next_layer()); client_stream.accept(); @@ -215,12 +220,5 @@ int main(int argc, char *argv[]) { Logger::error("Unknown exception caught!"); } - // Attempt to close connection - try { - Logger::debug("Attempting normal close"); - client_stream.close(websocket::close_code::normal); - } catch (...) { - Logger::error("Failed to cleanly close the WebSocket"); - } return 0; } \ No newline at end of file diff --git a/Client/src/main.cpp b/Client/src/main.cpp index e6afb7e..d70302a 100644 --- a/Client/src/main.cpp +++ b/Client/src/main.cpp @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) { std::cout.setf(std::ios::unitbuf); // Catch ctrl-c and restore cursor - std::signal(SIGINT, [](int signal){ throw std::runtime_error("User requested interrupt"); }); + std::signal(SIGINT, [](int signal){ std::cout << "Aborting\n"; show_cursor(); std::abort(); }); hide_cursor();