From be85fc65c1ee3f7d0fa945c2dea008d6dd3864f2 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 17 Jan 2018 18:29:53 +0100 Subject: [PATCH] Now ignores SIGPIPE, and added process->write check in source_language_protocol.cc --- src/juci.cc | 6 ++++++ src/source_language_protocol.cc | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/juci.cc b/src/juci.cc index 44b8d51..93a0e2d 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -5,6 +5,9 @@ #include "menu.h" #include "config.h" #include "terminal.h" +#ifndef _WIN32 +#include +#endif int Application::on_command_line(const Glib::RefPtr &cmd) { Glib::set_prgname("juci"); @@ -124,5 +127,8 @@ Application::Application() : Gtk::Application("no.sout.juci", Gio::APPLICATION_N } int main(int argc, char *argv[]) { +#ifndef _WIN32 + signal(SIGPIPE, SIG_IGN); // Do not terminate application when writing to a process fails +#endif return Application().run(argc, argv); } diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index 74f9cb0..73c99a0 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -232,7 +232,16 @@ void LanguageProtocol::Client::write_request(const std::string &method, const st auto message="Content-Length: "+std::to_string(content.size())+"\r\n\r\n"+content; if(output_messages_and_errors) std::cout << "Language client: " << content << std::endl; - process->write(message); + if(!process->write(message)) { + auto id_it=handlers.find(message_id); + if(id_it!=handlers.end()) { + auto function=std::move(id_it->second); + lock.unlock(); + function(boost::property_tree::ptree(), false); + lock.lock(); + handlers.erase(id_it->first); + } + } } void LanguageProtocol::Client::write_notification(const std::string &method, const std::string ¶ms) {