X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FServer.cc;h=243a782bab3229ba7422ecd19b7f97f374e8cee8;hb=93d9568d448749dc187e7622b733a4a3caa319df;hp=40b4d8059578cb51bfe133d1f2a92e72e5289732;hpb=ecb47e13433d59c79a74a4641a2e68648f142723;p=senf.git diff --git a/senf/Utils/Console/Server.cc b/senf/Utils/Console/Server.cc index 40b4d80..243a782 100644 --- a/senf/Utils/Console/Server.cc +++ b/senf/Utils/Console/Server.cc @@ -45,16 +45,25 @@ //#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", 0); + " 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, @@ -66,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 & @@ -126,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) @@ -173,9 +180,9 @@ prefix_ void senf::console::detail::DumbClientReader::showPrompt() prompt += " "; stream() << std::flush; - v_write(prompt); promptLen_ = prompt.size(); promptActive_ = true; + v_write(prompt); } prefix_ void senf::console::detail::DumbClientReader::v_disablePrompt() @@ -197,13 +204,20 @@ prefix_ void senf::console::detail::DumbClientReader::v_write(std::string const 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())); - stopClient(); // SUICIDE + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} } catch (...) { SENF_LOG(("unexpected failure writing to socket: unknown exception")); - stopClient(); // SUICIDE + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} } } @@ -213,7 +227,7 @@ prefix_ unsigned senf::console::detail::DumbClientReader::v_width() return 80; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::NoninteractiveClientReader prefix_ @@ -235,13 +249,20 @@ prefix_ void senf::console::detail::NoninteractiveClientReader::v_write(std::str 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())); - stopClient(); // SUICIDE + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} } catch (...) { SENF_LOG(("unexpected failure writing to socket: unknown exception")); - stopClient(); // SUICIDE + try { handle().facet().shutdown(senf::TCPSocketProtocol::ShutRD); } + catch (...) {} } } @@ -269,7 +290,7 @@ senf::console::detail::NoninteractiveClientReader::newData(int event) stream() << std::flush; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::Client prefix_ senf::console::Client::Client(Server & server, ClientHandle handle) @@ -338,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()); @@ -378,7 +400,7 @@ prefix_ unsigned senf::console::Client::getWidth(std::ostream & os, unsigned def return rv < minWidth ? defaultWidth : rv; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::Client::SysBacktrace prefix_ senf::console::Client::SysBacktrace::SysBacktrace() @@ -400,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"