diff --git a/Socket/AddressingPolicy.hh b/Socket/AddressingPolicy.hh new file mode 100644 index 0000000000000000000000000000000000000000..f0024bc8dc47cf4559a3cc7b4e82966a6510d873 --- /dev/null +++ b/Socket/AddressingPolicy.hh @@ -0,0 +1,53 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// 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. +// +// 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. +// +// 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. + +#ifndef HH_AddressingPolicy_ +#define HH_AddressingPolicy_ 1 + +// Custom includes +#include "SocketPolicy.hh" + +//#include "AddressingPolicy.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace satcom { +namespace lib { + + struct NoAddressingPolicy : public AddressingPolicyBase + { + typedef satcom::lib::nil Address; + }; + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "AddressingPolicy.cci" +//#include "AddressingPolicy.ct" +//#include "AddressingPolicy.cti" +//#include "AddressingPolicy.mpp" +#endif + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: diff --git a/Socket/ClientSocketHandle.hh b/Socket/ClientSocketHandle.hh index b7d56056b22111472e35873a553690d20cea78cd..ae0868ee0e3548ad545868aa58543cff0fe06b63 100644 --- a/Socket/ClientSocketHandle.hh +++ b/Socket/ClientSocketHandle.hh @@ -33,6 +33,8 @@ namespace satcom { namespace lib { + template <class Policy> class ServerSocketHandle; + /** \brief */ template <class Policy> @@ -45,6 +47,7 @@ namespace lib { typedef typename Policy::AddressingPolicy::Address Address; typedef typename boost::call_traits<Address>::param_type AddressParam; + typedef ServerSocketHandle<Policy> ServerSocketHandle; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members diff --git a/Socket/ProtocolServerSocketHandle.test.cc b/Socket/ProtocolServerSocketHandle.test.cc index ae3ea2c408555ab43d43b9c074895eeef0ac75ef..1cd392008a34209ec47027478d023bbf7bd6bea6 100644 --- a/Socket/ProtocolServerSocketHandle.test.cc +++ b/Socket/ProtocolServerSocketHandle.test.cc @@ -27,7 +27,7 @@ // Custom includes #include "ProtocolServerSocketHandle.hh" -#include "SocketProtocol.test.hh" +#include "ServerSocketHandle.test.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> @@ -37,7 +37,8 @@ BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle) { - typedef satcom::lib::ProtocolServerSocketHandle<satcom::lib::test::SomeProtocol> MySocketHandle; + typedef satcom::lib::ProtocolServerSocketHandle< + satcom::lib::test::SomeConnectedProtocol> MySocketHandle; MySocketHandle h; h.protocol(); diff --git a/Socket/ServerSocketHandle.cti b/Socket/ServerSocketHandle.cti index 27b5b4b076c6f1098ba2360e32fb487c2a1bfc33..59e8f022566d2b09aa8e0b40bffb991aec65d7da 100644 --- a/Socket/ServerSocketHandle.cti +++ b/Socket/ServerSocketHandle.cti @@ -52,6 +52,37 @@ satcom::lib::ServerSocketHandle<SocketPolicy>::operator=(ServerSocketHandle<Othe return *this; } +/////////////////////////////////////////////////////////////////////////// +// Server socket interface + +template <class Policy> +prefix_ void satcom::lib::ServerSocketHandle<Policy>::bind(AddressParam addr) +{ + Policy::AddressingPolicy::bind(*this,addr); +} + +template <class Policy> +prefix_ typename satcom::lib::ServerSocketHandle<Policy>::Address +satcom::lib::ServerSocketHandle<Policy>::local() +{ + typename Policy::AddressingPolicy::Address addr; + this->local(addr); + return addr; +} + +template <class Policy> +prefix_ void satcom::lib::ServerSocketHandle<Policy>::local(Address & addr) +{ + Policy::AddressingPolicy::local(*this,addr); +} + +template <class Policy> +prefix_ typename satcom::lib::ServerSocketHandle<Policy>::ClientSocketHandle +satcom::lib::ServerSocketHandle<Policy>::accept() +{ + return Policy::CommunicationPolicy::accept(*this); +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/ServerSocketHandle.hh b/Socket/ServerSocketHandle.hh index 0fad2cd99bbbcb82892d169fe30084ea0c333ab3..95338f154809173ff17abf6851571574570d01e4 100644 --- a/Socket/ServerSocketHandle.hh +++ b/Socket/ServerSocketHandle.hh @@ -24,7 +24,11 @@ #define HH_ServerSocketHandle_ 1 // Custom includes +#include <boost/static_assert.hpp> +#include <boost/call_traits.hpp> #include "SocketHandle.hh" +#include "CommunicationPolicy.hh" +#include "AddressingPolicy.hh" //#include "ServerSocketHandle.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -32,16 +36,28 @@ namespace satcom { namespace lib { + template <class Policy> class ClientSocketHandle; + /** \brief */ - template <class SocketPolicy> + template <class Policy> class ServerSocketHandle - : public SocketHandle<SocketPolicy> + : public SocketHandle<Policy> { + // FIXME: Are theese necessary ... hmm ... + BOOST_STATIC_ASSERT((boost::is_convertible< typename Policy::CommunicationPolicy *, + ConnectedCommunicationPolicy *>::value )); + BOOST_STATIC_ASSERT(!(boost::is_convertible< typename Policy::AddressingPolicy *, + NoAddressingPolicy *>::value )); + public: /////////////////////////////////////////////////////////////////////////// // Types + typedef typename Policy::AddressingPolicy::Address Address; + typedef typename boost::call_traits<Address>::param_type AddressParam; + typedef ClientSocketHandle<Policy> ClientSocketHandle; + /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ @@ -54,14 +70,28 @@ namespace lib { // conversion constructors template <class OtherPolicy> ServerSocketHandle(ServerSocketHandle<OtherPolicy> other, - typename SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type * = 0); + typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0); + + template <class OtherPolicy> + typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const & + operator=(ServerSocketHandle<OtherPolicy> other); ///@} /////////////////////////////////////////////////////////////////////////// - template <class OtherPolicy> - typename SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type const & - operator=(ServerSocketHandle<OtherPolicy> other); + /////////////////////////////////////////////////////////////////////////// + ///\name Server socket interface + ///@{ + + void bind (AddressParam addr); + + Address local (); + void local (Address & addr); + + ClientSocketHandle + accept (); + + ///@} protected: explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol); diff --git a/Socket/ServerSocketHandle.test.cc b/Socket/ServerSocketHandle.test.cc index 336ed3b3f9eff12b007f3bbfd17f41f659f37ee3..121faf872109ba0d5ef304d5aa77f4752984d2a5 100644 --- a/Socket/ServerSocketHandle.test.cc +++ b/Socket/ServerSocketHandle.test.cc @@ -27,7 +27,8 @@ // Custom includes #include "ServerSocketHandle.hh" -#include "SocketProtocol.test.hh" +#include "ServerSocketHandle.test.hh" +#include "ClientSocketHandle.hh" #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> @@ -36,14 +37,16 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { + namespace sl = satcom::lib; - + class MySocketHandle - : public sl::ServerSocketHandle<sl::test::SomeProtocol::Policy> + : public sl::ServerSocketHandle<sl::test::SomeConnectedProtocol::Policy> { public: MySocketHandle() - : sl::ServerSocketHandle<sl::test::SomeProtocol::Policy>(std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeProtocol())) + : sl::ServerSocketHandle<sl::test::SomeConnectedProtocol::Policy>( + std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeConnectedProtocol())) {} }; } @@ -60,6 +63,10 @@ BOOST_AUTO_UNIT_TEST(serverSocketHandle) MySocketHandle myh; OtherSocketHandle ssh (myh); ssh = myh; + + BOOST_CHECK_NO_THROW( myh.bind(0) ); + BOOST_CHECK_EQUAL( myh.local(), 2u ); + // BOOST_CHECK_NO_THROW( myh.accept() ); } diff --git a/Socket/ServerSocketHandle.test.hh b/Socket/ServerSocketHandle.test.hh new file mode 100644 index 0000000000000000000000000000000000000000..96a64432a4fc0e49904deeb51a2b40097143ba74 --- /dev/null +++ b/Socket/ServerSocketHandle.test.hh @@ -0,0 +1,71 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// 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. +// +// 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. +// +// 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. + +#ifndef HH_ServerSocketHandle_test_ +#define HH_ServerSocketHandle_test_ 1 + +// Custom includes +#include "SocketPolicy.test.hh" +#include "SocketProtocol.hh" + +//#include "ServerSocketHandle.test.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace satcom { +namespace lib { +namespace test { + + typedef satcom::lib::MakeSocketPolicy< + SomeAddressingPolicy, + SomeFramingPolicy, + ConnectedCommunicationPolicy, + SomeReadPolicy, + SomeWritePolicy, + SomeBufferingPolicy + >::policy SomeConnectedPolicy; + + class SomeConnectedProtocol + : public ConcreteSocketProtocol<SomeConnectedPolicy> + { + ~SomeConnectedProtocol() {} + + void init_client() const {} + void init_server() const {} + + unsigned available() const { return Policy::ReadPolicy::TEST_SIZE; } + bool eof() const { return false; } + }; + +}}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "ServerSocketHandle.test.cci" +//#include "ServerSocketHandle.test.ct" +//#include "ServerSocketHandle.test.cti" +//#include "ServerSocketHandle.test.mpp" +#endif + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: