Socket: Move protocol into the socket body (as private base class) and allow non...
g0dil [Thu, 31 Jan 2008 08:16:02 +0000 (08:16 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@650 270642c3-0616-0410-b53a-bc976706d245

45 files changed:
Socket/ClientSocketHandle.cti
Socket/ClientSocketHandle.hh
Socket/ClientSocketHandle.test.cc
Socket/ProtocolClientSocketHandle.cti
Socket/ProtocolClientSocketHandle.mpp
Socket/ProtocolServerSocketHandle.cti
Socket/ProtocolServerSocketHandle.mpp
Socket/ProtocolServerSocketHandle.test.cc
Socket/Protocols/DVB/DVBDemuxHandles.cc
Socket/Protocols/DVB/DVBDemuxHandles.hh
Socket/Protocols/DVB/DVBFrontendHandle.cc
Socket/Protocols/DVB/DVBFrontendHandle.hh
Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc
Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh
Socket/Protocols/INet/ConnectedUDPSocketHandle.cc
Socket/Protocols/INet/ConnectedUDPSocketHandle.hh
Socket/Protocols/INet/RawINetSocketHandle.cc
Socket/Protocols/INet/RawINetSocketHandle.hh
Socket/Protocols/INet/TCPSocketHandle.cc
Socket/Protocols/INet/TCPSocketHandle.hh
Socket/Protocols/INet/UDPSocketHandle.cc
Socket/Protocols/INet/UDPSocketHandle.hh
Socket/Protocols/Raw/PacketSocketHandle.cc
Socket/Protocols/Raw/PacketSocketHandle.hh
Socket/Protocols/Raw/TunTapSocketHandle.cc
Socket/Protocols/Raw/TunTapSocketHandle.hh
Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc
Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh
Socket/Protocols/UN/UNDatagramSocketHandle.cc
Socket/Protocols/UN/UNDatagramSocketHandle.hh
Socket/Protocols/UN/UNDatagramSocketHandle.test.cc
Socket/ServerSocketHandle.cti
Socket/ServerSocketHandle.hh
Socket/ServerSocketHandle.test.cc
Socket/SocketHandle.cc
Socket/SocketHandle.cci
Socket/SocketHandle.ct
Socket/SocketHandle.cti
Socket/SocketHandle.hh
Socket/SocketHandle.ih
Socket/SocketHandle.test.cc
Socket/SocketProtocol.cci
Socket/SocketProtocol.cti
Socket/SocketProtocol.hh
Socket/SocketProtocol.test.hh

index 8bd5ca8..9a5cd7b 100644 (file)
@@ -124,12 +124,9 @@ prefix_ senf::ClientSocketHandle<Policy>::ClientSocketHandle(FileHandle other, b
 
 template <class Policy>
 prefix_
-senf::ClientSocketHandle<Policy>::ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
-                                                     int fd)
-    : SocketHandle<Policy>(protocol,false) 
-{
-    this->body().fd(fd);
-}
+senf::ClientSocketHandle<Policy>::ClientSocketHandle(std::auto_ptr<SocketBody> body)
+    : SocketHandle<Policy>(body) 
+{}
 
 #ifndef DOXYGEN
 template <class Policy>
index 6150e28..93cd252 100644 (file)
@@ -429,8 +429,7 @@ namespace senf {
 
     protected:
         ClientSocketHandle(FileHandle other, bool isChecked);
-        explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
-                                    int fd = -1);
+        explicit ClientSocketHandle(std::auto_ptr<SocketBody> body);
 
     private:
         unsigned available();
index a7a253f..5714e55 100644 (file)
 
 namespace {
 
-    namespace sl = senf;
-
     class MySocketHandle
-        : public sl::ClientSocketHandle<sl::test::SomeProtocol::Policy>
+        : public senf::ClientSocketHandle<senf::test::SomeProtocol::Policy>
     {
     public:
         MySocketHandle()
-            : sl::ClientSocketHandle<sl::test::SomeProtocol::Policy>(
-                std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeProtocol()))
+            : senf::ClientSocketHandle<senf::test::SomeProtocol::Policy>(
+                std::auto_ptr<senf::SocketBody>(
+                    new senf::ProtocolSocketBody<senf::test::SomeProtocol>(false)))
             {}
     };
+
 }
 
 BOOST_AUTO_UNIT_TEST(clientSocketHandle)
@@ -59,27 +59,27 @@ BOOST_AUTO_UNIT_TEST(clientSocketHandle)
 
     // conversion to other socket handles
     {
-        typedef sl::MakeSocketPolicy<
-            sl::test::SomeFramingPolicy,
-            sl::test::SomeReadPolicy,
-            sl::test::SomeWritePolicy
+        typedef senf::MakeSocketPolicy<
+            senf::test::SomeFramingPolicy,
+            senf::test::SomeReadPolicy,
+            senf::test::SomeWritePolicy
             >::policy OtherSocketPolicy;
-        typedef sl::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
+        typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
 
         BOOST_CHECKPOINT("Copy-constructing socket handle");
         OtherSocketHandle osh (myh);
         BOOST_CHECKPOINT("Assigning socket handle");
         osh = myh;
-        typedef sl::ClientSocketHandle<sl::test::SomeProtocol::Policy> SomeSocketHandle;
+        typedef senf::ClientSocketHandle<senf::test::SomeProtocol::Policy> SomeSocketHandle;
         BOOST_CHECKPOINT("static_casting socket handle");
         SomeSocketHandle ssh =
-            sl::static_socket_cast<SomeSocketHandle>(osh);
-        BOOST_CHECK_NO_THROW( sl::dynamic_socket_cast<SomeSocketHandle>(osh) );
-        typedef sl::ClientSocketHandle<sl::MakeSocketPolicy<
+            senf::static_socket_cast<SomeSocketHandle>(osh);
+        BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
+        typedef senf::ClientSocketHandle<senf::MakeSocketPolicy<
             OtherSocketPolicy,
-            sl::NoAddressingPolicy
+            senf::NoAddressingPolicy
             >::policy> SomeOtherSocketHandle;
-        BOOST_CHECK_THROW( sl::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
+        BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
                            std::bad_cast );
     }
 
index e467fb0..43c7b01 100644 (file)
@@ -43,7 +43,7 @@ ProtocolClientSocketHandle(senf::NoInit_t)
 template <class SocketProtocol>
 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::ProtocolClientSocketHandle()
     : ClientSocketHandle<typename SocketProtocol::Policy>(
-        std::auto_ptr<senf::SocketProtocol>(new SocketProtocol()))
+        std::auto_ptr<senf::SocketBody>(new senf::ProtocolSocketBody<SocketProtocol>(false)))
 {
     this->protocol().init_client();
 }
