#include <boost/algorithm/string/trim.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
+#include <boost/bind.hpp>
#include "../Utils/senfassert.hh"
#include "../Utils/membind.hh"
#include "../Utils/Logger/SenfLog.hh"
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<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"),
senf::membind(&Client::clientData, this) );
}
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
-
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<void>(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<ClientHandle>::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"