Socket: Fix handle.state() on invalid handles
[senf.git] / Utils / Console / Server.cc
index 26a625f..a1bad60 100644 (file)
@@ -111,7 +111,15 @@ prefix_ void senf::console::Server::newClient(int event)
 
 prefix_ void senf::console::Server::removeClient(Client & client)
 {
-    SENF_LOG(( "Disposing client " << client.handle().peer() ));
+    SENF_LOG_BLOCK(({
+                log << "Disposing client ";
+                try {
+                    log << client.handle().peer();
+                }
+                catch (senf::SystemException ex) {
+                    log << "(unknown)";
+                }
+            }));
     // THIS DELETES THE CLIENT INSTANCE !!
     clients_.erase(boost::intrusive_ptr<Client>(&client));
 }
@@ -284,12 +292,6 @@ prefix_ void senf::console::Client::setNoninteractive()
 prefix_ std::string::size_type senf::console::Client::handleInput(std::string data,
                                                                   bool incremental)
 {
-    if (data.empty() && ! incremental) {
-        data = lastCommand_;
-        stream() << "repeat: " << data << std::endl;
-    } else
-        lastCommand_ = data;
-
     std::string::size_type n (data.size());
 
     try {
@@ -336,6 +338,17 @@ prefix_ void senf::console::Client::v_write(senf::log::time_type timestamp,
     reader_->enablePrompt();
 }
 
+prefix_ unsigned senf::console::Client::getWidth(std::ostream & os, unsigned defaultWidth,
+                                                 unsigned minWidth)
+{
+    unsigned rv (defaultWidth);
+    try { 
+        rv = get(os).width(); 
+    }
+    catch (std::bad_cast &) {}
+    return rv < minWidth ? defaultWidth : rv;
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::console::Client::SysBacktrace
 
@@ -349,7 +362,7 @@ prefix_ void senf::console::Client::SysBacktrace::backtrace(std::ostream & os)
 {
     Client & client (Client::get(os));
     if (client.backtrace().empty())
-        os << "(no backtrace)";
+        os << "(no backtrace)\n";
     else
         os << client.backtrace();
 }