index 20790a3..37a22de 100644 (file)
@@ -62,7 +62,7 @@ template < mpp_TemplateParameters() >
 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
 ProtocolClientSocketHandle( mpp_MethodParameters() )
     : ClientSocketHandle<typename SocketProtocol::Policy>(
-        std::auto_ptr<senf::SocketProtocol>(new SocketProtocol()))
+        std::auto_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(false)))
 {
     this->protocol().init_client( mpp_CallParameters() );
 }
@@ -88,4 +88,6 @@ ProtocolClientSocketHandle( mpp_MethodParameters() )
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End:
index 85ce200..e27a8e5 100644 (file)
@@ -43,7 +43,7 @@ ProtocolServerSocketHandle(senf::NoInit_t)
 template <class SocketProtocol>
 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::ProtocolServerSocketHandle()
     : ServerSocketHandle<typename SocketProtocol::Policy>(
-        std::auto_ptr<senf::SocketProtocol>(new SocketProtocol()))
+        std::auto_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(true)))
 {}
 
 #define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2))
index 08d1993..6d80464 100644 (file)
@@ -66,7 +66,7 @@ template < mpp_PSSH_TemplateParameters() >
 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
 ProtocolServerSocketHandle( mpp_PSSH_MethodParameters() )
     : ServerSocketHandle<typename SocketProtocol::Policy>(
-        std::auto_ptr<senf::SocketProtocol>(new SocketProtocol()))
+        std::auto_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(true)))
 {
     this->protocol().init_server( mpp_PSSH_CallParameters() );
 }
index e45ed4d..149342c 100644 (file)
@@ -69,8 +69,8 @@ BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle)
                            "file.handle: -1\n"
                            "file.refcount: 2\n"
                            "handle: senf::ProtocolServerSocketHandle<(anonymous namespace)::MyProtocol>\n"
-                           "socket.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
                            "socket.protocol: (anonymous namespace)::MyProtocol\n"
+                           "socket.protocol.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
                            "socket.server: true\n" );
 
     }
