From: g0dil Date: Thu, 15 May 2008 07:26:10 +0000 (+0000) Subject: Socket: Fix dynamic_socket_cast() / check_socket_cast() to support crosscasts X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=69e4a07eea4a95a83d226d7b7095b7d310dc4a06;p=senf.git Socket: Fix dynamic_socket_cast() / check_socket_cast() to support crosscasts Console: Clean up operator<< implementation for Client using socket crosscasts git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@844 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Console/Server.cc b/Console/Server.cc index ac9f034..64b669e 100644 --- a/Console/Server.cc +++ b/Console/Server.cc @@ -249,22 +249,26 @@ prefix_ void senf::console::Client::v_write(boost::posix_time::ptime timestamp, prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client const & client) { - // typedef senf::ClientSocketHandle::policy > v4Socket; - if( senf::check_socket_cast( client.handle())) { - os<( client.handle()).peer(); - } - else if( senf::check_socket_cast( client.handle())) { - os<( client.handle()).peer(); - } - else{ - os<<((void *)&client); - } + typedef ClientSocketHandle< MakeSocketPolicy< + INet4AddressingPolicy,ConnectedCommunicationPolicy>::policy > V4Socket; + typedef ClientSocketHandle< MakeSocketPolicy< + INet6AddressingPolicy,ConnectedCommunicationPolicy>::policy > V6Socket; + + if (check_socket_cast(client.handle())) + os << dynamic_socket_cast(client.handle()).peer(); + else if (check_socket_cast(client.handle())) + os << dynamic_socket_cast(client.handle()).peer(); + else + os << static_cast(&client); + return os; } + prefix_ std::ostream & senf::console::operator<<(std::ostream & os, Client * client) { - return os<<*client; + return os << *client; } + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Server.mpp" diff --git a/Console/Server.ih b/Console/Server.ih index eabef7e..6bbaf5a 100644 --- a/Console/Server.ih +++ b/Console/Server.ih @@ -80,14 +80,20 @@ namespace detail { virtual ~ClientReader() = 0; + // Called by subclasses to get information from the Client + Client & client() const; std::string promptString() const; ClientHandle handle() const; std::ostream & stream() const; + + // Called by subclasses to perform actions in the Client + void stopClient(); - void handleInput(std::string const & input) const; + // Called by the Client + void disablePrompt(); void enablePrompt(); void translate(std::string & data); diff --git a/Socket/SocketHandle.cti b/Socket/SocketHandle.cti index cbd9089..b04f1f8 100644 --- a/Socket/SocketHandle.cti +++ b/Socket/SocketHandle.cti @@ -133,11 +133,11 @@ prefix_ Target senf::static_socket_cast(Source handle) template prefix_ Target senf::dynamic_socket_cast(Source handle) { - BOOST_STATIC_ASSERT(( - boost::is_convertible::value && - boost::is_convertible::value && - ( boost::is_convertible::value || - boost::is_convertible::value ) )); +// BOOST_STATIC_ASSERT(( +// boost::is_convertible::value && +// boost::is_convertible::value && +// ( boost::is_convertible::value || +// boost::is_convertible::value ) )); try { return Target::cast_dynamic(handle); } @@ -147,11 +147,11 @@ prefix_ Target senf::dynamic_socket_cast(Source handle) template prefix_ bool senf::check_socket_cast(Source handle) { - BOOST_STATIC_ASSERT(( - boost::is_convertible::value && - boost::is_convertible::value && - ( boost::is_convertible::value || - boost::is_convertible::value ) )); +// BOOST_STATIC_ASSERT(( +// boost::is_convertible::value && +// boost::is_convertible::value && +// ( boost::is_convertible::value || +// boost::is_convertible::value ) )); // we don't have a non-throwing variant of cast_dynamic // for two reasons: // a) since the handle is passed back by value, we cannot return diff --git a/Socket/SocketHandle.test.cc b/Socket/SocketHandle.test.cc index c88c636..c8071f3 100644 --- a/Socket/SocketHandle.test.cc +++ b/Socket/SocketHandle.test.cc @@ -66,6 +66,12 @@ BOOST_AUTO_UNIT_TEST(socketHandle) >::policy OtherSocketPolicy; typedef senf::SocketHandle OtherSocketHandle; + typedef senf::MakeSocketPolicy< + senf::test::SomeCommunicationPolicy, + senf::test::SomeAddressingPolicy + >::policy AnotherSocketPolicy; + typedef senf::SocketHandle AnotherSocketHandle; + { MySocketHandle myh; OtherSocketHandle osh (myh); @@ -75,6 +81,7 @@ BOOST_AUTO_UNIT_TEST(socketHandle) SomeSocketHandle ssh = senf::static_socket_cast(osh); BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); typedef senf::SocketHandle< senf::MakeSocketPolicy< OtherSocketPolicy, diff --git a/Socket/SocketPolicy.test.hh b/Socket/SocketPolicy.test.hh index d921a47..00bf252 100644 --- a/Socket/SocketPolicy.test.hh +++ b/Socket/SocketPolicy.test.hh @@ -31,7 +31,6 @@ ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - namespace test { struct SomeAddressingPolicy : public senf::AddressingPolicyBase