Server logs client address
jmo [Thu, 8 May 2008 07:07:46 +0000 (07:07 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@838 270642c3-0616-0410-b53a-bc976706d245

Console/Server.cc
Console/Server.hh
Console/testServer.cc

index 9ab2c8d..ac9f034 100644 (file)
@@ -27,7 +27,6 @@
 #include "Server.ih"
 
 // Custom includes
-#include <unistd.h>
 #include <iostream>
 #include <boost/algorithm/string/trim.hpp>
 #include <boost/iostreams/device/file_descriptor.hpp>
@@ -248,6 +247,24 @@ prefix_ void senf::console::Client::v_write(boost::posix_time::ptime timestamp,
     reader_->enablePrompt();
 }
 
+prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client const & client)
+{
+    //    typedef senf::ClientSocketHandle<MakeSocketPolicy<INet4AddressingPolicy>::policy > v4Socket;
+    if( senf::check_socket_cast<TCPv4ServerSocketHandle::ClientSocketHandle>( client.handle())) {
+        os<<senf::dynamic_socket_cast<TCPv4ServerSocketHandle::ClientSocketHandle>( client.handle()).peer();
+    }
+    else if( senf::check_socket_cast<TCPv6ServerSocketHandle::ClientSocketHandle>( client.handle())) {
+        os<<senf::dynamic_socket_cast<TCPv6ServerSocketHandle::ClientSocketHandle>( client.handle()).peer();
+    }
+    else{
+        os<<((void *)&client);
+    }
+    return os;
+}
+prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client * client)
+{
+    return os<<*client;
+}
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "Server.mpp"
index dc7630d..be3dd6c 100644 (file)
@@ -164,6 +164,12 @@ namespace console {
         friend class detail::ClientReader;
         friend class detail::NonblockingSocketSink;
     };
+        
+    /** \brief Output INet4Address instance as it's string representation
+            \related INet4Address
+         */
+    std::ostream & operator<<(std::ostream & os, Client const & client);
+    std::ostream & operator<<(std::ostream & os, Client * client);
 
 }}
 
index e8123e2..3ed6ba9 100644 (file)
@@ -110,7 +110,7 @@ int main(int, char **)
 
     TestObject test;
     testDir
-        .add("testob", test.dir)
+        .add("extra", test.dir)
         .doc("Example of an instance directory");
 
     senf::console::Server::start( senf::INet4SocketAddress(23232u) )