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>
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();
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)
// 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 );
}
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();
}
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() );
}
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
// End:
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))
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() );
}
"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" );
}
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
{
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
{
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"
/** \brief xxx
*/
class DVBDemuxSectionProtocol
- : public ConcreteSocketProtocol<DVBDemux_Policy>,
+ : public ConcreteSocketProtocol<DVBDemux_Policy, DVBDemuxSectionProtocol>,
public DVBDemuxProtocol
{
public:
unsigned available() const;
- std::auto_ptr<SocketProtocol> clone() const;
-
///@}
void setSectionFilter(struct dmx_sct_filter_params *filter) const;
/** \brief xxx
*/
class DVBDemuxPESProtocol
- : public ConcreteSocketProtocol<DVBDemux_Policy>,
+ : public ConcreteSocketProtocol<DVBDemux_Policy,DVBDemuxPESProtocol>,
public DVBDemuxProtocol
{
public:
unsigned available() const;
- std::auto_ptr<SocketProtocol> clone() const;
-
///@}
void setPESFilter(struct dmx_pes_filter_params *filter) const;
/** \brief xxx
*/
class DVBDvrProtocol
- : public ConcreteSocketProtocol<DVBDemux_Policy>,
+ : public ConcreteSocketProtocol<DVBDemux_Policy, DVBDvrProtocol>,
public DVBDemuxProtocol
{
public:
unsigned available() const;
- std::auto_ptr<SocketProtocol> clone() const;
-
///@}
};
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
{
/** \brief xxx
*/
class DVBFrontendProtocol
- : public ConcreteSocketProtocol<DVBFrontend_Policy>
+ : public ConcreteSocketProtocol<DVBFrontend_Policy, DVBFrontendProtocol>
{
public:
///////////////////////////////////////////////////////////////////////////
unsigned available() const;
bool eof() const;
- std::auto_ptr<SocketProtocol> clone() const;
-
///@}
void signalStrength(int16_t *strength) const;
clientHandle().connect(address);
}
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV4SocketProtocol::clone()
- const
-{
- return std::auto_ptr<SocketProtocol>(new ConnectedRawV4SocketProtocol());
-}
-
///////////////////////////////////////////////////////////////////////////
// senf::UDPv6SocketProtocol::
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"
\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:
///////////////////////////////////////////////////////////////////////////
\param[in] address local address to connect to */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol> ConnectedRawV4ClientSocketHandle;
\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:
///////////////////////////////////////////////////////////////////////////
constructor (??) */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol> ConnectedRawV6ClientSocketHandle;
clientHandle().connect(address);
}
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv4SocketProtocol::clone()
- const
-{
- return std::auto_ptr<SocketProtocol>(new ConnectedUDPv4SocketProtocol());
-}
-
///////////////////////////////////////////////////////////////////////////
// senf::ConnectedUDPv6SocketProtocol::
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"
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<
clientHandle().bind(address);
}
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV4SocketProtocol::clone()
- const
-{
- return std::auto_ptr<SocketProtocol>(new RawV4SocketProtocol());
-}
-
///////////////////////////////////////////////////////////////////////////
// senf::RawV6SocketProtocol::
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"
\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:
///////////////////////////////////////////////////////////////////////////
\param[in] address local address to bind to */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<RawV4SocketProtocol> RawV4ClientSocketHandle;
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<RawV6SocketProtocol> RawV6ClientSocketHandle;
throwErrno();
}
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::TCPv4SocketProtocol::clone()
- const
-{
- return std::auto_ptr<SocketProtocol>(new TCPv4SocketProtocol());
-}
-
///////////////////////////////////////////////////////////////////////////
// senf::TCPv6SocketProtocol::
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"
#define HH_TCPSocketHandle_ 1
// Custom includes
-#include "../../../Utils/pool_alloc_mixin.hh"
#include "INetProtocol.hh"
#include "TCPProtocol.hh"
#include "../../../Socket/Protocols/BSDSocketProtocol.hh"
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<TCPv4SocketProtocol> TCPv4ClientSocketHandle;
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<TCPv6SocketProtocol> TCPv6ClientSocketHandle;
clientHandle().bind(address);
}
-prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv4SocketProtocol::clone()
- const
-{
- return std::auto_ptr<SocketProtocol>(new UDPv4SocketProtocol());
-}
-
///////////////////////////////////////////////////////////////////////////
// senf::UDPv6SocketProtocol::
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"
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
\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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<UDPv6SocketProtocol> UDPv6ClientSocketHandle;
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
{
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 };
///\name Abstract Interface Implementation
///@{
- std::auto_ptr<SocketProtocol> clone() const;
unsigned available() const;
bool eof() const;
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
{
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
///\name Abstract Interface Implementation
///@{
- std::auto_ptr<SocketProtocol> clone() const;
unsigned available() const;
bool eof() const;
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"
*/
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:
///////////////////////////////////////////////////////////////////////////
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<ConnectedUNDatagramSocketProtocol> ConnectedUNDatagramClientSocketHandle;
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"
Socket Handle typedefs above.
*/
class UNDatagramSocketProtocol
- : public ConcreteSocketProtocol<UNDatagramSocket_Policy>,
+ : public ConcreteSocketProtocol<UNDatagramSocket_Policy,
+ UNDatagramSocketProtocol>,
public UNProtocol,
public BSDSocketProtocol,
public AddressableBSDSocketProtocol
constructor */
///@}
- ///\name Abstract Interface Implementation
-
- std::auto_ptr<SocketProtocol> clone() const;
-
- ///@}
};
typedef ProtocolClientSocketHandle<UNDatagramSocketProtocol> UNDatagramClientSocketHandle;
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)
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>
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>
protected:
ServerSocketHandle(FileHandle other, bool isChecked);
- explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol);
+ explicit ServerSocketHandle(std::auto_ptr<SocketBody> body);
private:
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) );
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);
}
#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()
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
// Custom includes
#include <boost/lexical_cast.hpp>
+#include "../Utils/TypeInfo.hh"
#define prefix_
///////////////////////////////ct.p////////////////////////////////////////
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_
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+// senf::SocketHandle<SocketPolicy>
+
template <class SocketPolicy>
prefix_ senf::SocketHandle<SocketPolicy>::SocketHandle()
{}
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>
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_
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
std::string dumpState(SocketStateMap const & map);
}
+ template <class Policy, class Self> class ConcreteSocketProtocol;
+
/** \brief SocketHandle referenced body
\internal
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
///\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
///@}
///////////////////////////////////////////////////////////////////////////
- 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
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////////////////////////////////////////
///////////////////////////////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)))
{}
};
: 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;
"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" );
}
//#include "SocketProtocol.ih"
// Custom includes
-#include <../Utils/senfassert.hh>
+#include "../Utils/senfassert.hh"
+#include "../Utils/Logger/SenfLog.hh"
#define prefix_ inline
///////////////////////////////cci.p///////////////////////////////////////
}
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_
///////////////////////////////////////////////////////////////////////////
// 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());
///////////////////////////////////////////////////////////////////////////
// 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
::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;
};
\doc init_client init_server
*/
- template <class SocketPolicy>
+ template <class SocketPolicy, class Self>
class ConcreteSocketProtocol
: public virtual SocketProtocol
{
///////////////////////////////////////////////////////////////////////////
Policy const & policy() const;
-
+
protected:
ClientSocketHandle<Policy> clientHandle() const;
///< Get client handle for associated socket
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_;
};
/// @}
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
-
namespace test {
class SomeProtocol
- : public ConcreteSocketProtocol<SomeSocketPolicy>
+ : public ConcreteSocketProtocol<SomeSocketPolicy,SomeProtocol>
{
public:
~SomeProtocol() {}
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