From: g0dil Date: Thu, 31 Jan 2008 08:16:02 +0000 (+0000) Subject: Socket: Move protocol into the socket body (as private base class) and allow non... X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=6f50bf49e282c0528f51faa0a245bbfa2b867399;p=senf.git Socket: Move protocol into the socket body (as private base class) and allow non-const protocol access git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@650 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/ClientSocketHandle.cti b/Socket/ClientSocketHandle.cti index 8bd5ca8..9a5cd7b 100644 --- a/Socket/ClientSocketHandle.cti +++ b/Socket/ClientSocketHandle.cti @@ -124,12 +124,9 @@ prefix_ senf::ClientSocketHandle::ClientSocketHandle(FileHandle other, b template prefix_ -senf::ClientSocketHandle::ClientSocketHandle(std::auto_ptr protocol, - int fd) - : SocketHandle(protocol,false) -{ - this->body().fd(fd); -} +senf::ClientSocketHandle::ClientSocketHandle(std::auto_ptr body) + : SocketHandle(body) +{} #ifndef DOXYGEN template diff --git a/Socket/ClientSocketHandle.hh b/Socket/ClientSocketHandle.hh index 6150e28..93cd252 100644 --- a/Socket/ClientSocketHandle.hh +++ b/Socket/ClientSocketHandle.hh @@ -429,8 +429,7 @@ namespace senf { protected: ClientSocketHandle(FileHandle other, bool isChecked); - explicit ClientSocketHandle(std::auto_ptr protocol, - int fd = -1); + explicit ClientSocketHandle(std::auto_ptr body); private: unsigned available(); diff --git a/Socket/ClientSocketHandle.test.cc b/Socket/ClientSocketHandle.test.cc index a7a253f..5714e55 100644 --- a/Socket/ClientSocketHandle.test.cc +++ b/Socket/ClientSocketHandle.test.cc @@ -39,17 +39,17 @@ namespace { - namespace sl = senf; - class MySocketHandle - : public sl::ClientSocketHandle + : public senf::ClientSocketHandle { public: MySocketHandle() - : sl::ClientSocketHandle( - std::auto_ptr(new sl::test::SomeProtocol())) + : senf::ClientSocketHandle( + std::auto_ptr( + new senf::ProtocolSocketBody(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 OtherSocketHandle; + typedef senf::SocketHandle OtherSocketHandle; BOOST_CHECKPOINT("Copy-constructing socket handle"); OtherSocketHandle osh (myh); BOOST_CHECKPOINT("Assigning socket handle"); osh = myh; - typedef sl::ClientSocketHandle SomeSocketHandle; + typedef senf::ClientSocketHandle SomeSocketHandle; BOOST_CHECKPOINT("static_casting socket handle"); SomeSocketHandle ssh = - sl::static_socket_cast(osh); - BOOST_CHECK_NO_THROW( sl::dynamic_socket_cast(osh) ); - typedef sl::ClientSocketHandle(osh); + BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + typedef senf::ClientSocketHandle::policy> SomeOtherSocketHandle; - BOOST_CHECK_THROW( sl::dynamic_socket_cast(osh), + BOOST_CHECK_THROW( senf::dynamic_socket_cast(osh), std::bad_cast ); } diff --git a/Socket/ProtocolClientSocketHandle.cti b/Socket/ProtocolClientSocketHandle.cti index e467fb0..43c7b01 100644 --- a/Socket/ProtocolClientSocketHandle.cti +++ b/Socket/ProtocolClientSocketHandle.cti @@ -43,7 +43,7 @@ ProtocolClientSocketHandle(senf::NoInit_t) template prefix_ senf::ProtocolClientSocketHandle::ProtocolClientSocketHandle() : ClientSocketHandle( - std::auto_ptr(new SocketProtocol())) + std::auto_ptr(new senf::ProtocolSocketBody(false))) { this->protocol().init_client(); } diff --git a/Socket/ProtocolClientSocketHandle.mpp b/Socket/ProtocolClientSocketHandle.mpp index 20790a3..37a22de 100644 --- a/Socket/ProtocolClientSocketHandle.mpp +++ b/Socket/ProtocolClientSocketHandle.mpp @@ -62,7 +62,7 @@ template < mpp_TemplateParameters() > prefix_ senf::ProtocolClientSocketHandle:: ProtocolClientSocketHandle( mpp_MethodParameters() ) : ClientSocketHandle( - std::auto_ptr(new SocketProtocol())) + std::auto_ptr(new ProtocolSocketBody(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: diff --git a/Socket/ProtocolServerSocketHandle.cti b/Socket/ProtocolServerSocketHandle.cti index 85ce200..e27a8e5 100644 --- a/Socket/ProtocolServerSocketHandle.cti +++ b/Socket/ProtocolServerSocketHandle.cti @@ -43,7 +43,7 @@ ProtocolServerSocketHandle(senf::NoInit_t) template prefix_ senf::ProtocolServerSocketHandle::ProtocolServerSocketHandle() : ServerSocketHandle( - std::auto_ptr(new SocketProtocol())) + std::auto_ptr(new ProtocolSocketBody(true))) {} #define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2)) diff --git a/Socket/ProtocolServerSocketHandle.mpp b/Socket/ProtocolServerSocketHandle.mpp index 08d1993..6d80464 100644 --- a/Socket/ProtocolServerSocketHandle.mpp +++ b/Socket/ProtocolServerSocketHandle.mpp @@ -66,7 +66,7 @@ template < mpp_PSSH_TemplateParameters() > prefix_ senf::ProtocolServerSocketHandle:: ProtocolServerSocketHandle( mpp_PSSH_MethodParameters() ) : ServerSocketHandle( - std::auto_ptr(new SocketProtocol())) + std::auto_ptr(new ProtocolSocketBody(true))) { this->protocol().init_server( mpp_PSSH_CallParameters() ); } diff --git a/Socket/ProtocolServerSocketHandle.test.cc b/Socket/ProtocolServerSocketHandle.test.cc index e45ed4d..149342c 100644 --- a/Socket/ProtocolServerSocketHandle.test.cc +++ b/Socket/ProtocolServerSocketHandle.test.cc @@ -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\n" "socket.protocol: (anonymous namespace)::MyProtocol\n" + "socket.protocol.policy: senf::SocketPolicy\n" "socket.server: true\n" ); } diff --git a/Socket/Protocols/DVB/DVBDemuxHandles.cc b/Socket/Protocols/DVB/DVBDemuxHandles.cc index beed3c4..e54b3f9 100644 --- a/Socket/Protocols/DVB/DVBDemuxHandles.cc +++ b/Socket/Protocols/DVB/DVBDemuxHandles.cc @@ -57,12 +57,6 @@ prefix_ unsigned senf::DVBDemuxSectionProtocol::available() return 4096; } -prefix_ std::auto_ptr senf::DVBDemuxSectionProtocol::clone() - const -{ - return std::auto_ptr(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::DVBDemuxPESProtocol::clone() - const -{ - return std::auto_ptr(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::DVBDvrProtocol::clone() - const -{ - return std::auto_ptr(new DVBDvrProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "DVBDemuxHandles.mpp" diff --git a/Socket/Protocols/DVB/DVBDemuxHandles.hh b/Socket/Protocols/DVB/DVBDemuxHandles.hh index 59fd81a..6d521c7 100644 --- a/Socket/Protocols/DVB/DVBDemuxHandles.hh +++ b/Socket/Protocols/DVB/DVBDemuxHandles.hh @@ -52,7 +52,7 @@ namespace senf { /** \brief xxx */ class DVBDemuxSectionProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public DVBDemuxProtocol { public: @@ -73,8 +73,6 @@ namespace senf { unsigned available() const; - std::auto_ptr clone() const; - ///@} void setSectionFilter(struct dmx_sct_filter_params *filter) const; @@ -87,7 +85,7 @@ namespace senf { /** \brief xxx */ class DVBDemuxPESProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public DVBDemuxProtocol { public: @@ -108,8 +106,6 @@ namespace senf { unsigned available() const; - std::auto_ptr clone() const; - ///@} void setPESFilter(struct dmx_pes_filter_params *filter) const; @@ -124,7 +120,7 @@ namespace senf { /** \brief xxx */ class DVBDvrProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public DVBDemuxProtocol { public: @@ -145,8 +141,6 @@ namespace senf { unsigned available() const; - std::auto_ptr clone() const; - ///@} }; diff --git a/Socket/Protocols/DVB/DVBFrontendHandle.cc b/Socket/Protocols/DVB/DVBFrontendHandle.cc index c5e88e4..7092bda 100644 --- a/Socket/Protocols/DVB/DVBFrontendHandle.cc +++ b/Socket/Protocols/DVB/DVBFrontendHandle.cc @@ -63,13 +63,6 @@ prefix_ bool senf::DVBFrontendProtocol::eof() return false; } -prefix_ std::auto_ptr senf::DVBFrontendProtocol::clone() - const -{ - return std::auto_ptr(new DVBFrontendProtocol()); -} - - prefix_ void senf::DVBFrontendProtocol::signalStrength(int16_t *strength) const { diff --git a/Socket/Protocols/DVB/DVBFrontendHandle.hh b/Socket/Protocols/DVB/DVBFrontendHandle.hh index f40bab9..626a372 100644 --- a/Socket/Protocols/DVB/DVBFrontendHandle.hh +++ b/Socket/Protocols/DVB/DVBFrontendHandle.hh @@ -54,7 +54,7 @@ namespace senf { /** \brief xxx */ class DVBFrontendProtocol - : public ConcreteSocketProtocol + : public ConcreteSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -75,8 +75,6 @@ namespace senf { unsigned available() const; bool eof() const; - std::auto_ptr clone() const; - ///@} void signalStrength(int16_t *strength) const; diff --git a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc index 39bb3dc..da6be35 100644 --- a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc +++ b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc @@ -60,12 +60,6 @@ senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol, INet4Socke clientHandle().connect(address); } -prefix_ std::auto_ptr senf::ConnectedRawV4SocketProtocol::clone() - const -{ - return std::auto_ptr(new ConnectedRawV4SocketProtocol()); -} - /////////////////////////////////////////////////////////////////////////// // senf::UDPv6SocketProtocol:: @@ -92,12 +86,6 @@ senf::ConnectedRawV6SocketProtocol::init_client(int const & protocol, INet6Socke clientHandle().connect(address); } -prefix_ std::auto_ptr senf::ConnectedRawV6SocketProtocol::clone() - const -{ - return std::auto_ptr(new ConnectedRawV6SocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "ConnectedRawINetSocketHandle.mpp" diff --git a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh index 5cd86f8..e1795d3 100644 --- a/Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh +++ b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh @@ -74,12 +74,11 @@ namespace senf { \see RawV6SocketProtocol */ class ConnectedRawV4SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv4Protocol, public RawINetProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol//, -// public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -102,11 +101,6 @@ namespace senf { \param[in] address local address to connect to */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle ConnectedRawV4ClientSocketHandle; @@ -149,12 +143,11 @@ namespace senf { \see RawV6SocketProtocol */ class ConnectedRawV6SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv6Protocol, public RawINetProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol//, -// public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -181,11 +174,6 @@ namespace senf { constructor (??) */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle ConnectedRawV6ClientSocketHandle; diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc index d1150ba..4842f83 100644 --- a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc @@ -58,12 +58,6 @@ senf::ConnectedUDPv4SocketProtocol::init_client(INet4SocketAddress const & addre clientHandle().connect(address); } -prefix_ std::auto_ptr senf::ConnectedUDPv4SocketProtocol::clone() - const -{ - return std::auto_ptr(new ConnectedUDPv4SocketProtocol()); -} - /////////////////////////////////////////////////////////////////////////// // senf::ConnectedUDPv6SocketProtocol:: @@ -84,12 +78,6 @@ senf::ConnectedUDPv6SocketProtocol::init_client(INet6SocketAddress const & addre clientHandle().connect(address); } -prefix_ std::auto_ptr senf::ConnectedUDPv6SocketProtocol::clone() - const -{ - return std::auto_ptr(new ConnectedUDPv6SocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "ConnectedUDPSocketHandle.mpp" diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh b/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh index 928cf80..5e09364 100644 --- a/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh @@ -77,12 +77,11 @@ namespace senf { \see ConnectedUDPv6SocketProtocol */ class ConnectedUDPv4SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv4Protocol, public UDPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -106,11 +105,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle< @@ -143,12 +137,11 @@ namespace senf { \see ConnectedUDPv4SocketProtocol */ class ConnectedUDPv6SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv6Protocol, public UDPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -172,11 +165,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle< diff --git a/Socket/Protocols/INet/RawINetSocketHandle.cc b/Socket/Protocols/INet/RawINetSocketHandle.cc index c775948..159cb16 100644 --- a/Socket/Protocols/INet/RawINetSocketHandle.cc +++ b/Socket/Protocols/INet/RawINetSocketHandle.cc @@ -60,12 +60,6 @@ senf::RawV4SocketProtocol::init_client(int const & protocol, INet4SocketAddress clientHandle().bind(address); } -prefix_ std::auto_ptr senf::RawV4SocketProtocol::clone() - const -{ - return std::auto_ptr(new RawV4SocketProtocol()); -} - /////////////////////////////////////////////////////////////////////////// // senf::RawV6SocketProtocol:: @@ -92,12 +86,6 @@ senf::RawV6SocketProtocol::init_client(int const & protocol, INet6SocketAddress clientHandle().bind(address); } -prefix_ std::auto_ptr senf::RawV6SocketProtocol::clone() - const -{ - return std::auto_ptr(new RawV6SocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "RawINetSocketHandle.mpp" diff --git a/Socket/Protocols/INet/RawINetSocketHandle.hh b/Socket/Protocols/INet/RawINetSocketHandle.hh index 2886c7f..3853c46 100644 --- a/Socket/Protocols/INet/RawINetSocketHandle.hh +++ b/Socket/Protocols/INet/RawINetSocketHandle.hh @@ -74,14 +74,13 @@ namespace senf { \see RawV6SocketProtocol */ class RawV4SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv4Protocol, public RawINetProtocol, public BSDSocketProtocol, public AddressableBSDSocketProtocol, public MulticastProtocol, - public INet4MulticastProtocol, - public senf::pool_alloc_mixin + public INet4MulticastProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -104,11 +103,6 @@ namespace senf { \param[in] address local address to bind to */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle RawV4ClientSocketHandle; @@ -149,14 +143,13 @@ namespace senf { \see RawV4SocketProtocol */ class RawV6SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv6Protocol, public RawINetProtocol, public BSDSocketProtocol, public AddressableBSDSocketProtocol, public MulticastProtocol, - public INet4MulticastProtocol, - public senf::pool_alloc_mixin + public INet4MulticastProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -183,11 +176,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle RawV6ClientSocketHandle; diff --git a/Socket/Protocols/INet/TCPSocketHandle.cc b/Socket/Protocols/INet/TCPSocketHandle.cc index 1b38473..5afe60c 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.cc +++ b/Socket/Protocols/INet/TCPSocketHandle.cc @@ -78,12 +78,6 @@ prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & a throwErrno(); } -prefix_ std::auto_ptr senf::TCPv4SocketProtocol::clone() - const -{ - return std::auto_ptr(new TCPv4SocketProtocol()); -} - /////////////////////////////////////////////////////////////////////////// // senf::TCPv6SocketProtocol:: @@ -124,12 +118,6 @@ prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & a throwErrno(); } -prefix_ std::auto_ptr senf::TCPv6SocketProtocol::clone() - const -{ - return std::auto_ptr(new TCPv6SocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "TCPSocketHandle.mpp" diff --git a/Socket/Protocols/INet/TCPSocketHandle.hh b/Socket/Protocols/INet/TCPSocketHandle.hh index b3293de..dffd668 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.hh +++ b/Socket/Protocols/INet/TCPSocketHandle.hh @@ -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, + : public ConcreteSocketProtocol, public IPv4Protocol, public TCPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -124,11 +122,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle TCPv4ClientSocketHandle; @@ -162,12 +155,11 @@ namespace senf { \see TCPv4SocketProtocol */ class TCPv6SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv6Protocol, public TCPProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -206,11 +198,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle TCPv6ClientSocketHandle; diff --git a/Socket/Protocols/INet/UDPSocketHandle.cc b/Socket/Protocols/INet/UDPSocketHandle.cc index 687ad59..e7c7dc5 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.cc +++ b/Socket/Protocols/INet/UDPSocketHandle.cc @@ -58,12 +58,6 @@ senf::UDPv4SocketProtocol::init_client(INet4SocketAddress const & address) clientHandle().bind(address); } -prefix_ std::auto_ptr senf::UDPv4SocketProtocol::clone() - const -{ - return std::auto_ptr(new UDPv4SocketProtocol()); -} - /////////////////////////////////////////////////////////////////////////// // senf::UDPv6SocketProtocol:: @@ -84,12 +78,6 @@ senf::UDPv6SocketProtocol::init_client(INet6SocketAddress const & address) clientHandle().bind(address); } -prefix_ std::auto_ptr senf::UDPv6SocketProtocol::clone() - const -{ - return std::auto_ptr(new UDPv6SocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "UDPSocketHandle.mpp" diff --git a/Socket/Protocols/INet/UDPSocketHandle.hh b/Socket/Protocols/INet/UDPSocketHandle.hh index 13673e8..6ed334c 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.hh +++ b/Socket/Protocols/INet/UDPSocketHandle.hh @@ -79,15 +79,14 @@ namespace senf { \see UDPv6SocketProtocol */ class UDPv4SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv4Protocol, public UDPProtocol, public MulticastProtocol, public INet4MulticastProtocol, public BSDSocketProtocol, public DatagramSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -110,11 +109,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; @@ -147,15 +141,14 @@ namespace senf { \see UDPv4SocketProtocol */ class UDPv6SocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public IPv6Protocol, public UDPProtocol, public MulticastProtocol, public INet6MulticastProtocol, public BSDSocketProtocol, public DatagramSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -178,11 +171,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle UDPv6ClientSocketHandle; diff --git a/Socket/Protocols/Raw/PacketSocketHandle.cc b/Socket/Protocols/Raw/PacketSocketHandle.cc index b3183f9..a57edf5 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.cc +++ b/Socket/Protocols/Raw/PacketSocketHandle.cc @@ -54,12 +54,6 @@ prefix_ void senf::PacketProtocol::init_client(SocketType type, int protocol) fd(sock); } -prefix_ std::auto_ptr senf::PacketProtocol::clone() - const -{ - return std::auto_ptr(new PacketProtocol()); -} - prefix_ unsigned senf::PacketProtocol::available() const { diff --git a/Socket/Protocols/Raw/PacketSocketHandle.hh b/Socket/Protocols/Raw/PacketSocketHandle.hh index a44edf2..0ee1f8d 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.hh +++ b/Socket/Protocols/Raw/PacketSocketHandle.hh @@ -77,9 +77,8 @@ namespace senf { Socket Handle typedefs above. */ class PacketProtocol - : public ConcreteSocketProtocol, - public BSDSocketProtocol, - public senf::pool_alloc_mixin + : public ConcreteSocketProtocol, + public BSDSocketProtocol { public: enum SocketType { RawSocket, DatagramSocket }; @@ -129,7 +128,6 @@ namespace senf { ///\name Abstract Interface Implementation ///@{ - std::auto_ptr clone() const; unsigned available() const; bool eof() const; diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.cc b/Socket/Protocols/Raw/TunTapSocketHandle.cc index da12942..7049447 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.cc @@ -62,12 +62,6 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name, fd(f); } -prefix_ std::auto_ptr senf::TapProtocol::clone() - const -{ - return std::auto_ptr(new TapProtocol()); -} - prefix_ unsigned senf::TapProtocol::available() const { diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.hh b/Socket/Protocols/Raw/TunTapSocketHandle.hh index 4e66de0..844ab34 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.hh +++ b/Socket/Protocols/Raw/TunTapSocketHandle.hh @@ -73,9 +73,8 @@ namespace senf { Socket Handle typedefs above. */ class TapProtocol - : public ConcreteSocketProtocol, - public BSDSocketProtocol, - public senf::pool_alloc_mixin + : public ConcreteSocketProtocol, + public BSDSocketProtocol { public: ///\name Constructors @@ -99,7 +98,6 @@ namespace senf { ///\name Abstract Interface Implementation ///@{ - std::auto_ptr clone() const; unsigned available() const; bool eof() const; diff --git a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc index c4b48b1..ffefd71 100644 --- a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc +++ b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc @@ -50,12 +50,6 @@ prefix_ void senf::ConnectedUNDatagramSocketProtocol::init_client(UNSocketAddres clientHandle().connect(address); } -prefix_ std::auto_ptr senf::ConnectedUNDatagramSocketProtocol::clone() - const -{ - return std::auto_ptr(new ConnectedUNDatagramSocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "UNDatagramSocketHandle.mpp" diff --git a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh index 6a3d8c6..50ead3e 100644 --- a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh +++ b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh @@ -71,11 +71,11 @@ namespace senf { */ class ConnectedUNDatagramSocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public UNProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol, - public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol { public: /////////////////////////////////////////////////////////////////////////// @@ -98,11 +98,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle ConnectedUNDatagramClientSocketHandle; diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.cc index 77408fa..42d7f38 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.cc +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.cc @@ -51,12 +51,6 @@ prefix_ void senf::UNDatagramSocketProtocol::init_client(UNSocketAddress const & clientHandle().bind(address); } -prefix_ std::auto_ptr senf::UNDatagramSocketProtocol::clone() - const -{ - return std::auto_ptr(new UNDatagramSocketProtocol()); -} - ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "UNDatagramSocketHandle.mpp" diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.hh b/Socket/Protocols/UN/UNDatagramSocketHandle.hh index 3b7f8a5..92c2cd6 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.hh +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.hh @@ -71,7 +71,8 @@ namespace senf { Socket Handle typedefs above. */ class UNDatagramSocketProtocol - : public ConcreteSocketProtocol, + : public ConcreteSocketProtocol, public UNProtocol, public BSDSocketProtocol, public AddressableBSDSocketProtocol @@ -97,11 +98,6 @@ namespace senf { constructor */ ///@} - ///\name Abstract Interface Implementation - - std::auto_ptr clone() const; - - ///@} }; typedef ProtocolClientSocketHandle UNDatagramClientSocketHandle; diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc index 7ad720d..cf2b413 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.test.cc @@ -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) diff --git a/Socket/ServerSocketHandle.cti b/Socket/ServerSocketHandle.cti index f2342f1..e0e133f 100644 --- a/Socket/ServerSocketHandle.cti +++ b/Socket/ServerSocketHandle.cti @@ -48,8 +48,8 @@ ServerSocketHandle(ServerSocketHandle other, template prefix_ senf::ServerSocketHandle:: -ServerSocketHandle(std::auto_ptr protocol) - : SocketHandle(protocol,true) +ServerSocketHandle(std::auto_ptr body) + : SocketHandle(body) {} template @@ -95,8 +95,8 @@ template prefix_ typename senf::ServerSocketHandle::ClientSocketHandle senf::ServerSocketHandle::accept() { - return ClientSocketHandle(this->protocol().clone(), - Policy::CommunicationPolicy::accept(*this)); + return ClientSocketHandle(this->body().clone( + Policy::CommunicationPolicy::accept(*this), false)); } template diff --git a/Socket/ServerSocketHandle.hh b/Socket/ServerSocketHandle.hh index 22e9cb9..68f29b0 100644 --- a/Socket/ServerSocketHandle.hh +++ b/Socket/ServerSocketHandle.hh @@ -200,7 +200,7 @@ namespace senf { protected: ServerSocketHandle(FileHandle other, bool isChecked); - explicit ServerSocketHandle(std::auto_ptr protocol); + explicit ServerSocketHandle(std::auto_ptr body); private: diff --git a/Socket/ServerSocketHandle.test.cc b/Socket/ServerSocketHandle.test.cc index 950b072..0d9ba42 100644 --- a/Socket/ServerSocketHandle.test.cc +++ b/Socket/ServerSocketHandle.test.cc @@ -39,45 +39,45 @@ namespace { - namespace sl = senf; - class MySocketHandle - : public sl::ServerSocketHandle + : public senf::ServerSocketHandle { public: MySocketHandle() - : sl::ServerSocketHandle( - std::auto_ptr(new sl::test::SomeProtocol())) + : senf::ServerSocketHandle( + std::auto_ptr( + new senf::ProtocolSocketBody(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 OtherSocketHandle; + typedef senf::SocketHandle OtherSocketHandle; MySocketHandle myh; OtherSocketHandle osh (myh); osh = myh; - typedef sl::ServerSocketHandle SomeSocketHandle; - SomeSocketHandle ssh = sl::static_socket_cast(osh); + typedef senf::ServerSocketHandle SomeSocketHandle; + SomeSocketHandle ssh = senf::static_socket_cast(osh); - typedef sl::ServerSocketHandle::policy> SomeOtherSocketHandle; - typedef sl::ClientSocketHandle OtherClientHandle; + typedef senf::ClientSocketHandle OtherClientHandle; - BOOST_CHECK_NO_THROW( sl::dynamic_socket_cast(osh) ); - BOOST_CHECK_THROW( sl::dynamic_socket_cast(osh), + BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + BOOST_CHECK_THROW( senf::dynamic_socket_cast(osh), std::bad_cast ); - BOOST_CHECK_THROW( sl::dynamic_socket_cast(osh), + BOOST_CHECK_THROW( senf::dynamic_socket_cast(osh), std::bad_cast ); BOOST_CHECK_NO_THROW( myh.bind(0) ); diff --git a/Socket/SocketHandle.cc b/Socket/SocketHandle.cc index 562253b..042d267 100644 --- a/Socket/SocketHandle.cc +++ b/Socket/SocketHandle.cc @@ -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); } diff --git a/Socket/SocketHandle.cci b/Socket/SocketHandle.cci index c25d09f..896d13a 100644 --- a/Socket/SocketHandle.cci +++ b/Socket/SocketHandle.cci @@ -34,26 +34,23 @@ #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// -prefix_ senf::SocketBody::SocketBody(std::auto_ptr 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 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(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::clone(bool isServer) + const +{ + return protocol().clone(isServer); +} + +prefix_ std::auto_ptr senf::SocketBody::clone(int fd, bool isServer) + const +{ + return protocol().clone(fd, isServer); +} + /////////////////////////////////////////////////////////////////////////// // senf::detail::StreamableString diff --git a/Socket/SocketHandle.ct b/Socket/SocketHandle.ct index 6b66701..98ce100 100644 --- a/Socket/SocketHandle.ct +++ b/Socket/SocketHandle.ct @@ -28,6 +28,7 @@ // Custom includes #include +#include "../Utils/TypeInfo.hh" #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// @@ -45,6 +46,23 @@ senf::detail::StreamableString::operator<<(T const & other) return *this; } +/////////////////////////////////////////////////////////////////////////// +// senf::ProtocolSocketBody + +template +prefix_ senf::SocketProtocol const & senf::ProtocolSocketBody::v_protocol() + const +{ + return *this; +} + +template +prefix_ std::string senf::ProtocolSocketBody::v_protocolName() + const +{ + return senf::prettyName(typeid(SProtocol)); +} + ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ diff --git a/Socket/SocketHandle.cti b/Socket/SocketHandle.cti index 852cc3f..983c5a5 100644 --- a/Socket/SocketHandle.cti +++ b/Socket/SocketHandle.cti @@ -35,6 +35,9 @@ #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// +// senf::SocketHandle + template prefix_ senf::SocketHandle::SocketHandle() {} @@ -57,9 +60,8 @@ senf::SocketHandle::operator=(SocketHandle other) template prefix_ -senf::SocketHandle::SocketHandle(std::auto_ptr protocol, - bool isServer) - : FileHandle(std::auto_ptr(new SocketBody(protocol,isServer))) +senf::SocketHandle::SocketHandle(std::auto_ptr body) + : FileHandle(std::auto_ptr(body.release())) {} template @@ -182,6 +184,19 @@ prefix_ std::string senf::SocketHandle::dumpState(unsigned lod) return detail::dumpState(map); } +/////////////////////////////////////////////////////////////////////////// +// senf::ProtocolSocketBody + +template +prefix_ senf::ProtocolSocketBody::ProtocolSocketBody(bool isServer) + : SocketBody(isServer) +{} + +template +prefix_ senf::ProtocolSocketBody::ProtocolSocketBody(bool isServer, int fd) + : SocketBody(isServer, fd) +{} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/SocketHandle.hh b/Socket/SocketHandle.hh index 77cd781..85a14b6 100644 --- a/Socket/SocketHandle.hh +++ b/Socket/SocketHandle.hh @@ -147,7 +147,7 @@ namespace senf { documentation. */ protected: - explicit SocketHandle(std::auto_ptr protocol, bool isServer); + explicit SocketHandle(std::auto_ptr body); ///< Initialize SocketHandle providing the protocol /**< \param protocol Protocol class of the protocol implemented by this socket handle diff --git a/Socket/SocketHandle.ih b/Socket/SocketHandle.ih index 996ead4..43edd14 100644 --- a/Socket/SocketHandle.ih +++ b/Socket/SocketHandle.ih @@ -85,6 +85,8 @@ namespace senf { std::string dumpState(SocketStateMap const & map); } + template 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 + : public FileBody { public: - using senf::pool_alloc_mixin::operator new; - using senf::pool_alloc_mixin::operator delete; - /////////////////////////////////////////////////////////////////////////// // Types @@ -111,19 +109,12 @@ namespace senf { ///\name Structors and default members ///@{ - SocketBody(std::auto_ptr 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 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 clone(bool isServer) const; + std::auto_ptr 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 protocol_; + virtual SocketProtocol const & v_protocol() const = 0; + virtual std::string v_protocolName() const = 0; + bool isServer_; }; + template + class ProtocolSocketBody + : public SocketBody, + private SProtocol, + public senf::pool_alloc_mixin< ProtocolSocketBody > + { + public: + typedef SProtocol Protocol; + + using senf::pool_alloc_mixin< ProtocolSocketBody >::operator new; + using senf::pool_alloc_mixin< ProtocolSocketBody >::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; + }; + } ///////////////////////////////ih.e//////////////////////////////////////// diff --git a/Socket/SocketHandle.test.cc b/Socket/SocketHandle.test.cc index 0bcb477..9312676 100644 --- a/Socket/SocketHandle.test.cc +++ b/Socket/SocketHandle.test.cc @@ -37,15 +37,15 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - namespace sl = senf; class MySocketHandle - : public sl::SocketHandle + : public senf::SocketHandle { public: MySocketHandle() - : sl::SocketHandle( - std::auto_ptr(new sl::test::SomeProtocol()),false) + : senf::SocketHandle( + std::auto_ptr( + new senf::ProtocolSocketBody(false))) {} }; @@ -53,30 +53,29 @@ namespace { : public senf::FileHandle { public: - FDHandle() - : senf::FileHandle(std::auto_ptr( - new senf::FileBody())) {} + FDHandle() : senf::FileHandle(std::auto_ptr(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 OtherSocketHandle; + typedef senf::SocketHandle OtherSocketHandle; MySocketHandle myh; OtherSocketHandle osh (myh); osh = myh; - typedef sl::SocketHandle SomeSocketHandle; + typedef senf::SocketHandle SomeSocketHandle; SomeSocketHandle ssh = senf::static_socket_cast(osh); BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(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 >\n" - "socket.policy: senf::SocketPolicy\n" "socket.protocol: senf::test::SomeProtocol\n" + "socket.protocol.policy: senf::SocketPolicy\n" "socket.server: false\n" ); } diff --git a/Socket/SocketProtocol.cci b/Socket/SocketProtocol.cci index 5f8bbb6..04be16c 100644 --- a/Socket/SocketProtocol.cci +++ b/Socket/SocketProtocol.cci @@ -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_ diff --git a/Socket/SocketProtocol.cti b/Socket/SocketProtocol.cti index 1c16b75..4751ec4 100644 --- a/Socket/SocketProtocol.cti +++ b/Socket/SocketProtocol.cti @@ -35,32 +35,56 @@ /////////////////////////////////////////////////////////////////////////// // senf::ConcreteSocketProtocol -template -prefix_ senf::ConcreteSocketProtocol::~ConcreteSocketProtocol() +template +prefix_ senf::ConcreteSocketProtocol::~ConcreteSocketProtocol() {} -template -prefix_ typename senf::ConcreteSocketProtocol::Policy const & -senf::ConcreteSocketProtocol::policy() +template +prefix_ typename senf::ConcreteSocketProtocol::Policy const & +senf::ConcreteSocketProtocol::policy() const { return policy_; } +template +prefix_ std::auto_ptr +senf::ConcreteSocketProtocol::clone(bool isServer) + const +{ + return std::auto_ptr(new ProtocolSocketBody(isServer)); +} + +template +prefix_ std::auto_ptr +senf::ConcreteSocketProtocol::clone(int fd, bool isServer) + const +{ + return std::auto_ptr(new ProtocolSocketBody(isServer, fd)); +} + +template +prefix_ senf::SocketBody & senf::ConcreteSocketProtocol::body() + const +{ + return const_cast< ProtocolSocketBody &>( + static_cast< ProtocolSocketBody const & >(*this)); +} + //////////////////////////////////////// // protected members -template +template prefix_ senf::ClientSocketHandle -senf::ConcreteSocketProtocol::clientHandle() +senf::ConcreteSocketProtocol::clientHandle() const { return static_socket_cast< ClientSocketHandle >(fh()); } -template +template prefix_ senf::ServerSocketHandle -senf::ConcreteSocketProtocol::serverHandle() +senf::ConcreteSocketProtocol::serverHandle() const { return static_socket_cast< ServerSocketHandle >(fh()); diff --git a/Socket/SocketProtocol.hh b/Socket/SocketProtocol.hh index 7c34b3a..50301f9 100644 --- a/Socket/SocketProtocol.hh +++ b/Socket/SocketProtocol.hh @@ -153,14 +153,6 @@ namespace senf { /////////////////////////////////////////////////////////////////////////// // Virtual interface - virtual std::auto_ptr 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 clone(bool isServer) const = 0; + virtual std::auto_ptr 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 + template class ConcreteSocketProtocol : public virtual SocketProtocol { @@ -312,7 +303,7 @@ namespace senf { /////////////////////////////////////////////////////////////////////////// Policy const & policy() const; - + protected: ClientSocketHandle clientHandle() const; ///< Get client handle for associated socket @@ -324,8 +315,11 @@ namespace senf { this protocol instance */ private: - Policy policy_; + virtual std::auto_ptr clone(bool isServer) const; + virtual std::auto_ptr clone(int fd, bool isServer) const; + virtual SocketBody & body() const; + Policy policy_; }; /// @} diff --git a/Socket/SocketProtocol.test.hh b/Socket/SocketProtocol.test.hh index 220864d..f1459fe 100644 --- a/Socket/SocketProtocol.test.hh +++ b/Socket/SocketProtocol.test.hh @@ -32,11 +32,10 @@ ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - namespace test { class SomeProtocol - : public ConcreteSocketProtocol + : public ConcreteSocketProtocol { public: ~SomeProtocol() {} @@ -44,8 +43,6 @@ namespace test { void init_client() const {} void init_server() const {} - std::auto_ptr clone() const - { return std::auto_ptr(new SomeProtocol()); } unsigned available() const { return Policy::ReadPolicy::TEST_SIZE; } bool eof() const