X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FServer.cc;h=639b76d87240c985a534cfbac768f3cf7b9dc7f6;hb=d506c3134c5c01272c01608c86b8285176b50226;hp=8eb41acae0b6e04a6cc528feceedeabd5ec22bd2;hpb=80afad5e6501794ebf74e49ebd7220fa355b4fce;p=senf.git diff --git a/senf/Utils/Console/Server.cc b/senf/Utils/Console/Server.cc index 8eb41ac..639b76d 100644 --- a/senf/Utils/Console/Server.cc +++ b/senf/Utils/Console/Server.cc @@ -2,38 +2,38 @@ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief Server non-inline non-template implementation */ #include "Server.hh" -#include "Server.ih" +//#include "Server.ih" // Custom includes -#include -#include #include -#include -#include #include -#include #include #include #include @@ -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" + " © 2006-2011 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 & @@ -125,15 +132,15 @@ prefix_ void senf::console::Server::removeClient(Client & client) try { log << client.handle().peer(); } - catch (senf::SystemException ex) { - log << "(unknown)"; + catch (senf::SystemException & ex) { + 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) @@ -158,7 +165,7 @@ senf::console::detail::DumbClientReader::clientData(senf::ReadHelperdata()); tail_ = helper->tail(); - boost::trim(data); // Gets rid of superfluous \r or \n characters + boost::trim(data); // Gets rid of superfluous \r or \n characters handleInput(data); showPrompt(); @@ -173,9 +180,9 @@ prefix_ void senf::console::detail::DumbClientReader::showPrompt() prompt += " "; stream() << std::flush; - handle().write(prompt); promptLen_ = prompt.size(); promptActive_ = true; + v_write(prompt); } prefix_ void senf::console::detail::DumbClientReader::v_disablePrompt() @@ -194,7 +201,24 @@ prefix_ void senf::console::detail::DumbClientReader::v_enablePrompt() prefix_ void senf::console::detail::DumbClientReader::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::DumbClientReader::v_width() @@ -203,7 +227,7 @@ prefix_ unsigned senf::console::detail::DumbClientReader::v_width() return 80; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::NoninteractiveClientReader prefix_ @@ -222,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() @@ -249,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) @@ -318,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()); @@ -358,14 +400,12 @@ 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() { - namespace fty = senf::console::factory; - - sysdir().add("backtrace", fty::Command(&SysBacktrace::backtrace) + sysdir().add("backtrace", factory::Command(&SysBacktrace::backtrace) .doc("Display the backtrace of the last error / exception in this console") ); } @@ -380,7 +420,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"