X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FServer.cc;h=72fd25c36616f42e366a926b7515fd77f3a60ba6;hb=16d94efc2159cba35fc44e5b26747ae0a2ab237b;hp=5790d8366e14a47277dc1ba769de65cbb118d3c4;hpb=412cf8e222086fb5d89b15cb11556799e131f390;p=senf.git diff --git a/Console/Server.cc b/Console/Server.cc index 5790d83..72fd25c 100644 --- a/Console/Server.cc +++ b/Console/Server.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include "../Utils/senfassert.hh" #include "../Utils/membind.hh" #include "../Utils/Logger/SenfLog.hh" @@ -103,7 +104,7 @@ prefix_ void senf::console::Server::removeClient(Client & client) prefix_ senf::console::Client::Client(ClientHandle handle, std::string const & name) : handle_ (handle), name_ (name), out_(::dup(handle.fd())) { - out_ << name_ << "# " << std::flush; + showPrompt(); ReadHelper::dispatch( handle_, 16384u, ReadUntil("\n"), senf::membind(&Client::clientData, this) ); } @@ -125,32 +126,41 @@ prefix_ void senf::console::Client::clientData(ReadHelper::ptr hel return; } -# warning fix Client::clientData implementation - // Remove the 'dup' needed here so we don't close the same fd twice (see Client constructor) - // Make output non-blocking - // Don't register a new ReadHelper every round + ///\fixme Fix Client::clientData implementation + /// Remove the 'dup' needed here so we don't close the same fd twice (see Client constructor) + /// Make output non-blocking + /// Don't register a new ReadHelper every round std::string data (tail_ + helper->data()); tail_ = helper->tail(); boost::trim(data); // Gets rid of superfluous \r or \n characters - if (data == "exit") { + try { + if (! parser_.parse(data, boost::bind(boost::ref(executor_), _1, boost::ref(out_)))) + out_ << "syntax error" << std::endl; + } + catch (Executor::ExitException &) { // THIS COMMITS SUICIDE. THE INSTANCE IS GONE AFTER stopClient RETURNS stopClient(); return; } - - ParseCommandInfo command; - if (parser_.parseCommand(data, command)) - executor_(command, out_); - else - out_ << "syntax error" << std::endl; - - out_ << name_ << "# " << std::flush; + catch (std::exception & ex) { + out_ << ex.what() << std::endl; + } + catch (...) { + out_ << "unidentified error (unknown exception thrown)" << std::endl; + } + + showPrompt(); ReadHelper::dispatch( handle_, 16384u, ReadUntil("\n"), senf::membind(&Client::clientData, this) ); } +prefix_ void senf::console::Client::showPrompt() +{ + out_ << name_ << ":" << executor_.cwd().path() << "# " << std::flush; +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Server.mpp"