X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FConsole%2FServer.cc;h=58a3dcc0fd9ce5e7668ec9cf2069dc23962ea1e5;hb=731a143df4de38d4c8b0a81121990951971cd858;hp=04b54be8427a4216ebb98010917b20487b9a5a41;hpb=958bdb52c39fa39f4ef91cafd9628bcb4f85a03c;p=senf.git diff --git a/Utils/Console/Server.cc b/Utils/Console/Server.cc index 04b54be..58a3dcc 100644 --- a/Utils/Console/Server.cc +++ b/Utils/Console/Server.cc @@ -27,6 +27,7 @@ #include "Server.ih" // Custom includes +#include #include #include #include @@ -35,7 +36,10 @@ #include "../../Utils/senfassert.hh" #include "../../Utils/membind.hh" #include "../../Utils/Logger/SenfLog.hh" -#include "Readline.hh" +#include "LineEditor.hh" +#include "ScopedDirectory.hh" +#include "Sysdir.hh" +#include "ParsedCommand.hh" //#include "Server.mpp" #define prefix_ @@ -50,8 +54,7 @@ prefix_ std::streamsize senf::console::detail::NonblockingSocketSink::write(cons try { if (client_.handle().writeable()) { std::string data (s, n); - client_.translate(data); - client_.handle().write( data ); + client_.write(data); } } catch (SystemException & ex) { @@ -94,7 +97,8 @@ prefix_ senf::console::Server::Server(ServerHandle handle) : handle_ (handle), event_ ("senf::console::Server", senf::membind(&Server::newClient, this), handle_, scheduler::FdEvent::EV_READ), - root_ (senf::console::root().thisptr()), mode_ (Automatic) + root_ (senf::console::root().thisptr()), mode_ (Automatic), + name_ (::program_invocation_short_name) {} prefix_ void senf::console::Server::newClient(int event) @@ -102,12 +106,12 @@ prefix_ void senf::console::Server::newClient(int event) ServerHandle::ClientHandle client (handle_.accept()); boost::intrusive_ptr p (new Client(*this, client)); clients_.insert( p ); - SENF_LOG(( "Registered new client " << p.get() )); + SENF_LOG(( "Registered new client " << client.peer() )); } prefix_ void senf::console::Server::removeClient(Client & client) { - SENF_LOG(( "Disposing client " << & client )); + SENF_LOG(( "Disposing client " << client.handle().peer() )); // THIS DELETES THE CLIENT INSTANCE !! clients_.erase(boost::intrusive_ptr(&client)); } @@ -149,6 +153,7 @@ senf::console::detail::DumbClientReader::clientData(senf::ReadHelpertranslate(data); -} - prefix_ std::string::size_type senf::console::Client::handleInput(std::string data, bool incremental) { - if (data.empty() && ! incremental) + if (data.empty() && ! incremental) { data = lastCommand_; - else + stream() << "repeat: " << data << std::endl; + } else lastCommand_ = data; std::string::size_type n (data.size()); @@ -285,14 +303,21 @@ prefix_ std::string::size_type senf::console::Client::handleInput(std::string da _1 )); } catch (Executor::ExitException &) { - // This generates an EOF condition on the Handle. This EOF condition is expected - // to be handled gracefully by the ClientReader. We cannot call stop() here, since we - // are called from the client reader callback and that will continue executing even if we - // call stop here ... + // This generates an EOF condition on the Handle. This EOF condition is expected to be + // handled gracefully by the ClientReader. We cannot call stop() here, since we are called + // from the client reader callback and that will continue executing after stop() has been + // called. stop() however will delete *this instance ... BANG ... handle_.facet().shutdown(senf::TCPSocketProtocol::ShutRD); } catch (std::exception & ex) { - stream() << ex.what() << std::endl; + std::string msg (ex.what()); + std::string::size_type i (msg.find("-- \n")); + if (i != std::string::npos) { + backtrace_ = msg.substr(0,i); + msg = msg.substr(i+4); + } else + backtrace_.clear(); + stream() << msg << std::endl; } catch (...) { stream() << "unidentified error (unknown exception thrown)" << std::endl; @@ -311,33 +336,26 @@ prefix_ void senf::console::Client::v_write(senf::log::time_type timestamp, reader_->enablePrompt(); } -prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client const & client) -{ - typedef ClientSocketHandle< MakeSocketPolicy< - INet4AddressingPolicy,ConnectedCommunicationPolicy>::policy > V4Socket; - typedef ClientSocketHandle< MakeSocketPolicy< - INet6AddressingPolicy,ConnectedCommunicationPolicy>::policy > V6Socket; +/////////////////////////////////////////////////////////////////////////// +// senf::console::Client::SysBacktrace - try { - if (check_socket_cast(client.handle())) - os << dynamic_socket_cast(client.handle()).peer(); - else if (check_socket_cast(client.handle())) - os << dynamic_socket_cast(client.handle()).peer(); - else - os << static_cast(&client); - } - catch (SystemException &) { - os << "0.0.0.0:0"; - } - - return os; +prefix_ senf::console::Client::SysBacktrace::SysBacktrace() +{ + sysdir().node().add("backtrace", &SysBacktrace::backtrace) + .doc("Display the backtrace of the last error / exception in this console"); } -prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client * client) +prefix_ void senf::console::Client::SysBacktrace::backtrace(std::ostream & os) { - return os << *client; + Client & client (Client::get(os)); + if (client.backtrace().empty()) + os << "(no backtrace)\n"; + else + os << client.backtrace(); } +senf::console::Client::SysBacktrace senf::console::Client::SysBacktrace::instance_; + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Server.mpp"