std::ostream& stream;
public:
- MCSniffer(senf::INet4SocketAddress addr, std::ostream& s)
+ MCSniffer(senf::INet4Address addr, std::ostream& s)
: stream(s)
{
- sock.protocol().bind(addr);
+ // sock.bind(addr);
sock.protocol().mcLoop(true);
sock.protocol().mcAddMembership(addr);
senf::Scheduler::instance().add(
std::ofstream f2 ("233.132.152.2.txt");
MCSniffer sniffer1 (
- senf::INet4SocketAddress("233.132.152.1:22344"), f1);
+ senf::INet4Address::from_string("233.132.152.1"), f1);
MCSniffer sniffer2 (
- senf::INet4SocketAddress("233.132.152.2:22344"), f2);
+ senf::INet4Address::from_string("233.132.152.2"), f2);
senf::Scheduler::instance().process();
}
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-// Stefan Bund <g0dil@berlios.de>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-/** \file
- \brief BufferingPolicy non-inline non-template implementation
- */
-
-#include "BufferingPolicy.hh"
-//#include "BufferingPolicy.ih"
-
-// Custom includes
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include "../Utils/Exception.hh"
-
-//#include "BufferingPolicy.mpp"
-#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
-
-prefix_ unsigned senf::SocketBufferingPolicy::rcvbuf(FileHandle handle)
-{
- unsigned size;
- socklen_t len (sizeof(size));
- if (::getsockopt(handle.fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
- throwErrno();
- // Linux doubles the bufer size on setting the RCVBUF to cater for internal
- // headers. We fix this up here .. (see lkml FAQ)
- return size/2;
-}
-
-prefix_ void senf::SocketBufferingPolicy::rcvbuf(FileHandle handle, unsigned size)
-{
- if (::setsockopt(handle.fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
- throwErrno();
-}
-
-prefix_ unsigned senf::SocketBufferingPolicy::sndbuf(FileHandle handle)
-{
- unsigned size;
- socklen_t len (sizeof(size));
- if (::getsockopt(handle.fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
- throwErrno();
- // Linux doubles the bufer size on setting the SNDBUF to cater for internal
- // headers. We fix this up here .. (see lkml FAQ)
- return size/2;
-
-}
-
-prefix_ void senf::SocketBufferingPolicy::sndbuf(FileHandle handle, unsigned size)
-{
- if (::setsockopt(handle.fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
- throwErrno();
-}
-
-///////////////////////////////cc.e////////////////////////////////////////
-#undef prefix_
-//#include "BufferingPolicy.mpp"
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-// Stefan Bund <g0dil@berlios.de>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-/** \file
- \brief BufferingPolicy public header
- */
-
-#ifndef HH_BufferingPolicy_
-#define HH_BufferingPolicy_ 1
-
-// Custom includes
-#include "FileHandle.hh"
-#include "SocketPolicy.hh"
-
-//#include "BufferingPolicy.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
-
-namespace senf {
-
- /// \addtogroup policy_impl_group
- /// @{
-
- /** \brief BufferingPolicy for non-buffered sockets
-
- This is different from UndefinedBufferingPolicy (which is the
- same as BufferingPolicyBase). This policy class defines the
- buffering policy -- it explicitly states, that the socket does not
- support buffering.
- */
- struct NoBufferingPolicy : public BufferingPolicyBase
- {};
-
- /** \brief BufferingPolicy implementing standard socket buffering
-
- This policy class implements standard BSD socket buffering.
-
- \todo Shouldn't this be dependent on Read / WritePolicy ?
- */
- struct SocketBufferingPolicy : public BufferingPolicyBase
- {
- static unsigned rcvbuf(FileHandle handle);
- ///< Check receive buffer size
- /**< \param[in] handle socket handle to check
- \returns size of receive buffer in bytes */
- static void rcvbuf(FileHandle handle, unsigned size);
- ///< Change receive buffer size
- /**< \param[in] handle socket handle
- \param[in] size new receive buffer size */
-
- static unsigned sndbuf(FileHandle handle);
- ///< Check send buffer size
- /**< \param[in] handle socket handle to check
- \returns size of send buffer in bytes */
- static void sndbuf(FileHandle handle, unsigned size);
- ///< Change size of send buffer
- /**< \param[in] handle socket handle
- \param[in] size new send buffer size */
- };
-
- /// @}
-
-}
-
-///////////////////////////////hh.e////////////////////////////////////////
-//#include "BufferingPolicy.cci"
-//#include "BufferingPolicy.ct"
-//#include "BufferingPolicy.cti"
-//#include "BufferingPolicy.mpp"
-#endif
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
}
////////////////////////////////////////
-// Buffering
-
-// senf::ClientSocketHandle<Policy>::rcvbuf
-
-template <class Policy>
-prefix_ unsigned senf::ClientSocketHandle<Policy>::rcvbuf()
-{
- return Policy::BufferingPolicy::rcvbuf(*this);
-}
-
-template <class Policy>
-prefix_ void senf::ClientSocketHandle<Policy>::rcvbuf(unsigned size)
-{
- Policy::BufferingPolicy::rcvbuf(*this,size);
-}
-
-// senf::ClientSocketHandle<Policy>::sndbuf
-
-template <class Policy>
-prefix_ unsigned senf::ClientSocketHandle<Policy>::sndbuf()
-{
- return Policy::BufferingPolicy::sndbuf(*this);
-}
-
-template <class Policy>
-prefix_ void senf::ClientSocketHandle<Policy>::sndbuf(unsigned size)
-{
- Policy::BufferingPolicy::sndbuf(*this,size);
-}
-
-////////////////////////////////////////
// Casting
template <class Policy>
<tr><td>bind()</td> <td>AddressingPolicy::bind (\ref senf::AddressingPolicyBase)</td> <td></td></tr>
<tr><td>peer()</td> <td>AddressingPolicy::peer (\ref senf::AddressingPolicyBase)</td> <td></td></tr>
<tr><td>local()</td> <td>AddressingPolicy::local (\ref senf::AddressingPolicyBase)</td> <td></td></tr>
- <tr><td>rcvbuf()</td> <td>BufferingPolicy::sndbuf (\ref senf::BufferingPolicyBase)</td> <td></td></tr>
- <tr><td>sndbuf()</td> <td>BufferingPolicy::rcvbuf (\ref senf::BufferingPolicyBase)</td> <td></td></tr>
</table>
It is important to note, that not all members are always accessible. Which are depends on
///@}
- ///////////////////////////////////////////////////////////////////////////
- ///\name Buffering
- ///@{
-
- unsigned rcvbuf (); ///< Check size of receive buffer
- /**< \returns size of receive buffer in bytes */
- void rcvbuf (unsigned size);
- ///< Set size of receive buffer
- /**< \param[in] size size of receive buffer in bytes */
-
- unsigned sndbuf (); ///< Check size of send buffer
- /**< \returns size of send buffer in bytes */
- void sndbuf (unsigned size);
- ///< Set size of send buffer
- /**< \param[in] size size of send buffer in bytes */
-
- ///@}
-
static ClientSocketHandle cast_static(FileHandle handle);
static ClientSocketHandle cast_dynamic(FileHandle handle);
BOOST_CHECK_NO_THROW( myh.bind(0) );
BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.peer(), 1u ) );
BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.local(), 2u ) );
-
- BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.rcvbuf(), 0u ) );
- BOOST_CHECK_NO_THROW( myh.rcvbuf(1) );
- BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.sndbuf(), 0u ) );
- BOOST_CHECK_NO_THROW( myh.sndbuf(1) );
}
///////////////////////////////cc.e////////////////////////////////////////
"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, senf::test::SomeBufferingPolicy>\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.server: true\n" );
throwErrno();
}
-prefix_ struct timeval senf::BSDSocketProtocol::timestamp()
- const
-{
- struct timeval tv;
- if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
- throwErrno();
- return tv;
-}
-
///////////////////////////////////////////////////////////////////////////
prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
throwErrno();
}
-///////////////////////////////cc.e////////////////////////////////////////
+prefix_ boost::uint8_t senf::AddressableBSDSocketProtocol::priority()
+ const
+{
+ int value;
+ socklen_t len (sizeof(value));
+ if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
+ throwErrno();
+ return value;
+}
+
+prefix_ void senf::AddressableBSDSocketProtocol::priority(boost::uint8_t value)
+ const
+{
+ int ivalue (value);
+ if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
+ throwErrno();
+}
+
+prefix_ unsigned senf::AddressableBSDSocketProtocol::rcvbuf()
+ const
+{
+ unsigned size;
+ socklen_t len (sizeof(size));
+ if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
+ throwErrno();
+ // Linux doubles the bufer size on setting the RCVBUF to cater for internal
+ // headers. We fix this up here .. (see lkml FAQ)
+ return size/2;
+}
+
+prefix_ void senf::AddressableBSDSocketProtocol::rcvbuf(unsigned size)
+ const
+{
+ if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
+ throwErrno();
+}
+
+prefix_ unsigned senf::AddressableBSDSocketProtocol::sndbuf()
+ const
+{
+ unsigned size;
+ socklen_t len (sizeof(size));
+ if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
+ throwErrno();
+ // Linux doubles the bufer size on setting the SNDBUF to cater for internal
+ // headers. We fix this up here .. (see lkml FAQ)
+ return size/2;
+}
+
+prefix_ void senf::AddressableBSDSocketProtocol::sndbuf(unsigned size)
+ const
+{
+ if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
+ throwErrno();
+}
+
+/////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "BSDSocketProtocol.mpp"
#define HH_BSDSocketProtocol_ 1
// Custom includes
-#include <sys/time.h>
#include "../../Socket/SocketProtocol.hh"
+#include <boost/cstdint.hpp>
//#include "BSDSocketProtocol.mpp"
///////////////////////////////hh.p////////////////////////////////////////
\param[in] enable \c true to activate linger
\param[in] timeout linger timeout in seconds */
- struct timeval timestamp() const; ///< Return packet timestamp of last packet
- /**< The returned timestamp represents the time, at which
- the last network packet passed to the user has been
- received from the network. This allows precise network
- timing.
- \returns timestamp when packet was received
- \todo Move this to DatagramSocketProtocol class */
};
/** \brief Protocol facet providing basic connection oriented BSD socket functions
/**< A \c true value enables \c SO_REUSEADDR, \c false will
disable it.
\param[in] value new \c SO_REUSEADDR state */
+
+ boost::uint8_t priority() const; ///< Get packet priority assigned to outgoing packets
+ /**< This call will return the priority value assigned to
+ packets sent via this socket. Depending on the
+ protocol, this value may also be placed inside the
+ packet headers (for IPv4, this is the TOS value).
+ \returns current socket priority */
+ void priority(boost::uint8_t value) const; ///< Set packet priority (e.g. TOS)
+ /**< Changes the packet queueing priority. Additionally may
+ set protocol specific options. For IPv4 sockets, it
+ sets the TOS field.
+ \param[in] v new socket priority */
+
+ unsigned rcvbuf() const; ///< Check receive buffer size
+ /**< \param[in] handle socket handle to check
+ \returns size of receive buffer in bytes */
+ void rcvbuf(unsigned size) const; ///< Change receive buffer size
+ /**< \param[in] handle socket handle
+ \param[in] size new receive buffer size */
+
+ unsigned sndbuf() const; ///< Check send buffer size
+ /**< \param[in] handle socket handle to check
+ \returns size of send buffer in bytes */
+ void sndbuf(unsigned size) const; ///< Change size of send buffer
+ /**< \param[in] handle socket handle
+ \param[in] size new send buffer size */
+
};
/// @}
#define HH_DVBDemuxHandles_ 1
// Custom includes
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
ReadablePolicy,
- NotWriteablePolicy,
- NoBufferingPolicy
+ NotWriteablePolicy
>::policy DVBDemux_Policy; ///< Socket Policy for xxxx
/** \brief xxx
///@}
};
+
+ /// @}
}
///////////////////////////////hh.e////////////////////////////////////////
// Custom includes
#include <boost/cstdint.hpp>
#include <linux/dvb/frontend.h>
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
NotReadablePolicy,
- NotWriteablePolicy,
- NoBufferingPolicy
+ NotWriteablePolicy
>::policy DVBFrontend_Policy; ///< Socket Policy for xxxx
/** \brief xxx
// $Id$
//
// Copyright (C) 2007
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-// David Wagner <dw6@berlios.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+/** \file
+ \brief DatagramSocketProtocol non-inline non-template implementation */
-#include "RawInetProtocol.hh"
+#include "DatagramSocketProtocol.hh"
+//#include "DatagramSocketProtocol.ih"
// Custom includes
+#include <sys/types.h>
#include <sys/socket.h>
-#include <netinet/in.h>
#include <sys/ioctl.h>
-#include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
-#include <net/if.h> // for if_nametoindex
-#include "../../../Socket/SocketHandle.hh"
-//#include "UDPProtocol.mpp"
+//#include "DatagramSocketProtocol.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-prefix_ unsigned senf::RawInetProtocol::available()
+prefix_ struct timeval senf::DatagramSocketProtocol::timestamp()
const
{
- int n;
- if (::ioctl(fd(),SIOCINQ,&n) < 0)
+ struct timeval tv;
+ if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
throwErrno();
- return n;
-}
-
-prefix_ bool senf::RawInetProtocol::eof()
- const
-{
- return false;
+ return tv;
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-//#include "UDPProtocol.mpp"
+//#include "DatagramSocketProtocol.mpp"
\f
// Local Variables:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief DatagramSocketProtocol public header */
+
+#ifndef HH_DatagramSocketProtocol_
+#define HH_DatagramSocketProtocol_ 1
+
+// Custom includes
+#include <sys/time.h>
+#include "../../Socket/SocketProtocol.hh"
+
+//#include "DatagramSocketProtocol.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ ///\addtogroup protocol_facets_group
+ ///\{
+
+ /** \brief Protocol facet providing generic BSD datagram socket functionality
+ */
+ class DatagramSocketProtocol
+ : public virtual SocketProtocol
+ {
+ public:
+ struct timeval timestamp() const; ///< Return packet timestamp of last packet
+ /**< The returned timestamp represents the time, at which
+ the last network packet passed to the user has been
+ received from the network. This allows precise network
+ timing.
+ \pre The \c SO_TIMESTAMP socket option must not be set
+ on the socket.
+ \returns timestamp when last packet was received
+ \todo Move this to DatagramSocketProtocol class */
+ };
+
+
+ ///\}
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "DatagramSocketProtocol.cci"
+//#include "DatagramSocketProtocol.ct"
+//#include "DatagramSocketProtocol.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
-// $Id$
+// $Id: ConnectedRawINetSocketHandle.cc 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#include "ConnectedRawInetSocketHandle.hh"
+#include "ConnectedRawINetSocketHandle.hh"
// Custom includes
#include <sys/types.h>
const
{
init_client(protocol);
- connect(address);
+ clientHandle().connect(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV4SocketProtocol::clone()
const
{
init_client(protocol);
- connect(address);
+ clientHandle().connect(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV6SocketProtocol::clone()
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-//#include "ConnectedRawInetSocketHandle.mpp"
+//#include "ConnectedRawINetSocketHandle.mpp"
\f
// Local Variables:
-// $Id$
+// $Id: ConnectedRawINetSocketHandle.hh 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Custom includes
#include "INetProtocol.hh"
-#include "RawInetProtocol.hh"
+#include "RawINetProtocol.hh"
#include "../../../Socket/Protocols/BSDSocketProtocol.hh"
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
DatagramFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy ConnectedRawV4Socket_Policy; ///< Socket Policy of the Connected RawV4 Protocol
/** \brief IPv4 RAW Socket Protocol, connected
class ConnectedRawV4SocketProtocol
: public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy>,
public IPv4Protocol,
- public RawInetProtocol,
+ public RawINetProtocol,
public BSDSocketProtocol,
public AddressableBSDSocketProtocol//,
// public senf::pool_alloc_mixin<RawV4Socket_Policy>
DatagramFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy ConnectedRawV6Socket_Policy; ///< Socket Policy of the RawV6 Protocol
/** \brief IPv6 RAW Socket Protocol, connected
class ConnectedRawV6SocketProtocol
: public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy>,
public IPv6Protocol,
- public RawInetProtocol,
+ public RawINetProtocol,
public BSDSocketProtocol,
public AddressableBSDSocketProtocol//,
// public senf::pool_alloc_mixin<RawV6SocketProtocol>
const
{
init_client();
- connect(address);
+ clientHandle().connect(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv4SocketProtocol::clone()
const
{
init_client();
- connect(address);
+ clientHandle().connect(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv6SocketProtocol::clone()
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
//#include "ConnectedUDPSocketHandle.mpp"
DatagramFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy ConnectedUDPv4Socket_Policy; ///< Socket Policy of the UDPv4 Protocol
/** \brief IPv4 UDP Socket Protocol, connected
// Custom includes
#include <sys/socket.h>
#include <netinet/in.h>
+#include <net/if.h>
#include "../../../Utils/Exception.hh"
//#include "INetProtocol.mpp"
///////////////////////////////cc.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// senf::IPv4Protocol
+// senf::INetProtocol
-prefix_ void senf::IPv4Protocol::connect(INet4SocketAddress const & address)
+prefix_ void senf::INetProtocol::bindInterface(std::string const & iface)
const
{
- if (::connect(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
- throwErrno();
+ if (::setsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) < 0)
+ throwErrno("::setsockopt(SO_BINDTODEVICE)");
}
-prefix_ void senf::IPv4Protocol::bind(INet4SocketAddress const & address)
- const
+prefix_ std::string senf::INetProtocol::bindInterface()
{
- if (::bind(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
- throwErrno();
+ char iface[IFNAMSIZ];
+ socklen_t size (sizeof(iface));
+ ::memset(iface, 0, sizeof(iface));
+ if (::getsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface, &size) < 0)
+ throwErrno("::getsockopt(SO_BINDTODEVICE)");
+ iface[size < IFNAMSIZ ? size : IFNAMSIZ-1] = 0;
+ return iface;
}
+///////////////////////////////////////////////////////////////////////////
+// senf::IPv4Protocol
///////////////////////////////////////////////////////////////////////////
// senf::IPv6Protocol
-prefix_ void senf::IPv6Protocol::connect(INet6SocketAddress const & address)
- const
-{
- if (::connect(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
- throwErrno();
-}
-
-prefix_ void senf::IPv6Protocol::bind(INet6SocketAddress const & address)
- const
-{
- if (::bind(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
- throwErrno();
-}
-
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "INetProtocol.mpp"
/// \addtogroup protocol_facets_group
/// @{
+ class INetProtocol
+ : public virtual SocketProtocol
+ {
+ public:
+ void bindInterface(std::string const & iface) const;
+ ///< Bind socket to specific interface
+ /**< When a socket is bound to an interface, it will only
+ receive data received on that interface. If the
+ interface name is empty, the binding is removed.
+
+ \param[in] iface name of interface to bind to or empty
+ to remove binding
+
+ \implementation Sets the SO_BINDTODEVICE socket option
+ */
+ std::string bindInterface(); ///< Get bound interface
+ /**< Returns the interface, the socket is currently bound
+ to. Returns the empty string, if not bound to any
+ interface.
+ \returns Bound interface name */
+ };
+
/** \brief Protocol facet providing IPv4 Addressing related API
This protocol facet introduces all the socket api protocol members which are related to IPv4
: public virtual SocketProtocol
{
public:
- void connect(INet4SocketAddress const & address) const; ///< Connect to remote address
- /**< \todo make this obsolete by allowing access to the
- ClientSocketHandle from ConcreateSocketProtocol
- \param[in] address Address to connect to */
- void bind(INet4SocketAddress const & address) const; ///< Set local socket address
- /**< \todo make this obsolete by allowing access to the
- ClientSocketHandle from ConcreateSocketProtocol
- \param[in] address Address to set */
};
/** \brief Protocol facet providing IPv6 Addressing related API
: public virtual SocketProtocol
{
public:
- void connect(INet6SocketAddress const & address) const; ///< Connect to remote address
- /**< \todo make this obsolete by allowing access to the
- ClientSocketHandle from ConcreateSocketProtocol
- \param[in] address Address to connect to */
- void bind(INet6SocketAddress const & address) const; ///< Set local socket address
- /**< \todo make this obsolete by allowing access to the
- ClientSocketHandle from ConcreateSocketProtocol
- \param[in] address Address to set */
};
/// @}
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief MulticastProtocol non-inline non-template implementation */
+
+#include "MulticastProtocol.hh"
+//#include "MulticastProtocol.ih"
+
+// Custom includes
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if.h> // for if_nametoindex
+
+//#include "MulticastProtocol.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::MulticastProtocol
+
+prefix_ void senf::MulticastProtocol::broadcastEnabled(bool v)
+{
+ int ivalue (v);
+ if (::setsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &ivalue, sizeof(ivalue)) < 0)
+ throwErrno("::setsockopt(SO_BROADCAST)");
+}
+
+prefix_ bool senf::MulticastProtocol::broadcastEnabled()
+{
+ int value (0);
+ ::socklen_t len (sizeof(value));
+ if (::getsockopt(fd(), SOL_SOCKET, SO_BROADCAST, &value, &len) < 0)
+ throwErrno("::getsockopt(SO_BROADCAST)");
+ return value;
+}
+
+prefix_ bool senf::MulticastProtocol::mcLoop()
+ const
+{
+ int value;
+ socklen_t len (sizeof(value));
+ if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
+ throwErrno();
+ return value;
+}
+
+prefix_ void senf::MulticastProtocol::mcLoop(bool value)
+ const
+{
+ int ivalue (value);
+ if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
+ throwErrno();
+}
+
+prefix_ void senf::MulticastProtocol::mcIface(std::string const & iface)
+ const
+{
+ struct ip_mreqn mreqn;
+ ::memset(&mreqn,sizeof(mreqn),0);
+ if (!iface.empty()) {
+ mreqn.imr_ifindex = if_nametoindex(iface.c_str());
+ if (mreqn.imr_ifindex == 0)
+ throwErrno(EINVAL);
+ }
+ if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno();
+}
+
+prefix_ unsigned senf::MulticastProtocol::mcTTL()
+ const
+{
+ int value;
+ socklen_t len (sizeof(value));
+ if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
+ throwErrno();
+ return value;
+}
+
+prefix_ void senf::MulticastProtocol::mcTTL(unsigned value)
+ const
+{
+ if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
+ throwErrno();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::INet4MulticastProtocol
+
+prefix_ void senf::INet4MulticastProtocol::mcAddMembership(INet4Address const & mcAddr)
+ const
+{
+ struct ip_mreqn mreqn;
+ mreqn.imr_multiaddr.s_addr = mcAddr.inaddr();
+ mreqn.imr_address.s_addr = htons(INADDR_ANY);
+ mreqn.imr_ifindex = 0;
+ if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno("::setsockopt(IP_ADD_MEMBERSHIP");
+}
+
+prefix_ void senf::INet4MulticastProtocol::mcAddMembership(INet4Address const & mcAddr,
+ INet4Address const & localAddr)
+ const
+{
+ struct ip_mreqn mreqn;
+ mreqn.imr_multiaddr.s_addr = mcAddr.inaddr();
+ mreqn.imr_address.s_addr = localAddr.inaddr();
+ mreqn.imr_ifindex = 0;
+ if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno("::setsockopt(IP_ADD_MEMBERSHIP");
+}
+
+prefix_ void senf::INet4MulticastProtocol::mcAddMembership(INet4Address const & mcAddr,
+ std::string const & iface)
+ const
+{
+ struct ip_mreqn mreqn;
+ mreqn.imr_multiaddr.s_addr = mcAddr.inaddr();
+ mreqn.imr_address.s_addr = htons(INADDR_ANY);
+ mreqn.imr_ifindex = if_nametoindex(iface.c_str());
+ if (mreqn.imr_ifindex == 0)
+ throwErrno("::if_nametoindex()",ENOENT);
+ if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno("::setsockopt(IP_ADD_MEMBERSHIP");
+}
+
+prefix_ void senf::INet4MulticastProtocol::mcDropMembership(INet4Address const & mcAddr)
+ const
+{
+ struct ip_mreqn mreqn;
+ mreqn.imr_multiaddr.s_addr = mcAddr.inaddr();
+ mreqn.imr_address.s_addr = htons(INADDR_ANY);
+ mreqn.imr_ifindex = 0;
+ if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno();
+}
+
+prefix_ void senf::INet4MulticastProtocol::mcDropMembership(INet4Address const & mcAddr,
+ INet4Address const & localAddr)
+ const
+{
+ struct ip_mreqn mreqn;
+ mreqn.imr_multiaddr.s_addr = mcAddr.inaddr();
+ mreqn.imr_address.s_addr = localAddr.inaddr();
+ mreqn.imr_ifindex = 0;
+ if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno();
+}
+
+prefix_ void senf::INet4MulticastProtocol::mcDropMembership(INet4Address const & mcAddr,
+ std::string const & iface)
+ const
+{
+ struct ip_mreqn mreqn;
+ mreqn.imr_multiaddr.s_addr = mcAddr.inaddr();
+ mreqn.imr_address.s_addr = htons(INADDR_ANY);
+ mreqn.imr_ifindex = if_nametoindex(iface.c_str());
+ if (mreqn.imr_ifindex == 0)
+ throwErrno("::if_nametoindex()",ENOENT);
+ if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::INet6MulticastProtocol
+
+prefix_ void senf::INet6MulticastProtocol::mcAddMembership(INet6Address const & mcAddr)
+ const
+{
+ struct ipv6_mreq mreqn;
+ std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
+ mreqn.ipv6mr_interface = 0;
+ if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno("::setsockopt(IPV6_ADD_MEMBERSHIP");
+}
+
+prefix_ void senf::INet6MulticastProtocol::mcAddMembership(INet6Address const & mcAddr,
+ std::string const & iface)
+{
+ struct ipv6_mreq mreqn;
+ std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
+ mreqn.ipv6mr_interface = if_nametoindex(iface.c_str());
+ if (mreqn.ipv6mr_interface == 0)
+ throwErrno("::if_nametoindex()",ENOENT);
+ if (::setsockopt(fd(),SOL_IP,IPV6_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno("::setsockopt(IPV6_ADD_MEMBERSHIP");
+}
+
+prefix_ void senf::INet6MulticastProtocol::mcDropMembership(INet6Address const & mcAddr)
+ const
+{
+ struct ipv6_mreq mreqn;
+ std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
+ mreqn.ipv6mr_interface = 0;
+ if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno();
+}
+
+prefix_ void
+senf::INet6MulticastProtocol::mcDropMembership(INet6Address const & mcAddr,
+ std::string const & iface)
+ const
+{
+ struct ipv6_mreq mreqn;
+ std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
+ mreqn.ipv6mr_interface = if_nametoindex(iface.c_str());
+ if (mreqn.ipv6mr_interface == 0)
+ throwErrno("::if_nametoindex()",ENOENT);
+ if (::setsockopt(fd(),SOL_IP,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+ throwErrno();
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "MulticastProtocol.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief MulticastProtocol public header */
+
+#ifndef HH_MulticastProtocol_
+#define HH_MulticastProtocol_ 1
+
+// Custom includes
+#include "../../../Socket/SocketProtocol.hh"
+#include "INet4Address.hh"
+#include "INet6Address.hh"
+
+//#include "MulticastProtocol.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ ///\addtogroup protocol_facets_group
+ ///\{
+
+ class MulticastProtocol
+ : public virtual SocketProtocol
+ {
+ public:
+ void broadcastEnabled(bool v); ///< Enable broadcast send/receive
+ /**< If this option is enabled, broadcast UDP messages will
+ be received on the socket and the socket will be
+ allowed to send out broadcast UDP messages
+ \param[in] v \c true to enable broadcast send/receive,
+ \c false to disable */
+
+ bool broadcastEnabled(); ///< Get broadcast send/receive state
+ /**< \returns Current state of the broadcastEnabled()
+ option. */
+
+
+ unsigned mcTTL() const; ///< Return current multicast TTL
+ void mcTTL(unsigned value) const; ///< Set multicast TTL
+
+ bool mcLoop() const; ///< Return current multicast loopback state
+ void mcLoop(bool value) const; ///< Set multicast loopback state
+
+ void mcIface(std::string const & iface = std::string()) const;
+ ///< Set multicast send interface of the socket
+ /**< \param[in] iface name of interface to send multicast
+ data from */
+ };
+
+ class INet4MulticastProtocol
+ : public virtual SocketProtocol
+ {
+ public:
+ void mcAddMembership(INet4Address const & mcAddr) const;
+ ///< Join multicast group on default interface
+ /**< This member will add \a mcAddr to the list of multicast
+ groups received. The group is joined on the default
+ interface.
+ \param[in] mcAddr address of group to join */
+ void mcAddMembership(INet4Address const & mcAddr, INet4Address const & localAddr)
+ const;
+ ///< join multicast group on a specific interface
+ /**< This member will add \a mcAddr to the list of multicast
+ groups received. The group is joined on the interface
+ with the given local address.
+ \deprecated Use \link mcAddMembership(INet4Address const & mcAddr, std::string const & iface) const mcAddMembership( \a mcAddr , \a iface )\endlink
+ for compatibility with the IPv6 API.
+ \param[in] mcAddr address of group to join
+ \param[in] localAddr address of interface to join on */
+ void mcAddMembership(INet4Address const & mcAddr, std::string const & iface) const;
+ ///< join multicast group on a specific interface
+ /**< This member will add \a mcAddr to the list of multicast
+ groups received. The group is joined on the given
+ interface.
+ \param[in] mcAddr address of group to join
+ \param[in] iface interface name */
+
+ void mcDropMembership(INet4Address const & mcAddr) const;
+ ///< Leave multicast group
+ /**< This member will remove \a mcAddr from the list of
+ multicast groups received. The group is left from the
+ default interface.
+ \param[in] mcAddr address of group to leave */
+ void mcDropMembership(INet4Address const & mcAddr, INet4Address const & localAddr)
+ const;
+ ///< leave multicast group on a specific interface
+ /**< This member will remove \a mcAddr from the list of
+ multicast groups received. The group is left from the
+ interface with the given local address.
+ \deprecated Use \link mcDropMembership(INet4Address const & mcAddr, std::string const & iface) const mcDropMembership( \a mcAddr , \a iface )\endlink
+ for compatibility with the IPv6 API.
+ \param[in] mcAddr address of group to leave
+ \param[in] localAddr address of interface to leave
+ from */
+ void mcDropMembership(INet4Address const & mcAddr, std::string const & iface)
+ const;
+ ///< leave multicast group on a specific interface
+ /**< This member will remove \a mcAddr from the list of
+ multicast groups received. The group is left from the
+ interface with the given local address.
+ \param[in] mcAddr address of group to leave
+ \param[in] localAddr address of interface to leave
+ from */
+ };
+
+ class INet6MulticastProtocol
+ : public virtual SocketProtocol
+ {
+ public:
+ void mcAddMembership(INet6Address const & mcAddr) const;
+ ///< Join multicast group on default interface
+ /**< This member will add \a mcAddr to the list of multicast
+ groups received. The group is joined on the default
+ interface.
+ \param[in] mcAddr address of group to join */
+ void mcAddMembership(INet6Address const & mcAddr, INet6Address const & localAddr)
+ const;
+ ///< join multicast group on a specific interface
+ /**< This member will add \a mcAddr to the list of multicast
+ groups received. The group is joined on the interface
+ with the given local address.
+ \param[in] mcAddr address of group to join
+ \param[in] localAddr address of interface to join on */
+ void mcAddMembership(INet6Address const & mcAddr, std::string const & iface);
+ ///< join multicast group on a specific interface
+ /**< This member will add \a mcAddr to the list of multicast
+ groups received. The group is joined on the given
+ interface.
+ \param[in] mcAddr address of group to join
+ \param[in] iface interface name */
+
+ void mcDropMembership(INet6Address const & mcAddr) const;
+ ///< Leave multicast group
+ /**< This member will remove \a mcAddr from the list of
+ multicast groups received. The group is left from the
+ default interface.
+ \param[in] mcAddr address of group to leave */
+ void mcDropMembership(INet6Address const & mcAddr, INet6Address const & localAddr)
+ const;
+ ///< leave multicast group on a specific interface
+ /**< This member will remove \a mcAddr from the list of
+ multicast groups received. The group is left from the
+ interface with the given local address.
+ \param[in] mcAddr address of group to leave
+ \param[in] localAddr address of interface to leave
+ from */
+ void mcDropMembership(INet6Address const & mcAddr, std::string const & iface)
+ const;
+ ///< leave multicast group on a specific interface
+ /**< This member will remove \a mcAddr from the list of
+ multicast groups received. The group is left from the
+ interface with the given local address.
+ \param[in] mcAddr address of group to leave
+ \param[in] localAddr address of interface to leave
+ from */
+ };
+
+ ///\}
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "MulticastProtocol.cci"
+//#include "MulticastProtocol.ct"
+//#include "MulticastProtocol.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
-// $Id$
+// $Id: RawINetProtocol.cc 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#include "RawInetProtocol.hh"
+#include "RawINetProtocol.hh"
// Custom includes
#include <sys/socket.h>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-prefix_ unsigned senf::RawInetProtocol::available()
+prefix_ unsigned senf::RawINetProtocol::available()
const
{
int n;
return n;
}
-prefix_ bool senf::RawInetProtocol::eof()
+prefix_ bool senf::RawINetProtocol::eof()
const
{
return false;
-// $Id$
+// $Id: RawINetProtocol.hh 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
namespace senf {
which are available on a PF_INET[6]/RAW socket.
*/
- class RawInetProtocol
+ class RawINetProtocol
: public virtual SocketProtocol
{
public:
-// $Id$
+// $Id: RawINetSocketHandle.cc 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#include "RawInetSocketHandle.hh"
+#include "RawINetSocketHandle.hh"
// Custom includes
#include <sys/types.h>
const
{
init_client(protocol);
- bind(address);
+ clientHandle().bind(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV4SocketProtocol::clone()
const
{
init_client(protocol);
- bind(address);
+ clientHandle().bind(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV6SocketProtocol::clone()
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
-//#include "RawInetSocketHandle.mpp"
+//#include "RawINetSocketHandle.mpp"
\f
// Local Variables:
-// $Id$
+// $Id: RawINetSocketHandle.hh 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Custom includes
#include "INetProtocol.hh"
-#include "RawInetProtocol.hh"
+#include "RawINetProtocol.hh"
+#include "MulticastProtocol.hh"
#include "../../../Socket/Protocols/BSDSocketProtocol.hh"
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy RawV4Socket_Policy; ///< Socket Policy of the RawV4 Protocol
/** \brief IPv4 RAW Socket Protocol
class RawV4SocketProtocol
: public ConcreteSocketProtocol<RawV4Socket_Policy>,
public IPv4Protocol,
- public RawInetProtocol,
+ public RawINetProtocol,
public BSDSocketProtocol,
- public AddressableBSDSocketProtocol//,
-// public senf::pool_alloc_mixin<RawV4Socket_Policy>
+ public AddressableBSDSocketProtocol,
+ public MulticastProtocol,
+ public INet4MulticastProtocol,
+ public senf::pool_alloc_mixin<RawV4SocketProtocol>
{
public:
///////////////////////////////////////////////////////////////////////////
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy RawV6Socket_Policy; ///< Socket Policy of the RawV6 Protocol
/** \brief IPv6 RAW Socket Protocol
class RawV6SocketProtocol
: public ConcreteSocketProtocol<RawV6Socket_Policy>,
public IPv6Protocol,
- public RawInetProtocol,
+ public RawINetProtocol,
public BSDSocketProtocol,
- public AddressableBSDSocketProtocol//,
-// public senf::pool_alloc_mixin<RawV6SocketProtocol>
+ public AddressableBSDSocketProtocol,
+ public MulticastProtocol,
+ public INet4MulticastProtocol,
+ public senf::pool_alloc_mixin<RawV6SocketProtocol>
{
public:
///////////////////////////////////////////////////////////////////////////
-// $Id$
+// $Id: RawINetSocketHandle.test.cc 597 2008-01-15 09:16:20Z g0dil $
//
// Copyright (C) 2007
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
- \brief RawInetSocketHandle.test unit tests */
+ \brief RawINetSocketHandle.test unit tests */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include "RawInetSocketHandle.hh"
+#include "RawINetSocketHandle.hh"
#include <iostream>
#include "../../../Utils/auto_unit_test.hh"
alarm(10);
start(server_v4);
senf::RawV4ClientSocketHandle sock(47); //IPPROTO_GRE
- BOOST_CHECK_NO_THROW( sock.rcvbuf(2048) );
- BOOST_CHECK_EQUAL( sock.rcvbuf(), 2048u );
- BOOST_CHECK_NO_THROW( sock.sndbuf(2048) );
- BOOST_CHECK_EQUAL( sock.sndbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
BOOST_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:0"), test) );
senf::RawV4ClientSocketHandle sockrec(48); //IPPROTO_GRE+1
std::string in = sockrec.read();
start(server_v6);
sleep(1);
senf::RawV6ClientSocketHandle sock(47); //IPPROTO_GRE
- BOOST_CHECK_NO_THROW( sock.rcvbuf(2048) );
- BOOST_CHECK_EQUAL( sock.rcvbuf(), 2048u );
- BOOST_CHECK_NO_THROW( sock.sndbuf(2048) );
- BOOST_CHECK_EQUAL( sock.sndbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
BOOST_CHECK_NO_THROW( sock.writeto(senf::INet6SocketAddress("[::1]:0"), test) );
senf::RawV6ClientSocketHandle sockrec(48); //IPPROTO_GRE+1
std::string in = sockrec.read();
throw;
}
}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
const
{
init_client();
- connect(address);
+ clientHandle().connect(address);
}
prefix_ void senf::TCPv4SocketProtocol::init_server()
const
{
init_server();
- bind(address);
+ serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
throwErrno();
const
{
init_client();
- connect(address);
+ clientHandle().connect(address);
}
prefix_ void senf::TCPv6SocketProtocol::init_server()
const
{
init_server();
- bind(address);
+ serverHandle().bind(address);
reuseaddr(true);
if (::listen(fd(),backlog) < 0)
throwErrno();
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
#include "../../../Socket/ProtocolServerSocketHandle.hh"
StreamFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy TCPv4Socket_Policy; ///< Socket Policy of the TCPv4 Protocol
/** \brief IPv4 TCP Socket Protocol
BOOST_CHECK_THROW( sock.connect(senf::INet4SocketAddress("127.0.0.1:12345")),
senf::SystemException );
- BOOST_CHECK_THROW( sock.protocol().connect(senf::INet4SocketAddress("127.0.0.1:12345")),
- senf::SystemException );
}
try {
BOOST_CHECK( sock.peer() == senf::INet4SocketAddress("127.0.0.1:12345") );
BOOST_CHECK( sock.local() == senf::INet4SocketAddress("127.0.0.1:23456") );
BOOST_CHECK( sock.blocking() );
- BOOST_CHECK_NO_THROW( sock.rcvbuf(2048) );
- BOOST_CHECK_EQUAL( sock.rcvbuf(), 2048u );
- BOOST_CHECK_NO_THROW( sock.sndbuf(2048) );
- BOOST_CHECK_EQUAL( sock.sndbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
BOOST_CHECK_NO_THROW( sock.write("TEST-WRITE") );
BOOST_CHECK_EQUAL( sock.read(), "TEST-WRITE" );
BOOST_CHECK( !sock.eof() );
BOOST_CHECK( sock.peer() == senf::INet6SocketAddress("[::1]:12345") );
BOOST_CHECK( sock.local() == senf::INet6SocketAddress("[::1]:23456") );
BOOST_CHECK( sock.blocking() );
- BOOST_CHECK_NO_THROW( sock.rcvbuf(2048) );
- BOOST_CHECK_EQUAL( sock.rcvbuf(), 2048u );
- BOOST_CHECK_NO_THROW( sock.sndbuf(2048) );
- BOOST_CHECK_EQUAL( sock.sndbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
BOOST_CHECK_NO_THROW( sock.write("TEST-WRITE") );
BOOST_CHECK_EQUAL( sock.read(), "TEST-WRITE" );
// this fails with ENOFILE ... why ????
return false;
}
-prefix_ bool senf::UDPProtocol::mcLoop()
- const
-{
- int value;
- socklen_t len (sizeof(value));
- if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
- throwErrno();
- return value;
-}
-
-prefix_ void senf::UDPProtocol::mcLoop(bool value)
- const
-{
- int ivalue (value);
- if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
- throwErrno();
-}
-
-prefix_ void senf::UDPProtocol::mcAddMembership(INet4SocketAddress const & mcAddr)
- const
-{
- struct ip_mreqn mreqn;
- mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
- mreqn.imr_address.s_addr = htons(INADDR_ANY);
- mreqn.imr_ifindex = 0;
- if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
-}
-
-prefix_ void senf::UDPProtocol::mcAddMembership(INet4SocketAddress const & mcAddr,
- INet4SocketAddress const & localAddr)
- const
-{
- struct ip_mreqn mreqn;
- mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
- mreqn.imr_address = reinterpret_cast<struct sockaddr_in const *>(localAddr.sockaddr_p())->sin_addr;
- mreqn.imr_ifindex = 0;
- if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
-}
-
-prefix_ void senf::UDPProtocol::mcDropMembership(INet4SocketAddress const & mcAddr)
- const
-{
- struct ip_mreqn mreqn;
- mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
- mreqn.imr_address.s_addr = htons(INADDR_ANY);
- mreqn.imr_ifindex = 0;
- if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
-}
-
-prefix_ void senf::UDPProtocol::mcDropMembership(INet4SocketAddress const & mcAddr,
- INet4SocketAddress const & localAddr)
- const
-{
- struct ip_mreqn mreqn;
- mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
- mreqn.imr_address = reinterpret_cast<struct sockaddr_in const *>(localAddr.sockaddr_p())->sin_addr;
- mreqn.imr_ifindex = 0;
- if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
-}
-
-prefix_ void senf::UDPProtocol::mcIface(std::string const & iface)
- const
-{
- struct ip_mreqn mreqn;
- ::memset(&mreqn,sizeof(mreqn),0);
- if (!iface.empty()) {
- mreqn.imr_ifindex = if_nametoindex(iface.c_str());
- if (mreqn.imr_ifindex == 0)
- throwErrno(EINVAL);
- }
- if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
- throwErrno();
-}
-
-prefix_ unsigned senf::UDPProtocol::mcTTL()
- const
-{
- int value;
- socklen_t len (sizeof(value));
- if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
- throwErrno();
- return value;
-}
-
-prefix_ void senf::UDPProtocol::mcTTL(unsigned value)
- const
-{
- if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
- throwErrno();
-}
-
-
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "UDPProtocol.mpp"
: public virtual SocketProtocol
{
public:
- unsigned mcTTL() const; ///< Return current multicast TTL
- void mcTTL(unsigned value) const; ///< Set multicast TTL
-
- bool mcLoop() const; ///< Return current multicast loopback state
- void mcLoop(bool value) const; ///< Set multicast loopback state
-
- void mcAddMembership(INet4SocketAddress const & mcAddr) const;
- ///< Join multicast group
- /**< This member will add \a mcAddr to the list of multicast
- groups received. The group is joined on the default
- interface.
- \param[in] mcAddr address of group to join
- \todo fix this as soon as we have a real address class
- (different from the sockaddress class */
- void mcAddMembership(INet4SocketAddress const & mcAddr, INet4SocketAddress const & localAddr) const;
- ///< join multicast group on a specific address/interface
- /**< This member will add \a mcAddr to the list of multicast
- groups received. The group is joined on the interface
- with the given local address.
- \param[in] mcAddr address of group to join
- \param[in] localAddr address of interface to join on
- \todo fix this as soon as we have a real address class
- (different from the sockaddress class */
-
- void mcDropMembership(INet4SocketAddress const & mcAddr) const;
- ///< Leave multicast group
- /**< This member will remove \a mcAddr from the list of
- multicast groups received. The group is left from the
- default interface.
- \param[in] mcAddr address of group to leave
- \todo fix this as soon as we have a real address class
- (different from the sockaddress class */
- void mcDropMembership(INet4SocketAddress const & mcAddr, INet4SocketAddress const & localAddr) const;
- ///< leave multicast group on a specific address/interface
- /**< This member will remove \a mcAddr from the list of
- multicast groups received. The group is left from the
- interface with the given local address.
- \param[in] mcAddr address of group to leave
- \param[in] localAddr address of interface to leave from
- \todo fix this as soon as we have a real address class
- (different from the sockaddress class */
-
- void mcIface(std::string const & iface = std::string()) const;
- ///< set default multicast interface of the socket
- /**< \param[in] iface name of interface */
-
-
///\name Abstract Interface Implementation
///@{
const
{
init_client();
- bind(address);
+ clientHandle().bind(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv4SocketProtocol::clone()
const
{
init_client();
- bind(address);
+ clientHandle().bind(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv6SocketProtocol::clone()
// Custom includes
#include "INetProtocol.hh"
#include "UDPProtocol.hh"
+#include "MulticastProtocol.hh"
#include "../../../Socket/Protocols/BSDSocketProtocol.hh"
+#include "../../../Socket/Protocols/DatagramSocketProtocol.hh"
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
//#include "UDPSocketHandle.mpp"
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy UDPv4Socket_Policy; ///< Socket Policy of the UDPv4 Protocol
/** \brief IPv4 UDP Socket Protocol
: public ConcreteSocketProtocol<UDPv4Socket_Policy>,
public IPv4Protocol,
public UDPProtocol,
+ public MulticastProtocol,
+ public INet4MulticastProtocol,
public BSDSocketProtocol,
+ public DatagramSocketProtocol,
public AddressableBSDSocketProtocol,
public senf::pool_alloc_mixin<UDPv4SocketProtocol>
{
std::auto_ptr<SocketProtocol> clone() const;
///@}
+
};
typedef ProtocolClientSocketHandle<UDPv4SocketProtocol> UDPv4ClientSocketHandle;
: public ConcreteSocketProtocol<UDPv6Socket_Policy>,
public IPv6Protocol,
public UDPProtocol,
+ public MulticastProtocol,
+ public INet6MulticastProtocol,
public BSDSocketProtocol,
+ public DatagramSocketProtocol,
public AddressableBSDSocketProtocol,
public senf::pool_alloc_mixin<UDPv6SocketProtocol>
{
senf::UDPv4ClientSocketHandle sock;
BOOST_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress("127.0.0.1:23456")) );
BOOST_CHECK( sock.local() == senf::INet4SocketAddress("127.0.0.1:23456") );
- BOOST_CHECK_NO_THROW( sock.rcvbuf(2048) );
- BOOST_CHECK_EQUAL( sock.rcvbuf(), 2048u );
- BOOST_CHECK_NO_THROW( sock.sndbuf(2048) );
- BOOST_CHECK_EQUAL( sock.sndbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u );
+ BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) );
+ BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u );
BOOST_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:12345"),
std::string("TEST-WRITE")) );
BOOST_CHECK_EQUAL( sock.read(), "TEST-WRITE" );
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/Protocols/BSDSocketProtocol.hh"
#include "LLAddressing.hh"
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy Packet_Policy; ///< Policy of PacketProtocol
/** \brief Raw Packet-Socket access (Linux)
void mcDrop(std::string const & interface, MACAddress const & address) const;
///< Disable reception of a multicast group
/**< \see \ref mcAdd() */
+
///@}
///\name Abstract Interface Implementation
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/Protocols/BSDSocketProtocol.hh"
#include "LLAddressing.hh"
DatagramFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy Tap_Policy; ///< Policy for TAP
/** \brief TAP
ob = SConscript(sc)
if ob : objects.extend(ob)
-SENFSCons.InstallIncludeFiles(env, [ 'INet.hh', 'Raw.hh', 'DVB.hh' ])
+SENFSCons.InstallIncludeFiles(env, [ 'INet.hh', 'Raw.hh', 'DVB.hh', 'UN.hh' ])
Return('objects')
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief UN public header */
+
+#include "UN/UN.hh"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
prefix_ void senf::ConnectedUNDatagramSocketProtocol::init_client(UNSocketAddress const & address) const
{
init_client();
- connect(address);
+ clientHandle().connect(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUNDatagramSocketProtocol::clone()
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "UNDatagramSocketHandle.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
//#include "UNDatagramSocketHandle.mpp"
DatagramFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy ConnectedUNDatagramSocket_Policy; ///< Socket Policy of the Unix Domain Datagram Protocol (connected)
/** \brief Unix Domain Datagram Socket Protocol (connected)
}
-#endif /*CONNECTEDUNDATAGRAMSOCKETHANDLE_HH_*/
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "ConnectedUNDatagramSocketHandle.cci"
+//#include "ConnectedUNDatagramSocketHandle.ct"
+//#include "ConnectedUNDatagramSocketHandle.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
prefix_ void senf::UNDatagramSocketProtocol::init_client(UNSocketAddress const & address) const
{
init_client();
- bind(address);
+ clientHandle().bind(address);
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::UNDatagramSocketProtocol::clone()
#include "../../../Socket/FramingPolicy.hh"
#include "../../../Socket/CommunicationPolicy.hh"
#include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
#include "../../../Socket/ProtocolClientSocketHandle.hh"
//#include "UNDatagramSocketHandle.mpp"
DatagramFramingPolicy,
UnconnectedCommunicationPolicy,
ReadablePolicy,
- WriteablePolicy,
- SocketBufferingPolicy
+ WriteablePolicy
>::policy UNDatagramSocket_Policy; ///< Socket Policy of the Unix Domain Datagram Protocol
/** \brief Unix Domain Datagram Socket Protocol
return false;
}
-prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address)
- const
-{
- if(::connect(fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
- throwErrno();
-}
-
-prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address)
- const
-{
- if(::bind(fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
- throwErrno();
-
-}
-
-
-
prefix_ void senf::UNProtocol::close()
const
{
}
}
-// // struct sockaddr_un test;
-// // socklen_t len;
-// // memset( (char*)&test, 0xff, sizeof( test));
-// // int fd = inputSocket.fd() ;
-// //// printf( "fd: %d\n", fd);
-// //
-// // int r = getsockname( fd, (struct sockaddr *)&test, &len);
-// // if( r < 0){
-// // perror( "bla:");
-// // }
-// // else{
-// // printf( "name: %d %d %s\n", r, len , test.sun_path);
-// // unsigned char *p = (unsigned char*) &test;for( r=0; r< len; r++) printf( "%2.2x ", (int)(p[r])); printf ("\n");
-// // }
-// struct sockaddr_un test;
-// socklen_t len = sizeof( test);
-// int r = ::getsockname(fd(), (struct sockaddr *)&test, &len);
-// if( r == 0 && ::strlen(test.sun_path) > 0){
-// ::unlink( test.sun_path);
-// }
-
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "UNProtocol.mpp"
This protocol facet introduces all the socket api protocol members which are related to Unix
Domain addressing.
-
- \todo connect() is only available on stream sockets. We want to access bind() and connect()
- via the ClientSocketHandle -> see SocketProtocol todo point
*/
class UNProtocol
: public virtual SocketProtocol
{
public:
- void connect(UNSocketAddress const & address) const; ///< Connect to a unix domain socket
- /**< \todo make this obsolete by allowing access to the
- ClientSocketHandle from ConcreateSocketProtocol
- \param[in] address Address to connect to */
- void bind(UNSocketAddress const & address) const; ///< Set local socket address (path)
- /**< \todo make this obsolete by allowing access to the
- ClientSocketHandle from ConcreateSocketProtocol
- \param[in] address Address to set */
-
virtual void close() const; ///< Close socket
/**< This override will automatically \c shutdown() the
socket whenever it is closed.
std::string path_;
};
+
+ ///@}
}
///////////////////////////////hh.e////////////////////////////////////////
BOOST_CHECK_EQUAL( myh.dumpState(),
"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, senf::test::SomeBufferingPolicy> >\n"
- "socket.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy, senf::test::SomeBufferingPolicy>\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.server: false\n" );
}
/** \file
\brief Policy Framework public header
- \todo We should probably remove BufferingPolicy from the interface, it does not make much sense
- (how did I come to include it ??)
-
\todo Do we want to support separate read and write policies. This allows to treat pipes within
this framework however, is this worth the effort?
\htmlonly
<map name="socketPolicy">
<area shape="rect" alt="SocketPolicy" href="structsenf_1_1SocketPolicy.html" title="SocketPolicy" coords="276,90,558,213" />
- <area shape="rect" alt="BufferingPolicyBase" href="structsenf_1_1BufferingPolicyBase.html" title="BufferingPolicyBase" coords="25,282,190,306" />
<area shape="rect" alt="WritePolicyBase" href="structsenf_1_1WritePolicyBase.html" title="WritePolicyBase" coords="39,243,174,268" />
<area shape="rect" alt="ReadPolicyBase" href="structsenf_1_1ReadPolicyBase.html" title="ReadPolicyBase" coords="42,204,174,231" />
<area shape="rect" alt="CommunicationPolicyBase" href="structsenf_1_1CommunicationPolicyBase.html" title="CommunicationPolicyBase" coords="0,166,215,193" />
<dt><em>writePolicy</em></dt><dd>configures the writability of the socket</dd>
- <dt><em>bufferingPolicy</em></dt><dd>configures, if and how buffering is configured for a
- socket</dd> </dl>
-
The template senf::SocketPolicy combines these policy axis to form a concrete socket policy. In
a concrete policy, each of these policy axis is assigned a value, the policy value. This value
is identified by a class type, a policy class. E.g. possible values for <em>framingPolicy</em>
separately but at the same time for each policy axis:
\code
- // This defines an incomplete policy where addressingPolicy, writePolicy and bufferingPolicy
+ // This defines an incomplete policy where addressingPolicy and writePolicy
// are unspecified
typedef senf::MakeSocketPolicy<
senf::StreamFramingPolicy,
// StreamFramingPolicy,
// ConnectedCommunicationPolicy,
// ReadablePolicy,
- // WritablePolicy,
- // SocketBufferingPolicy>::policy
+ // WritablePolicy>::policy
senf::TCPv4ClientSocketHandle tcpHandle (...);
MyReadableHandle myHandle (tcpHandle); // Conversion to more basic socket handle
In the following discussion we will use the following conventions:
\li \e Axis is one or \c AddressingPolicy, \c FramingPolicy, \c CommunicationPolicy, \c
- ReadPolicy, \c WritePolicy or \c BufferingPolicy
+ ReadPolicy or \c WritePolicy
\li \e socketPolicy is any socket policy (that is, an instantiation of the SocketPolicy
template)
\li \e trait is an any policy class (that is, any class derived from one of the axis base
derives from SocketPolicyBase. This is simpler than checking the template directly).</dd>
<dt>\c template \c SocketPolicy < \e addressingPolicy, \e framingPolicy, \e communicationPolicy,
- \e readPolicy, \e writePolicy, \e bufferingPolicy ></dt> <dd>This is the central SocketPolicy
+ \e readPolicy, \e writePolicy ></dt> <dd>This is the central SocketPolicy
template. It combines a complete set of policy classes, one for each axis.</dd>
<dt>\c template \c MakeSocketPolicy < \e args ></dt> <dd>\c MakeSocketPolicy is a template
\section policy_implement Implementing Policy Classes
- To define a new policy class, derive from the corresponding base class for your policy
- axes. The only policy axis which might possibly need to be extended are the addressing policy
- (AddressingPolicyBase) and the buffering policy (BufferingPolicyBase). See the Documentation of
- these classes for more information on which members can be implemented.
+ To define a new policy class, derive from the corresponding base class for your policy axes. The
+ only policy axis which might possibly need to be extended is the addressing policy
+ (AddressingPolicyBase). See the Documentation of these classes for more information on which
+ members can be implemented.
All members you define must be static. For any of the policy classes, you must only define those
members which are supported by your implementation. If you leave out a member you automatically
(FramingPolicy) \
(CommunicationPolicy) \
(ReadPolicy) \
- (WritePolicy) \
- (BufferingPolicy)
+ (WritePolicy)
// Wer define these classes explicitly (and not with some macro
// magic) because
virtual ~WritePolicyBase() {}
};
- /** \brief Policy defining the buffering interface
-
- The BufferingPolicy defines the buffer handling of the socket. It may provide the following
- members:
-
- \see policy_group
- */
- struct BufferingPolicyBase
- {
- virtual ~BufferingPolicyBase() {}
- };
-
// The implementation file will for each Policy declared above
// define the following (SomePolicy is one of the above):
//
struct WritablePolicy : public WritePolicyBase {};
struct UnwritablePolicy : public WritePolicyBase {};
- struct SocketBufferingPolicy : public BufferingPolicyBase {};
-
template <class Policy>
struct ConvertibleValue
{
UnspecifiedFramingPolicy,
ConnectedCommunicationPolicy,
ReadablePolicy,
- UnspecifiedWritePolicy,
- UnspecifiedBufferingPolicy> Policy2;
+ UnspecifiedWritePolicy> Policy2;
BOOST_MPL_ASSERT(( boost::is_same<Policy1,Policy2> ));
UnspecifiedFramingPolicy,
UnspecifiedCommunicationPolicy,
ReadablePolicy,
- UnspecifiedWritePolicy,
- UnspecifiedBufferingPolicy> Policy4;
+ UnspecifiedWritePolicy> Policy4;
BOOST_MPL_ASSERT(( boost::is_same<Policy3,Policy4> ));
BOOST_MPL_ASSERT_NOT(( boost::is_same<Policy1, Policy3> ));
}
};
- struct SomeBufferingPolicy : public senf::BufferingPolicyBase
- {
- static unsigned rcvbuf(FileHandle handle)
- { return 0; }
- static unsigned rcvbuf(FileHandle handle, unsigned size)
- { return 0; }
-
- static unsigned sndbuf(FileHandle handle)
- { return 0; }
- static unsigned sndbuf(FileHandle handle, unsigned size)
- { return 0; }
- };
-
typedef senf::MakeSocketPolicy<
SomeAddressingPolicy,
SomeFramingPolicy,
SomeCommunicationPolicy,
SomeReadPolicy,
- SomeWritePolicy,
- SomeBufferingPolicy
+ SomeWritePolicy
>::policy SomeSocketPolicy;
}}
//#include "SocketProtocol.ih"
// Custom includes
+#include "SocketHandle.hh"
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
return policy_;
}
+////////////////////////////////////////
+// protected members
+
+template <class SocketPolicy>
+prefix_ senf::ClientSocketHandle<SocketPolicy>
+senf::ConcreteSocketProtocol<SocketPolicy>::clientHandle()
+ const
+{
+ return static_socket_cast< ClientSocketHandle<Policy> >(fh());
+}
+
+template <class SocketPolicy>
+prefix_ senf::ServerSocketHandle<SocketPolicy>
+senf::ConcreteSocketProtocol<SocketPolicy>::serverHandle()
+ const
+{
+ return static_socket_cast< ServerSocketHandle<Policy> >(fh());
+}
+
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
\htmlonly
<map name="protocols">
- <area shape="rect" alt="SocketPolicy" href="structsenf_1_1SocketPolicy.html" title="SocketPolicy" coords="416,50,536,68" />
- <area shape="rect" alt="ConcreteSocketProtocol" href="classsenf_1_1ConcreteSocketProtocol.html" title="ConcreteSocketProtocol" coords="268,65,456,88" />
- <area shape="rect" alt="SocketProtocol" href="classsenf_1_1SocketProtocol.html" title="SocketProtocol" coords="1,2,120,26" />
- <area shape="rect" alt="BSDSocketProtocol" href="classsenf_1_1BSDSocketProtocol.html" title="BSDSocketProtocol" coords="124,118,276,143" />
- <area shape="rect" alt="AddressableBSDSocketProtocol" href="classsenf_1_1AddressableBSDSocketProtocol.html" title="AddressableBSDSocketProtocol" coords="82,200,314,224" />
- <area shape="rect" alt="IPv4Protocol" href="classsenf_1_1IPv4Protocol.html" title="IPv4Protocol" coords="149,272,252,296" />
- <area shape="rect" alt="IPv6Protocol" href="classsenf_1_1IPv6Protocol.html" title="IPv6Protocol" coords="149,335,251,359" />
- <area shape="rect" alt="TCPProtocol" href="classsenf_1_1TCPProtocol.html" title="TCPProtocol" coords="151,398,248,420" />
- <area shape="rect" alt="TCPv4SocketProtocol" href="classsenf_1_1TCPv4SocketProtocol.html" title="TCPv4SocketProtocol" coords="288,471,405,494" />
- <area shape="rect" alt="TCPv6SocketProtocol" href="classsenf_1_1TCPv6SocketProtocol.html" title="TCPv6SocketProtocol" coords="424,470,540,494" />
- <area shape="rect" alt="PacketProtocol" href="classsenf_1_1PacketProtocol.html" title="PacketProtocol" coords="560,469,680,495" />
+ <area shape="rect" alt="SocketPolicy" href="structsenf_1_1SocketPolicy.html" title="SocketPolicy" coords="416,50,536,68" />
+ <area shape="rect" alt="ConcreteSocketProtocol" href="classsenf_1_1ConcreteSocketProtocol.html" title="ConcreteSocketProtocol" coords="268,65,456,88" />
+ <area shape="rect" alt="SocketProtocol" href="classsenf_1_1SocketProtocol.html" title="SocketProtocol" coords="1,2,120,26" />
+ <area shape="rect" alt="BSDSocketProtocol" href="classsenf_1_1BSDSocketProtocol.html" title="BSDSocketProtocol" coords="124,118,276,143" />
+ <area shape="rect" alt="AddressableBSDSocketProtocol" href="classsenf_1_1AddressableBSDSocketProtocol.html" title="AddressableBSDSocketProtocol" coords="82,200,314,224" />
+ <area shape="rect" alt="IPv4Protocol" href="classsenf_1_1IPv4Protocol.html" title="IPv4Protocol" coords="149,272,252,296" />
+ <area shape="rect" alt="IPv6Protocol" href="classsenf_1_1IPv6Protocol.html" title="IPv6Protocol" coords="149,335,251,359" />
+ <area shape="rect" alt="TCPProtocol" href="classsenf_1_1TCPProtocol.html" title="TCPProtocol" coords="151,398,248,420" />
+ <area shape="rect" alt="TCPv4SocketProtocol" href="classsenf_1_1TCPv4SocketProtocol.html" title="TCPv4SocketProtocol" coords="288,471,405,494" />
+ <area shape="rect" alt="TCPv6SocketProtocol" href="classsenf_1_1TCPv6SocketProtocol.html" title="TCPv6SocketProtocol" coords="424,470,540,494" />
+ <area shape="rect" alt="PacketProtocol" href="classsenf_1_1PacketProtocol.html" title="PacketProtocol" coords="560,469,680,495" />
</map>
<img src="Protocols.png" border="0" alt="Protocols" usemap="#protocols">
\endhtmlonly
///////////////////////////////////////////////////////////////////////////
virtual SocketPolicyBase const & policy() const = 0;
- ///< Access the policy instance
+ ///< Access the policy instance
///////////////////////////////////////////////////////////////////////////
// Virtual interface
not support the notion of EOF, this member should
always return \c false. */
- virtual void close() const; ///< Close socket
+ virtual void close() const; ///< Close socket
/**< This override will automatically \c shutdown() the
socket whenever it is closed.
\throws senf::SystemException */
-
- virtual void terminate() const; ///< Forcibly close socket
+
+ virtual void terminate() const; ///< Forcibly close socket
/**< This override will automatically \c shutdown() the
- socket whenever it is called. Additionally it will
- disable SO_LINGER to ensure, that v_terminate will not
- block. Like the overriden method, this member will ignore
- failures and will never throw. It is therefore safe to be
- called from a destructor. */
+ socket whenever it is called. Additionally it will
+ disable SO_LINGER to ensure, that v_terminate will not
+ block. Like the overriden method, this member will ignore
+ failures and will never throw. It is therefore safe to be
+ called from a destructor. */
virtual void state(SocketStateMap & map, unsigned lod) const;
///< Return socket state information
\a lod value with a default value of 0. The
interpretation of the \a lod value is completely
implementation defined.
-
+
Every class derived from SocketProtocol should
reimplement state(). The reimplemented method should
call (all) baseclass-implementations of this
keys are interpreted as hierarchical strings with '.'
as a separator (like hostnames or struct or class
members). They are automatically sorted correctly.
-
+
The values are std:string with one additional feature:
they allow assignment or conversion from *any* type as
long as that type is streamable. This simplifies
assigning non-string values to the map:
-
+
\code
- map["socket.protocol.ip.address"] << peer();
- map["socket.protocol.tcp.backlog"] << backlog();
+ map["socket.protocol.ip.address"] << peer();
+ map["socket.protocol.tcp.backlog"] << backlog();
\endcode
-
+
This will work even if peer() returns an ip-address
object or backlog() returns an integer. The values are
automatically converted to their string representation.
-
+
Additionally, if the slot the date is written to is not
empty, the <tt>\<\<</tt> operator will add add a comma
as separator. */
SocketBody * body_;
friend class SocketBody;
- };
-
+ };
+
+ template <class Policy> class ClientSocketHandle;
+ template <class Policy> class ServerSocketHandle;
/** \brief Concrete Socket Protocol implementation base class
Policy const & policy() const;
protected:
+ ClientSocketHandle<Policy> clientHandle() const;
+ ///< Get client handle for associated socket
+ /**< Returns a client handle for the socket associated with
+ this protocol instance */
+ ServerSocketHandle<Policy> serverHandle() const;
+ ///< Get server handle for associated socket
+ /**< Returns a server handle for the socket associated with
+ this protocol instance */
private:
Policy policy_;
"SENF_PARSER_LABEL(x)=" \
"SENF_PARSER_INIT()=void init()" \
"SENF_PARSER_FINALIZE(name)=" \
- "ParseField_unsigned(b)=Parse_UIntField<?,?+b>" \
- "ParseField_signed(b)=Parse_IntField<?,?+b>" \
- "ParseField_bool(b)=Parse_Flag<?>" \
+ "ParseField_unsigned(b)=UIntFieldParser<?,?+b>" \
+ "ParseField_signed(b)=IntFieldParser<?,?+b>" \
+ "ParseField_bool(b)=FlagParser<?>" \
"SENF_PARSER_ARRAY(name,elt_type,size)=senf::Parse_Array<size,elt_type> name() const" \
"SENF_PARSER_LIST_B(name,elt_type,size_type)=senf::Parse_ListB<elt_type,size_type>::parser name() const" \
"SENF_PARSER_LIST_N(name,elt_type,size_type)=senf::Parse_ListN<elt_type,size_type>::parser name() const" \