index beed3c4..e54b3f9 100644 (file)
@@ -57,12 +57,6 @@ prefix_ unsigned senf::DVBDemuxSectionProtocol::available()
     return 4096;
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDemuxSectionProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new DVBDemuxSectionProtocol());
-}
-
 prefix_ void senf::DVBDemuxSectionProtocol::setSectionFilter(struct dmx_sct_filter_params *filter)
     const
 {
@@ -89,12 +83,6 @@ prefix_ unsigned senf::DVBDemuxPESProtocol::available()
     return 4096; //???
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDemuxPESProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new DVBDemuxPESProtocol());
-}
-
 prefix_ void senf::DVBDemuxPESProtocol::setPESFilter(struct dmx_pes_filter_params *filter)
     const
 {
@@ -121,12 +109,6 @@ prefix_ unsigned senf::DVBDvrProtocol::available()
     return 188;
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDvrProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new DVBDvrProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "DVBDemuxHandles.mpp"
index 59fd81a..6d521c7 100644 (file)
@@ -52,7 +52,7 @@ namespace senf {
     /** \brief xxx
      */
     class DVBDemuxSectionProtocol
-        : public ConcreteSocketProtocol<DVBDemux_Policy>,
+        : public ConcreteSocketProtocol<DVBDemux_Policy, DVBDemuxSectionProtocol>,
           public DVBDemuxProtocol
     {
     public:
@@ -73,8 +73,6 @@ namespace senf {
         
         unsigned available() const;
 
-        std::auto_ptr<SocketProtocol> clone() const;
-
         ///@}
         
         void setSectionFilter(struct dmx_sct_filter_params *filter) const;    
@@ -87,7 +85,7 @@ namespace senf {
     /** \brief xxx
      */
     class DVBDemuxPESProtocol
-        : public ConcreteSocketProtocol<DVBDemux_Policy>,
+        : public ConcreteSocketProtocol<DVBDemux_Policy,DVBDemuxPESProtocol>,
           public DVBDemuxProtocol
     {
     public:
@@ -108,8 +106,6 @@ namespace senf {
         
         unsigned available() const;
 
-        std::auto_ptr<SocketProtocol> clone() const;
-
         ///@}
         
         void setPESFilter(struct dmx_pes_filter_params *filter) const;    
@@ -124,7 +120,7 @@ namespace senf {
     /** \brief xxx
          */
     class DVBDvrProtocol
-        : public ConcreteSocketProtocol<DVBDemux_Policy>,
+        : public ConcreteSocketProtocol<DVBDemux_Policy, DVBDvrProtocol>,
           public DVBDemuxProtocol
     {
     public:
@@ -145,8 +141,6 @@ namespace senf {
         
         unsigned available() const;
 
-        std::auto_ptr<SocketProtocol> clone() const;
-        
         ///@}
      };
 
index c5e88e4..7092bda 100644 (file)
@@ -63,13 +63,6 @@ prefix_ bool senf::DVBFrontendProtocol::eof()
     return false;
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBFrontendProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new DVBFrontendProtocol());
-}
-
-
 prefix_ void senf::DVBFrontendProtocol::signalStrength(int16_t *strength)
     const
 {
index f40bab9..626a372 100644 (file)
@@ -54,7 +54,7 @@ namespace senf {
     /** \brief xxx
      */
     class DVBFrontendProtocol
-        : public ConcreteSocketProtocol<DVBFrontend_Policy>
+        : public ConcreteSocketProtocol<DVBFrontend_Policy, DVBFrontendProtocol>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -75,8 +75,6 @@ namespace senf {
         unsigned available() const;
         bool eof() const;
 
-        std::auto_ptr<SocketProtocol> clone() const;
-
         ///@}
         
         void signalStrength(int16_t *strength) const;
index 39bb3dc..da6be35 100644 (file)
@@ -60,12 +60,6 @@ senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol, INet4Socke
     clientHandle().connect(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV4SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new ConnectedRawV4SocketProtocol());
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // senf::UDPv6SocketProtocol::
 
@@ -92,12 +86,6 @@ senf::ConnectedRawV6SocketProtocol::init_client(int const & protocol, INet6Socke
     clientHandle().connect(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV6SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new ConnectedRawV6SocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "ConnectedRawINetSocketHandle.mpp"
index 5cd86f8..e1795d3 100644 (file)
@@ -74,12 +74,11 @@ namespace senf {
         \see RawV6SocketProtocol
      */
     class ConnectedRawV4SocketProtocol
-        : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy>,
+        : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy, ConnectedRawV4SocketProtocol>,
           public IPv4Protocol,
           public RawINetProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol//,
-//          public senf::pool_alloc_mixin<RawV4Socket_Policy>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -102,11 +101,6 @@ namespace senf {
                                              \param[in] address local address to connect to */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol> ConnectedRawV4ClientSocketHandle;
@@ -149,12 +143,11 @@ namespace senf {
         \see RawV6SocketProtocol
      */
     class ConnectedRawV6SocketProtocol
-        : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy>,
+        : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy, ConnectedRawV6SocketProtocol>,
           public IPv6Protocol,
           public RawINetProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol//,
-//          public senf::pool_alloc_mixin<RawV6SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -181,11 +174,6 @@ namespace senf {
                                              constructor (??) */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol> ConnectedRawV6ClientSocketHandle;
index d1150ba..4842f83 100644 (file)
@@ -58,12 +58,6 @@ senf::ConnectedUDPv4SocketProtocol::init_client(INet4SocketAddress const & addre
     clientHandle().connect(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv4SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new ConnectedUDPv4SocketProtocol());
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // senf::ConnectedUDPv6SocketProtocol::
 
@@ -84,12 +78,6 @@ senf::ConnectedUDPv6SocketProtocol::init_client(INet6SocketAddress const & addre
     clientHandle().connect(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv6SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new ConnectedUDPv6SocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "ConnectedUDPSocketHandle.mpp"
index 928cf80..5e09364 100644 (file)
@@ -77,12 +77,11 @@ namespace senf {
         \see ConnectedUDPv6SocketProtocol
      */
     class ConnectedUDPv4SocketProtocol
-        : public ConcreteSocketProtocol<ConnectedUDPv4Socket_Policy>,
+        : public ConcreteSocketProtocol<ConnectedUDPv4Socket_Policy, ConnectedUDPv4SocketProtocol>,
           public IPv4Protocol,
           public UDPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<ConnectedUDPv4SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -106,11 +105,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<
@@ -143,12 +137,11 @@ namespace senf {
         \see ConnectedUDPv4SocketProtocol
      */
     class ConnectedUDPv6SocketProtocol
-        : public ConcreteSocketProtocol<ConnectedUDPv6Socket_Policy>,
+        : public ConcreteSocketProtocol<ConnectedUDPv6Socket_Policy, ConnectedUDPv6SocketProtocol>,
           public IPv6Protocol,
           public UDPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<ConnectedUDPv6SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -172,11 +165,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<
index c775948..159cb16 100644 (file)
@@ -60,12 +60,6 @@ senf::RawV4SocketProtocol::init_client(int const & protocol, INet4SocketAddress
     clientHandle().bind(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV4SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new RawV4SocketProtocol());
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // senf::RawV6SocketProtocol::
 
@@ -92,12 +86,6 @@ senf::RawV6SocketProtocol::init_client(int const & protocol, INet6SocketAddress
     clientHandle().bind(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV6SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new RawV6SocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "RawINetSocketHandle.mpp"
index 2886c7f..3853c46 100644 (file)
@@ -74,14 +74,13 @@ namespace senf {
         \see RawV6SocketProtocol
      */
     class RawV4SocketProtocol
-        : public ConcreteSocketProtocol<RawV4Socket_Policy>,
+        : public ConcreteSocketProtocol<RawV4Socket_Policy, RawV4SocketProtocol>,
           public IPv4Protocol,
           public RawINetProtocol,
           public BSDSocketProtocol,
           public AddressableBSDSocketProtocol,
          public MulticastProtocol,
-         public INet4MulticastProtocol,
-         public senf::pool_alloc_mixin<RawV4SocketProtocol>
+         public INet4MulticastProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -104,11 +103,6 @@ namespace senf {
                                              \param[in] address local address to bind to */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<RawV4SocketProtocol> RawV4ClientSocketHandle;
@@ -149,14 +143,13 @@ namespace senf {
         \see RawV4SocketProtocol
      */
     class RawV6SocketProtocol
-        : public ConcreteSocketProtocol<RawV6Socket_Policy>,
+        : public ConcreteSocketProtocol<RawV6Socket_Policy,RawV6SocketProtocol>,
           public IPv6Protocol,
           public RawINetProtocol,
           public BSDSocketProtocol,
           public AddressableBSDSocketProtocol,
          public MulticastProtocol,
-         public INet4MulticastProtocol,
-         public senf::pool_alloc_mixin<RawV6SocketProtocol>
+         public INet4MulticastProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -183,11 +176,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<RawV6SocketProtocol> RawV6ClientSocketHandle;
index 1b38473..5afe60c 100644 (file)
@@ -78,12 +78,6 @@ prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & a
         throwErrno();
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::TCPv4SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new TCPv4SocketProtocol());
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // senf::TCPv6SocketProtocol::
 
@@ -124,12 +118,6 @@ prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & a
         throwErrno();
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::TCPv6SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new TCPv6SocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "TCPSocketHandle.mpp"
index b3293de..dffd668 100644 (file)
@@ -31,7 +31,6 @@
 #define HH_TCPSocketHandle_ 1
 
 // Custom includes
-#include "../../../Utils/pool_alloc_mixin.hh"
 #include "INetProtocol.hh"
 #include "TCPProtocol.hh"
 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
@@ -80,12 +79,11 @@ namespace senf {
         \see TCPv6SocketProtocol
      */
     class TCPv4SocketProtocol
-        : public ConcreteSocketProtocol<TCPv4Socket_Policy>,
+        : public ConcreteSocketProtocol<TCPv4Socket_Policy,TCPv4SocketProtocol>,
           public IPv4Protocol,
           public TCPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<TCPv4SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -124,11 +122,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<TCPv4SocketProtocol> TCPv4ClientSocketHandle;
@@ -162,12 +155,11 @@ namespace senf {
         \see TCPv4SocketProtocol
      */
     class TCPv6SocketProtocol
-        : public ConcreteSocketProtocol<TCPv6Socket_Policy>,
+        : public ConcreteSocketProtocol<TCPv6Socket_Policy,TCPv6SocketProtocol>,
           public IPv6Protocol,
           public TCPProtocol,
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<TCPv6SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -206,11 +198,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<TCPv6SocketProtocol> TCPv6ClientSocketHandle;
index 687ad59..e7c7dc5 100644 (file)
@@ -58,12 +58,6 @@ senf::UDPv4SocketProtocol::init_client(INet4SocketAddress const & address)
     clientHandle().bind(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv4SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new UDPv4SocketProtocol());
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // senf::UDPv6SocketProtocol::
 
@@ -84,12 +78,6 @@ senf::UDPv6SocketProtocol::init_client(INet6SocketAddress const & address)
     clientHandle().bind(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv6SocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new UDPv6SocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "UDPSocketHandle.mpp"
index 13673e8..6ed334c 100644 (file)
@@ -79,15 +79,14 @@ namespace senf {
         \see UDPv6SocketProtocol
      */
     class UDPv4SocketProtocol
-        : public ConcreteSocketProtocol<UDPv4Socket_Policy>,
+        : public ConcreteSocketProtocol<UDPv4Socket_Policy, UDPv4SocketProtocol>,
           public IPv4Protocol,
           public UDPProtocol,
           public MulticastProtocol,
           public INet4MulticastProtocol,
           public BSDSocketProtocol,
           public DatagramSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<UDPv4SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -110,11 +109,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
 
     };
 
@@ -147,15 +141,14 @@ namespace senf {
         \see UDPv4SocketProtocol
      */
     class UDPv6SocketProtocol
-        : public ConcreteSocketProtocol<UDPv6Socket_Policy>,
+        : public ConcreteSocketProtocol<UDPv6Socket_Policy, UDPv6SocketProtocol>,
           public IPv6Protocol,
           public UDPProtocol,
           public MulticastProtocol,
           public INet6MulticastProtocol,
           public BSDSocketProtocol,
           public DatagramSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<UDPv6SocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -178,11 +171,6 @@ namespace senf {
                                              constructor */
 
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<UDPv6SocketProtocol> UDPv6ClientSocketHandle;
index b3183f9..a57edf5 100644 (file)
@@ -54,12 +54,6 @@ prefix_ void senf::PacketProtocol::init_client(SocketType type, int protocol)
     fd(sock);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::PacketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new PacketProtocol());
-}
-
 prefix_ unsigned senf::PacketProtocol::available()
     const
 {
index a44edf2..0ee1f8d 100644 (file)
@@ -77,9 +77,8 @@ namespace senf {
         Socket Handle typedefs above.
      */
     class PacketProtocol
-        : public ConcreteSocketProtocol<Packet_Policy>,
-          public BSDSocketProtocol,
-          public senf::pool_alloc_mixin<PacketProtocol>
+        : public ConcreteSocketProtocol<Packet_Policy, PacketProtocol>,
+          public BSDSocketProtocol
     {
     public:
         enum SocketType { RawSocket, DatagramSocket };
@@ -129,7 +128,6 @@ namespace senf {
         ///\name Abstract Interface Implementation
         ///@{
 
-        std::auto_ptr<SocketProtocol> clone() const;
         unsigned available() const;
         bool eof() const;
 
index da12942..7049447 100644 (file)
@@ -62,12 +62,6 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name,
     fd(f);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::TapProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new TapProtocol());
-}
-
 prefix_ unsigned senf::TapProtocol::available()
   const
 {
index 4e66de0..844ab34 100644 (file)
@@ -73,9 +73,8 @@ namespace senf {
         Socket Handle typedefs above.
      */
     class TapProtocol
-        : public ConcreteSocketProtocol<Tap_Policy>,
-          public BSDSocketProtocol,
-          public senf::pool_alloc_mixin<TapProtocol>
+        : public ConcreteSocketProtocol<Tap_Policy,TapProtocol>,
+          public BSDSocketProtocol
     {
     public:
         ///\name Constructors
@@ -99,7 +98,6 @@ namespace senf {
         ///\name Abstract Interface Implementation
         ///@{
 
-        std::auto_ptr<SocketProtocol> clone() const;
         unsigned available() const;
         bool eof() const;
 
index c4b48b1..ffefd71 100644 (file)
@@ -50,12 +50,6 @@ prefix_ void senf::ConnectedUNDatagramSocketProtocol::init_client(UNSocketAddres
     clientHandle().connect(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUNDatagramSocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new ConnectedUNDatagramSocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "UNDatagramSocketHandle.mpp"
index 6a3d8c6..50ead3e 100644 (file)
@@ -71,11 +71,11 @@ namespace senf {
 
     */
     class ConnectedUNDatagramSocketProtocol
-        : public ConcreteSocketProtocol<ConnectedUNDatagramSocket_Policy>,
+        : public ConcreteSocketProtocol<ConnectedUNDatagramSocket_Policy,
+                                        ConnectedUNDatagramSocketProtocol>,
           public UNProtocol, 
           public BSDSocketProtocol,
-          public AddressableBSDSocketProtocol,
-          public senf::pool_alloc_mixin<ConnectedUNDatagramSocketProtocol>
+          public AddressableBSDSocketProtocol
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -98,11 +98,6 @@ namespace senf {
                                              constructor */
         
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<ConnectedUNDatagramSocketProtocol> ConnectedUNDatagramClientSocketHandle;
index 77408fa..42d7f38 100644 (file)
@@ -51,12 +51,6 @@ prefix_ void senf::UNDatagramSocketProtocol::init_client(UNSocketAddress const &
     clientHandle().bind(address);
 }
 
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::UNDatagramSocketProtocol::clone()
-    const
-{
-    return std::auto_ptr<SocketProtocol>(new UNDatagramSocketProtocol());
-}
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "UNDatagramSocketHandle.mpp"
index 3b7f8a5..92c2cd6 100644 (file)
@@ -71,7 +71,8 @@ namespace senf {
         Socket Handle typedefs above.
     */
     class UNDatagramSocketProtocol
-        : public ConcreteSocketProtocol<UNDatagramSocket_Policy>,
+        : public ConcreteSocketProtocol<UNDatagramSocket_Policy,
+                                        UNDatagramSocketProtocol>,
           public UNProtocol, 
           public BSDSocketProtocol,
           public AddressableBSDSocketProtocol
@@ -97,11 +98,6 @@ namespace senf {
                                              constructor */
         
         ///@}
-        ///\name Abstract Interface Implementation
-
-        std::auto_ptr<SocketProtocol> clone() const;
-
-        ///@}
     };
 
     typedef ProtocolClientSocketHandle<UNDatagramSocketProtocol> UNDatagramClientSocketHandle;
index 7ad720d..cf2b413 100644 (file)
@@ -40,19 +40,26 @@ BOOST_AUTO_UNIT_TEST(unDatagramSocketHandle)
     std::string testString ("Hallo Welt.");
     std::string socketPath (".socket-UNDatagramSocketHandle.test");
 
+    BOOST_CHECKPOINT( 1 );
     senf::UNSocketAddress addr (socketPath);
+    BOOST_CHECKPOINT( 2 );
     senf::UNDatagramClientSocketHandle inputSocket(addr);
+    BOOST_CHECKPOINT( 3 );
     senf::UNDatagramClientSocketHandle outputSocket;
 
 
+    BOOST_CHECKPOINT( 4 );
     outputSocket.writeto( addr, testString);
 
+    BOOST_CHECKPOINT( 5 );
     BOOST_CHECK_EQUAL( inputSocket.read(), testString);
 
       
     
 
+    BOOST_CHECKPOINT( 6 );
     outputSocket.close();
+    BOOST_CHECKPOINT( 7 );
     inputSocket.close();
 
 //    if( unlink(socketPath.c_str()) != 0)
index f2342f1..e0e133f 100644 (file)
@@ -48,8 +48,8 @@ ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
 
 template <class SocketPolicy>
 prefix_  senf::ServerSocketHandle<SocketPolicy>::
-ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol)
-    : SocketHandle<SocketPolicy>(protocol,true)
+ServerSocketHandle(std::auto_ptr<SocketBody> body)
+    : SocketHandle<SocketPolicy>(body)
 {}
 
 template <class SocketPolicy>
@@ -95,8 +95,8 @@ template <class Policy>
 prefix_ typename senf::ServerSocketHandle<Policy>::ClientSocketHandle
 senf::ServerSocketHandle<Policy>::accept()
 {
-    return ClientSocketHandle(this->protocol().clone(),
-                              Policy::CommunicationPolicy::accept(*this));
+    return ClientSocketHandle(this->body().clone(
+                                  Policy::CommunicationPolicy::accept(*this), false));
 }
 
 template <class Policy>
index 22e9cb9..68f29b0 100644 (file)
@@ -200,7 +200,7 @@ namespace senf {
 
     protected:
         ServerSocketHandle(FileHandle other, bool isChecked);
-        explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol);
+        explicit ServerSocketHandle(std::auto_ptr<SocketBody> body);
 
     private:
 
index 950b072..0d9ba42 100644 (file)
 
 namespace {
 
-    namespace sl = senf;
-
     class MySocketHandle
-        : public sl::ServerSocketHandle<sl::test::SomeProtocol::Policy>
+        : public senf::ServerSocketHandle<senf::test::SomeProtocol::Policy>
     {
     public:
         MySocketHandle()
-            : sl::ServerSocketHandle<sl::test::SomeProtocol::Policy>(
-                std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeProtocol()))
+            : senf::ServerSocketHandle<senf::test::SomeProtocol::Policy>(
+                std::auto_ptr<senf::SocketBody>(
+                    new senf::ProtocolSocketBody<senf::test::SomeProtocol>(true)))
             {}
     };
+
 }
 
 BOOST_AUTO_UNIT_TEST(serverSocketHandle)
 {
-    typedef sl::MakeSocketPolicy<
-        sl::test::SomeFramingPolicy,
-        sl::test::SomeReadPolicy,
-        sl::test::SomeWritePolicy
+    typedef senf::MakeSocketPolicy<
+        senf::test::SomeFramingPolicy,
+        senf::test::SomeReadPolicy,
+        senf::test::SomeWritePolicy
         >::policy OtherSocketPolicy;
-    typedef sl::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
+    typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
 
     MySocketHandle myh;
     OtherSocketHandle osh (myh);
     osh = myh;
 
-    typedef sl::ServerSocketHandle<sl::test::SomeProtocol::Policy> SomeSocketHandle;
-    SomeSocketHandle ssh = sl::static_socket_cast<SomeSocketHandle>(osh);
+    typedef senf::ServerSocketHandle<senf::test::SomeProtocol::Policy> SomeSocketHandle;
+    SomeSocketHandle ssh = senf::static_socket_cast<SomeSocketHandle>(osh);
 
-    typedef sl::ServerSocketHandle<sl::MakeSocketPolicy<
+    typedef senf::ServerSocketHandle<senf::MakeSocketPolicy<
         OtherSocketPolicy,
         senf::NoAddressingPolicy
         >::policy> SomeOtherSocketHandle;
-    typedef sl::ClientSocketHandle<OtherSocketPolicy> OtherClientHandle;
+    typedef senf::ClientSocketHandle<OtherSocketPolicy> OtherClientHandle;
 
-    BOOST_CHECK_NO_THROW( sl::dynamic_socket_cast<SomeSocketHandle>(osh) );
-    BOOST_CHECK_THROW( sl::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
+    BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
+    BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
                        std::bad_cast );
-    BOOST_CHECK_THROW( sl::dynamic_socket_cast<OtherClientHandle>(osh),
+    BOOST_CHECK_THROW( senf::dynamic_socket_cast<OtherClientHandle>(osh),
                        std::bad_cast );
 
     BOOST_CHECK_NO_THROW( myh.bind(0) );
index 562253b..042d267 100644 (file)
@@ -57,8 +57,8 @@ prefix_ void senf::SocketBody::state(SocketStateMap & map, unsigned lod)
     map["file.handle"]     << fd();
     map["file.refcount"]   << refcount();
     map["socket.server"]   << isServer();
-    map["socket.protocol"] << prettyName(typeid(protocol()));
-    map["socket.policy"]   << prettyName(typeid(protocol().policy()));
+    map["socket.protocol"] << v_protocolName();
+    map["socket.protocol.policy"]   << prettyName(typeid(protocol().policy()));
     protocol().state(map,lod);
 }
 
index c25d09f..896d13a 100644 (file)
 #define prefix_ inline
 ///////////////////////////////cci.p///////////////////////////////////////
 
-prefix_ senf::SocketBody::SocketBody(std::auto_ptr<SocketProtocol> protocol,
-                                            bool isServer)
-    : protocol_(protocol), isServer_(isServer)
-{
-    SENF_ASSERT( ! protocol_->body_ );
-    protocol_->body_ = this;
-}
+prefix_ senf::SocketBody::SocketBody(bool isServer)
+    : isServer_(isServer)
+{}
+
+prefix_ senf::SocketBody::SocketBody(bool isServer, int fd)
+    : FileBody(fd), isServer_(isServer)
+{}
 
-prefix_ senf::SocketBody::SocketBody(std::auto_ptr<SocketProtocol> protocol,
-                                            bool isServer, int fd)
-    : FileBody(fd), protocol_(protocol), isServer_(isServer)
+prefix_ senf::SocketProtocol & senf::SocketBody::protocol()
 {
-    SENF_ASSERT( ! protocol_->body_ );
-    protocol_->body_ = this;
+    return const_cast<SocketProtocol &>(v_protocol());
 }
 
 prefix_ senf::SocketProtocol const & senf::SocketBody::protocol()
     const
 {
-    return *protocol_;
+    return v_protocol();
 }
 
 prefix_ bool senf::SocketBody::isServer()
@@ -61,6 +58,18 @@ prefix_ bool senf::SocketBody::isServer()
     return isServer_;
 }
 
+prefix_ std::auto_ptr<senf::SocketBody> senf::SocketBody::clone(bool isServer)
+    const
+{
+    return protocol().clone(isServer);
+}
+
+prefix_ std::auto_ptr<senf::SocketBody> senf::SocketBody::clone(int fd, bool isServer)
+    const
+{
+    return protocol().clone(fd, isServer);
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::detail::StreamableString
 
index 6b66701..98ce100 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include <boost/lexical_cast.hpp>
+#include "../Utils/TypeInfo.hh"
 
 #define prefix_
 ///////////////////////////////ct.p////////////////////////////////////////
@@ -45,6 +46,23 @@ senf::detail::StreamableString::operator<<(T const & other)
     return *this;
 }
 
+///////////////////////////////////////////////////////////////////////////
+// senf::ProtocolSocketBody<SProtocol>
+
+template <class SProtocol>
+prefix_ senf::SocketProtocol const & senf::ProtocolSocketBody<SProtocol>::v_protocol()
+    const
+{
+    return *this;
+}
+
+template <class SProtocol>
+prefix_ std::string senf::ProtocolSocketBody<SProtocol>::v_protocolName()
+    const
+{
+    return senf::prettyName(typeid(SProtocol));
+}
+
 ///////////////////////////////ct.e////////////////////////////////////////
 #undef prefix_
 
index 852cc3f..983c5a5 100644 (file)
@@ -35,6 +35,9 @@
 #define prefix_ inline
 ///////////////////////////////cti.p///////////////////////////////////////
 
+///////////////////////////////////////////////////////////////////////////
+// senf::SocketHandle<SocketPolicy>
+
 template <class SocketPolicy>
 prefix_ senf::SocketHandle<SocketPolicy>::SocketHandle()
 {}
@@ -57,9 +60,8 @@ senf::SocketHandle<SocketPolicy>::operator=(SocketHandle<OtherPolicy> other)
 
 template <class SocketPolicy>
 prefix_
-senf::SocketHandle<SocketPolicy>::SocketHandle(std::auto_ptr<SocketProtocol> protocol,
-                                                      bool isServer)
-    : FileHandle(std::auto_ptr<FileBody>(new SocketBody(protocol,isServer)))
+senf::SocketHandle<SocketPolicy>::SocketHandle(std::auto_ptr<SocketBody> body)
+    : FileHandle(std::auto_ptr<FileBody>(body.release()))
 {}
 
 template <class SocketPolicy>
@@ -182,6 +184,19 @@ prefix_ std::string senf::SocketHandle<SocketPolicy>::dumpState(unsigned lod)
     return detail::dumpState(map);
 }
 
+///////////////////////////////////////////////////////////////////////////
+// senf::ProtocolSocketBody<SProtocol>
+
+template <class SProtocol>
+prefix_ senf::ProtocolSocketBody<SProtocol>::ProtocolSocketBody(bool isServer)
+    : SocketBody(isServer)
+{}
+
+template <class SProtocol>
+prefix_ senf::ProtocolSocketBody<SProtocol>::ProtocolSocketBody(bool isServer, int fd)
+    : SocketBody(isServer, fd)
+{}
+
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_
 
index 77cd781..85a14b6 100644 (file)
@@ -147,7 +147,7 @@ namespace senf {
                                                  documentation. */
 
     protected:
-        explicit SocketHandle(std::auto_ptr<SocketProtocol> protocol, bool isServer);
+        explicit SocketHandle(std::auto_ptr<SocketBody> body);
                                         ///< Initialize SocketHandle providing the protocol
                                         /**< \param protocol Protocol class of the protocol
                                                  implemented by this socket handle
index 996ead4..43edd14 100644 (file)
@@ -85,6 +85,8 @@ namespace senf {
         std::string dumpState(SocketStateMap const & map);
     }
 
+    template <class Policy, class Self> class ConcreteSocketProtocol;
+
     /** \brief SocketHandle referenced body
 
         \internal
@@ -95,13 +97,9 @@ namespace senf {
         properly. If this invariant is violated, your Program will probably crash.
      */
     class SocketBody
-        : public FileBody, 
-          public senf::pool_alloc_mixin<SocketBody>
+        : public FileBody
     {
     public:
-        using senf::pool_alloc_mixin<SocketBody>::operator new;
-        using senf::pool_alloc_mixin<SocketBody>::operator delete;
-
         ///////////////////////////////////////////////////////////////////////////
         // Types
 
@@ -111,19 +109,12 @@ namespace senf {
         ///\name Structors and default members
         ///@{
 
-        SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer);
-                                        /**<
-                                           \param protocol Protocol class implementing the desired
-                                           protocol
-                                           \param isServer \c true, if this socket is a server
-                                           socket, false otherwise */
-        SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer, int fd);
-                                        /**<
-                                           \param protocol Protocol class implementing the desired
-                                           protocol
-                                           \param isServer \c true, if this socket is a server
-                                           socket, false otherwise
-                                           \param fd socket file descriptor */
+        SocketBody(bool isServer);      /**< \param isServer \c true, if this socket is a server
+                                             socket, false otherwise */
+        SocketBody(bool isServer, int fd);
+                                        /**< \param isServer \c true, if this socket is a server
+                                             socket, false otherwise
+                                             \param fd socket file descriptor */
 
         // no copy
         // no conversion constructors
@@ -131,14 +122,18 @@ namespace senf {
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
-        SocketProtocol const & protocol() const;
-                                        ///< Access the protocol instance
+        SocketProtocol & protocol(); ///< Access the protocol instance
+        SocketProtocol const & protocol() const; ///< Access the protocol instance (const)
+
         bool isServer();                ///< Check socket type
                                         /**< \return \c true, if this is a server socket, \c false
                                            otherwise */
 
         void state(SocketStateMap & map, unsigned lod);
 
+        std::auto_ptr<SocketBody> clone(bool isServer) const;
+        std::auto_ptr<SocketBody> clone(int fd, bool isServer) const;
+
     private:
         virtual void v_close();         ///< Close socket
                                         /**< This override will automatically \c shutdown() the
@@ -156,10 +151,38 @@ namespace senf {
                                            dependent, this member will forward the call to
                                            senf::SocketPolicy::eof() */
 
-        boost::scoped_ptr<SocketProtocol> protocol_;
+        virtual SocketProtocol const & v_protocol() const = 0;
+        virtual std::string v_protocolName() const = 0;
+
         bool isServer_;
     };
 
+    template <class SProtocol>
+    class ProtocolSocketBody 
+        : public SocketBody, 
+          private SProtocol,
+          public senf::pool_alloc_mixin< ProtocolSocketBody<SProtocol> >
+    {
+    public:
+        typedef SProtocol Protocol;
+
+        using senf::pool_alloc_mixin< ProtocolSocketBody<SProtocol> >::operator new;
+        using senf::pool_alloc_mixin< ProtocolSocketBody<SProtocol> >::operator delete;
+
+        ProtocolSocketBody(bool isServer); /**< \param isServer \c true, if this socket is a server
+                                             socket, false otherwise */
+        ProtocolSocketBody(bool isServer, int fd);
+                                        /**< \param isServer \c true, if this socket is a server
+                                             socket, false otherwise
+                                             \param fd socket file descriptor */
+        
+    private:
+        virtual SocketProtocol const & v_protocol() const;
+        virtual std::string v_protocolName() const;
+
+        friend class ConcreteSocketProtocol<typename SProtocol::Policy, SProtocol>;
+    };
+
 }
 
 ///////////////////////////////ih.e////////////////////////////////////////
index 0bcb477..9312676 100644 (file)
 ///////////////////////////////cc.p////////////////////////////////////////
 
 namespace {
-    namespace sl = senf;
 
     class MySocketHandle
-        : public sl::SocketHandle<sl::test::SomeProtocol::Policy>
+        : public senf::SocketHandle<senf::test::SomeProtocol::Policy>
     {
     public:
         MySocketHandle()
-            : sl::SocketHandle<sl::test::SomeProtocol::Policy>(
-                std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeProtocol()),false)
+            : senf::SocketHandle<senf::test::SomeProtocol::Policy>(
+                std::auto_ptr<senf::SocketBody>(
+                    new senf::ProtocolSocketBody<senf::test::SomeProtocol>(false)))
             {}
     };
 
@@ -53,30 +53,29 @@ namespace {
         : public senf::FileHandle
     {
     public:
-        FDHandle()
-            : senf::FileHandle(std::auto_ptr<senf::FileBody>(
-                                          new senf::FileBody())) {}
+        FDHandle() : senf::FileHandle(std::auto_ptr<senf::FileBody>(new senf::FileBody())) {}
     };
+
 }
 
 BOOST_AUTO_UNIT_TEST(socketHandle)
 {
-    typedef sl::MakeSocketPolicy<
-        sl::test::SomeCommunicationPolicy,
-        sl::test::SomeReadPolicy
+    typedef senf::MakeSocketPolicy<
+        senf::test::SomeCommunicationPolicy,
+        senf::test::SomeReadPolicy
         >::policy OtherSocketPolicy;
-    typedef sl::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
+    typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
 
     MySocketHandle myh;
     OtherSocketHandle osh (myh);
     osh = myh;
 
-    typedef sl::SocketHandle<sl::test::SomeProtocol::Policy> SomeSocketHandle;
+    typedef senf::SocketHandle<senf::test::SomeProtocol::Policy> SomeSocketHandle;
     SomeSocketHandle ssh = senf::static_socket_cast<SomeSocketHandle>(osh);
 
     BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
 
-    typedef sl::SocketHandle< sl::MakeSocketPolicy<
+    typedef senf::SocketHandle< senf::MakeSocketPolicy<
         OtherSocketPolicy,
         senf::NoAddressingPolicy
         >::policy> SomeOtherSocketHandle;
@@ -91,8 +90,8 @@ BOOST_AUTO_UNIT_TEST(socketHandle)
                        "file.handle: -1\n"
                        "file.refcount: 3\n"
                        "handle: senf::SocketHandle<senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy> >\n"
-                       "socket.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
                        "socket.protocol: senf::test::SomeProtocol\n"
+                       "socket.protocol.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
                        "socket.server: false\n" );
 }
 
index 5f8bbb6..04be16c 100644 (file)
@@ -27,7 +27,8 @@
 //#include "SocketProtocol.ih"
 
 // Custom includes
-#include <../Utils/senfassert.hh>
+#include "../Utils/senfassert.hh"
+#include "../Utils/Logger/SenfLog.hh"
 
 #define prefix_ inline
 ///////////////////////////////cci.p///////////////////////////////////////
@@ -55,19 +56,11 @@ prefix_ void senf::SocketProtocol::fd(int fd)
 }
 
 prefix_ senf::SocketProtocol::SocketProtocol()
-    : body_(0)
 {}
 
 prefix_  senf::SocketProtocol::~SocketProtocol()
 {}
 
-prefix_ senf::SocketBody & senf::SocketProtocol::body()
-    const
-{
-    SENF_ASSERT( body_ );
-    return *body_;
-}
-
 ///////////////////////////////cci.e///////////////////////////////////////
 #undef prefix_
 
index 1c16b75..4751ec4 100644 (file)
 ///////////////////////////////////////////////////////////////////////////
 // senf::ConcreteSocketProtocol<SocketPolicy>
 
-template <class SocketPolicy>
-prefix_ senf::ConcreteSocketProtocol<SocketPolicy>::~ConcreteSocketProtocol()
+template <class SocketPolicy, class Self>
+prefix_ senf::ConcreteSocketProtocol<SocketPolicy,Self>::~ConcreteSocketProtocol()
 {}
 
-template <class SocketPolicy>
-prefix_ typename senf::ConcreteSocketProtocol<SocketPolicy>::Policy const &
-senf::ConcreteSocketProtocol<SocketPolicy>::policy()
+template <class SocketPolicy, class Self>
+prefix_ typename senf::ConcreteSocketProtocol<SocketPolicy,Self>::Policy const &
+senf::ConcreteSocketProtocol<SocketPolicy,Self>::policy()
     const
 {
     return policy_;
 }
 
+template <class SocketPolicy, class Self>
+prefix_ std::auto_ptr<senf::SocketBody>
+senf::ConcreteSocketProtocol<SocketPolicy,Self>::clone(bool isServer)
+    const
+{
+    return std::auto_ptr<SocketBody>(new ProtocolSocketBody<Self>(isServer));
+}
+
+template <class SocketPolicy, class Self>
+prefix_ std::auto_ptr<senf::SocketBody>
+senf::ConcreteSocketProtocol<SocketPolicy,Self>::clone(int fd, bool isServer)
+    const
+{
+    return std::auto_ptr<SocketBody>(new ProtocolSocketBody<Self>(isServer, fd));
+}
+
+template <class SocketPolicy, class Self>
+prefix_ senf::SocketBody & senf::ConcreteSocketProtocol<SocketPolicy,Self>::body()
+    const
+{
+    return const_cast< ProtocolSocketBody<Self> &>(
+        static_cast< ProtocolSocketBody<Self> const & >(*this));
+}
+
 ////////////////////////////////////////
 // protected members
 
-template <class SocketPolicy>
+template <class SocketPolicy, class Self>
 prefix_ senf::ClientSocketHandle<SocketPolicy>
-senf::ConcreteSocketProtocol<SocketPolicy>::clientHandle()
+senf::ConcreteSocketProtocol<SocketPolicy,Self>::clientHandle()
     const
 {
     return static_socket_cast< ClientSocketHandle<Policy> >(fh());
 }
 
-template <class SocketPolicy>
+template <class SocketPolicy, class Self>
 prefix_ senf::ServerSocketHandle<SocketPolicy>
-senf::ConcreteSocketProtocol<SocketPolicy>::serverHandle()
+senf::ConcreteSocketProtocol<SocketPolicy,Self>::serverHandle()
     const
 {
     return static_socket_cast< ServerSocketHandle<Policy> >(fh());
index 7c34b3a..50301f9 100644 (file)
@@ -153,14 +153,6 @@ namespace senf {
         ///////////////////////////////////////////////////////////////////////////
         // Virtual interface
 
-        virtual std::auto_ptr<SocketProtocol> clone() const = 0;
-                                        ///< Polymorphically return a copy of this protocol class
-                                        /**< This member will create a new copy of the protocol
-                                             class on the heap.
-                                             \attention This member must be implemented in every \e
-                                                 leaf protocol class to return a new instance of the
-                                                 appropriate type. */
-
         virtual unsigned available() const = 0;
                                         ///< Return (maximum) number of bytes available for reading
                                         ///< without < blocking
@@ -260,11 +252,10 @@ namespace senf {
                                              ::dup2()). */
 
     private:
-        // backpointer to owning SocketBody instance
-        
-        SocketBody & body() const;
+        virtual std::auto_ptr<SocketBody> clone(bool isServer) const = 0;
+        virtual std::auto_ptr<SocketBody> clone(int fd, bool isServer) const = 0;
+        virtual SocketBody & body() const = 0;
 
-        SocketBody * body_;
         friend class SocketBody;
     };
     
@@ -288,7 +279,7 @@ namespace senf {
         
         \doc init_client init_server
      */
-    template <class SocketPolicy>
+    template <class SocketPolicy, class Self>
     class ConcreteSocketProtocol
         : public virtual SocketProtocol
     {
@@ -312,7 +303,7 @@ namespace senf {
         ///////////////////////////////////////////////////////////////////////////
 
         Policy const & policy() const;
-
+        
     protected:
         ClientSocketHandle<Policy> clientHandle() const; 
                                         ///< Get client handle for associated socket
@@ -324,8 +315,11 @@ namespace senf {
                                              this protocol instance */
 
     private:
-        Policy policy_;
+        virtual std::auto_ptr<SocketBody> clone(bool isServer) const;
+        virtual std::auto_ptr<SocketBody> clone(int fd, bool isServer) const;
+        virtual SocketBody & body() const;
 
+        Policy policy_;
     };
 
     /// @}
index 220864d..f1459fe 100644 (file)
 ///////////////////////////////hh.p////////////////////////////////////////
 
 namespace senf {
-
 namespace test {
 
     class SomeProtocol
-        : public ConcreteSocketProtocol<SomeSocketPolicy>
+        : public ConcreteSocketProtocol<SomeSocketPolicy,SomeProtocol>
     {
     public:
         ~SomeProtocol() {}
@@ -44,8 +43,6 @@ namespace test {
         void init_client() const {}
         void init_server() const {}
 
-        std::auto_ptr<SocketProtocol> clone() const
-            { return std::auto_ptr<SocketProtocol>(new SomeProtocol()); }
         unsigned available() const
             { return Policy::ReadPolicy::TEST_SIZE; }
         bool eof() const