X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FServer.cc;h=243a782bab3229ba7422ecd19b7f97f374e8cee8;hb=93d9568d448749dc187e7622b733a4a3caa319df;hp=a1bad60e45e27a1a2b53e43b9e1e77e93fb57951;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/Server.cc b/senf/Utils/Console/Server.cc index a1bad60..243a782 100644 --- a/senf/Utils/Console/Server.cc +++ b/senf/Utils/Console/Server.cc @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -33,19 +33,37 @@ #include #include #include -#include "../../Utils/senfassert.hh" -#include "../../Utils/membind.hh" -#include "../../Utils/Logger/SenfLog.hh" +#include +#include +#include +#include #include "LineEditor.hh" #include "ScopedDirectory.hh" #include "Sysdir.hh" +#include "SysInfo.hh" #include "ParsedCommand.hh" //#include "Server.mpp" #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef SENF_DEBUG +# define BUILD_TYPE "development" +#else +# define BUILD_TYPE "production" +#endif + +namespace { + senf::console::SysInfo::Proxy addSysInfo ( + "SENF: The Simple and Extensible Network Framework\n" + " © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research\n" + " Contact: senf-dev@lists.berlios.de\n" + " Version: " SENF_LIB_VERSION " Revision number: " SENF_REVISION "\n" + " Build-type: " BUILD_TYPE ", SenfLog compile time limit: " + + senf::str(senf::log::LEVELNAMES[senf::SenfLog::compileLimit::value]), 0); +} -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::NonBlockingSocketSink prefix_ std::streamsize senf::console::detail::NonblockingSocketSink::write(const char * s, @@ -57,13 +75,11 @@ prefix_ std::streamsize senf::console::detail::NonblockingSocketSink::write(cons client_.write(data); } } - catch (SystemException & ex) { - ; - } + catch (...) {} return n; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::Server prefix_ senf::console::Server & @@ -71,7 +87,7 @@ senf::console::Server::start(senf::INet4SocketAddress const & address) { senf::TCPv4ServerSocketHandle handle (address); Server & server (senf::console::Server::start(handle)); - SENF_LOG((Server::SENFLogArea)(log::NOTICE)( + SENF_LOG((Server::SENFLogArea)(log::NOTICE)( "Console server started at " << address )); return server; } @@ -81,7 +97,7 @@ senf::console::Server::start(senf::INet6SocketAddress const & address) { senf::TCPv6ServerSocketHandle handle (address); Server & server (senf::console::Server::start(handle)); - SENF_LOG((Server::SENFLogArea)(log::NOTICE)( + SENF_LOG((Server::SENFLogArea)(log::NOTICE)( "Console server started at " << address )); return server; } @@ -94,7 +110,7 @@ prefix_ senf::console::Server & senf::console::Server::start(ServerHandle handle } prefix_ senf::console::Server::Server(ServerHandle handle) - : handle_ (handle), + : handle_ (handle), event_ ("senf::console::Server", senf::membind(&Server::newClient, this), handle_, scheduler::FdEvent::EV_READ), root_ (senf::console::root().thisptr()), mode_ (Automatic), @@ -117,14 +133,14 @@ prefix_ void senf::console::Server::removeClient(Client & client) log << client.handle().peer(); } catch (senf::SystemException ex) { - log << "(unknown)"; + log << "(dead socket)"; } })); // THIS DELETES THE CLIENT INSTANCE !! clients_.erase(boost::intrusive_ptr(&client)); } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::DumbClientReader prefix_ senf::console::detail::DumbClientReader::DumbClientReader(Client & client) @@ -143,7 +159,7 @@ senf::console::detail::DumbClientReader::clientData(senf::ReadHelper().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} + } + catch (std::exception & ex) { + SENF_LOG(("unexpected failure writing to socket:" << ex.what())); + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} + } + catch (...) { + SENF_LOG(("unexpected failure writing to socket: unknown exception")); + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} + } } prefix_ unsigned senf::console::detail::DumbClientReader::v_width() @@ -194,13 +227,13 @@ prefix_ unsigned senf::console::detail::DumbClientReader::v_width() return 80; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::NoninteractiveClientReader prefix_ senf::console::detail::NoninteractiveClientReader::NoninteractiveClientReader(Client & client) - : ClientReader (client), - readevent_ ("senf::console::detail::NoninteractiveClientReader", + : ClientReader (client), + readevent_ ("senf::console::detail::NoninteractiveClientReader", senf::membind(&NoninteractiveClientReader::newData, this), handle(), senf::scheduler::FdEvent::EV_READ) {} @@ -213,7 +246,24 @@ prefix_ void senf::console::detail::NoninteractiveClientReader::v_enablePrompt() prefix_ void senf::console::detail::NoninteractiveClientReader::v_write(std::string const & data) { - handle().write(data); + try { + handle().write(data); + } + catch (senf::ExceptionMixin & ex) { + SENF_LOG(("unexpected failure writing to socket:" << ex.message())); + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} + } + catch (std::exception & ex) { + SENF_LOG(("unexpected failure writing to socket:" << ex.what())); + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} + } + catch (...) { + SENF_LOG(("unexpected failure writing to socket: unknown exception")); + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} + } } prefix_ unsigned senf::console::detail::NoninteractiveClientReader::v_width() @@ -240,17 +290,17 @@ senf::console::detail::NoninteractiveClientReader::newData(int event) stream() << std::flush; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::Client prefix_ senf::console::Client::Client(Server & server, ClientHandle handle) - : out_t(boost::ref(*this)), - senf::log::IOStreamTarget("client-" + senf::str(handle.peer()), out_t::member), - server_ (server), handle_ (handle), - readevent_ ("senf::console::Client::interactive_check", - boost::bind(&Client::setNoninteractive,this), + : out_t(boost::ref(*this)), + senf::log::IOStreamTarget("client-" + senf::str(handle.peer()), out_t::member), + server_ (server), handle_ (handle), + readevent_ ("senf::console::Client::interactive_check", + boost::bind(&Client::setNoninteractive,this), handle, scheduler::FdEvent::EV_READ, false), - timer_ ("senf::console::Client::interactive_timer", + timer_ ("senf::console::Client::interactive_timer", boost::bind(&Client::setInteractive, this), scheduler::eventTime() + ClockService::milliseconds(INTERACTIVE_TIMEOUT), false), @@ -309,7 +359,8 @@ prefix_ std::string::size_type senf::console::Client::handleInput(std::string da // 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); + try { handle_.facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} } catch (std::exception & ex) { std::string msg (ex.what()); @@ -317,7 +368,7 @@ prefix_ std::string::size_type senf::console::Client::handleInput(std::string da if (i != std::string::npos) { backtrace_ = msg.substr(0,i); msg = msg.substr(i+4); - } else + } else backtrace_.clear(); stream() << msg << std::endl; } @@ -342,20 +393,22 @@ prefix_ unsigned senf::console::Client::getWidth(std::ostream & os, unsigned def unsigned minWidth) { unsigned rv (defaultWidth); - try { - rv = get(os).width(); + try { + rv = get(os).width(); } catch (std::bad_cast &) {} return rv < minWidth ? defaultWidth : rv; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::Client::SysBacktrace prefix_ senf::console::Client::SysBacktrace::SysBacktrace() { - sysdir().node().add("backtrace", &SysBacktrace::backtrace) - .doc("Display the backtrace of the last error / exception in this console"); + namespace fty = senf::console::factory; + + sysdir().add("backtrace", fty::Command(&SysBacktrace::backtrace) + .doc("Display the backtrace of the last error / exception in this console") ); } prefix_ void senf::console::Client::SysBacktrace::backtrace(std::ostream & os) @@ -369,7 +422,7 @@ prefix_ void senf::console::Client::SysBacktrace::backtrace(std::ostream & os) senf::console::Client::SysBacktrace senf::console::Client::SysBacktrace::instance_; -///////////////////////////////cc.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ //#include "Server.mpp"