Socket: Fix handle.state() on invalid handles
[senf.git] / Socket / SocketHandle.cti
index b04f1f8..bc3f7be 100644 (file)
@@ -27,9 +27,8 @@
 #include "SocketHandle.ih"
 
 // Custom includes
-#include "../Utils/senfassert.hh"
 #include <typeinfo>
-#include <boost/lexical_cast.hpp>
+#include "../Utils/senfassert.hh"
 #include "../Utils/TypeInfo.hh"
 
 #define prefix_ inline
@@ -69,7 +68,7 @@ prefix_ senf::SocketHandle<SPolicy>::SocketHandle(FileHandle other, bool isCheck
     : FileHandle(other)
 {
     SENF_ASSERT( isChecked );
-    SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
+    SENF_ASSERT( ! valid() || dynamic_cast<SocketBody *>(&FileHandle::body()) );
 }
 
 template <class SPolicy>
@@ -88,7 +87,7 @@ prefix_ senf::SocketBody const & senf::SocketHandle<SPolicy>::body()
 }
 
 template <class SPolicy>
-prefix_ senf::SocketProtocol const & senf::SocketHandle<SPolicy>::protocol()
+prefix_ senf::SocketProtocol & senf::SocketHandle<SPolicy>::protocol()
     const
 {
     return body().protocol();
@@ -176,7 +175,11 @@ prefix_ void senf::SocketHandle<SPolicy>::state(SocketStateMap & map, unsigned l
     // the type name and therefore show the \e static policy of the
     // socket handle.
     map["handle"] << prettyName(typeid(*this));
-    body().state(map,lod);
+    if (valid()) {
+        map["valid"] << "true";
+        body().state(map,lod);
+    } else
+        map["valid"] << "false";
 }
 
 template <class SPolicy>
@@ -189,11 +192,11 @@ prefix_ std::string senf::SocketHandle<SPolicy>::dumpState(unsigned lod)
 
 template <class SPolicy>
 template <class Facet>
-prefix_ Facet const & senf::SocketHandle<SPolicy>::facet()
+prefix_ Facet & senf::SocketHandle<SPolicy>::facet()
 
 {
     try {
-        return dynamic_cast<Facet const &>(protocol());
+        return dynamic_cast<Facet &>(protocol());
     }
     SENF_WRAP_EXC(std::bad_cast)
 }