added UDP support
tho [Tue, 20 Mar 2007 13:32:59 +0000 (13:32 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@215 270642c3-0616-0410-b53a-bc976706d245

Socket/ClientSocketHandle.hh
Socket/GenericAddressingPolicy.hh
Socket/INetProtocol.cc
Socket/INetProtocol.hh
Socket/TCPSocketHandle.test.cc
Socket/UDPProtocol.cc [new file with mode: 0644]
Socket/UDPProtocol.hh [new file with mode: 0644]
Socket/UDPSocketHandle.cc [new file with mode: 0644]
Socket/UDPSocketHandle.hh [new file with mode: 0644]

index f5e2716..29f1903 100644 (file)
@@ -102,7 +102,7 @@ namespace senf {
         /** Depending on the type of \c Address, this will be either <tt>Address</tt> or <tt>Address
             const &</tt>. See <a
             href="http://www.boost.org/libs/utility/call_traits.htm">call_traits documentation in
-            the Boost.Utility library\endlink.</a>
+            the Boost.Utility library.</a>
          */
         typedef typename boost::call_traits<Address>::param_type AddressParam;
         /// Corresponding server socket handle with the same policy
index f842d2b..9094879 100644 (file)
@@ -103,7 +103,7 @@ namespace senf {
                                              communication policy is ConnectedCommunicationPolicy.
 
                                              \param[in] handle socket handle
-                                             \param[in] address address of remote peer to connect
+                                             \param[in] addr address of remote peer to connect
                                                  to */
         static void bind(FileHandle handle, Address const & addr);
                                         ///< Set local socket address
index 7d51f4d..b6685b0 100644 (file)
@@ -29,7 +29,6 @@
 // Custom includes
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <net/if.h> // for if_nametoindex
 #include "Utils/Exception.hh"
 
 //#include "INetProtocol.mpp"
@@ -53,100 +52,6 @@ prefix_ void senf::IPv4Protocol::bind(INet4Address const & address)
         throw SystemException(errno);
 }
 
-prefix_ bool senf::IPv4Protocol::mcLoop()
-    const
-{
-    int value;
-    socklen_t len (sizeof(value));
-    if (::getsockopt(body().fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
-        throw SystemException(errno);
-    return value;
-}
-
-prefix_ void senf::IPv4Protocol::mcLoop(bool value)
-    const
-{
-    int ivalue (value);
-    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
-        throw SystemException(errno);
-}
-
-prefix_ void senf::IPv4Protocol::mcAddMembership(INet4Address 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(body().fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        throw SystemException(errno);
-}
-
-prefix_ void senf::IPv4Protocol::mcAddMembership(INet4Address const & mcAddr,
-                                                        INet4Address 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(body().fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        throw SystemException(errno);
-}
-
-prefix_ void senf::IPv4Protocol::mcDropMembership(INet4Address 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(body().fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        throw SystemException(errno);
-}
-
-prefix_ void senf::IPv4Protocol::mcDropMembership(INet4Address const & mcAddr,
-                                                         INet4Address 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(body().fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        throw SystemException(errno);
-}
-
-prefix_ void senf::IPv4Protocol::mcIface(std::string 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)
-            throw SystemException(EINVAL);
-    }
-    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
-        throw SystemException(errno);
-}
-
-prefix_ unsigned senf::IPv4Protocol::mcTTL()
-    const
-{
-    int value;
-    socklen_t len (sizeof(value));
-    if (::getsockopt(body().fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
-        throw SystemException(errno);
-    return value;
-}
-
-prefix_ void senf::IPv4Protocol::mcTTL(unsigned value)
-    const
-{
-    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
-        throw SystemException(errno);
-}
 
 ///////////////////////////////////////////////////////////////////////////
 // senf::IPv6Protocol
index 5145be0..bedf7a8 100644 (file)
@@ -55,11 +55,6 @@ namespace senf {
         \todo Is it safe, not to allow setting the interface index on add/drop? what does it do
         (especially if the local address is given ?). What have I been thinking here ???
 
-        \todo move all multicast-methods into an extra IPv4MulticastProtocol class (it's only
-        available on datagram sockets)
-
-        \todo the multicast add/remove/iface semantics are quite unclear ...
-
         \todo connect() is only available on stream sockets. We want to access bind() and connect()
         via the ClientSocketHandle -> see SocketProtocol todo point
      */
@@ -75,52 +70,6 @@ namespace senf {
                                         /**< \todo make this obsolete by allowing access to the
                                              ClientSocketHandle from ConcreateSocketProtocol
                                              \param[in] address Address to set */
-
-        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(INet4Address 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(INet4Address const & mcAddr, INet4Address 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(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
-                                             \todo fix this as soon as we have a real address class
-                                                 (different from the sockaddress class */
-        void mcDropMembership(INet4Address const & mcAddr, INet4Address 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 iface = std::string()) const;
-                                        ///< set default multicast interface of the socket
-                                        /**< \param[in] iface name of interface */
     };
 
     /** \brief Protocol facet providing IPv6 Addressing related API
index da91e29..85a0e95 100644 (file)
@@ -201,15 +201,15 @@ BOOST_AUTO_UNIT_TEST(tcpv4ClientSocketHandle)
         // are at least not sensible ...
         // I'll have to move those to a UDPSocket test ... they should
         // realy only be in the UDP Protocol implementation
-        BOOST_CHECK_NO_THROW( sock.protocol().mcTTL() );
-        BOOST_CHECK_THROW( sock.protocol().mcTTL(1), senf::SystemException );
-        BOOST_CHECK_NO_THROW( sock.protocol().mcLoop() );
-        BOOST_CHECK_NO_THROW( sock.protocol().mcLoop(false) );
-        BOOST_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0") );
-        BOOST_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0","127.0.0.1:0") );
-        BOOST_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0","127.0.0.1:0") );
-        BOOST_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0") );
-        BOOST_CHECK_THROW( sock.protocol().mcIface("lo"), senf::SystemException );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcTTL() );
+//        BOOST_CHECK_THROW( sock.protocol().mcTTL(1), senf::SystemException );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcLoop() );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcLoop(false) );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0") );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0","127.0.0.1:0") );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0","127.0.0.1:0") );
+//        BOOST_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0") );
+//        BOOST_CHECK_THROW( sock.protocol().mcIface("lo"), senf::SystemException );
 
         // The following setsockopts are hard to REALLY test ...
         BOOST_CHECK_NO_THROW( sock.protocol().nodelay(true) );
diff --git a/Socket/UDPProtocol.cc b/Socket/UDPProtocol.cc
new file mode 100644 (file)
index 0000000..854a522
--- /dev/null
@@ -0,0 +1,165 @@
+// $Id$
+//
+// Copyright (C) 2006
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief TCPProtocol non-inline non-template implementation
+ */
+
+#include "UDPProtocol.hh"
+//#include "UDPProtocol.ih"
+
+// Custom includes
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <sys/ioctl.h>
+#include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
+#include <net/if.h> // for if_nametoindex
+#include "SocketHandle.hh"
+
+//#include "UDPProtocol.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+prefix_ unsigned senf::UDPProtocol::available()
+    const
+{
+    int n;
+    if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
+        throw senf::SystemException(errno);
+    return n;
+}
+
+prefix_ bool senf::UDPProtocol::eof()
+    const
+{
+    return false;
+}
+
+prefix_ bool senf::UDPProtocol::mcLoop()
+    const
+{
+    int value;
+    socklen_t len (sizeof(value));
+    if (::getsockopt(body().fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
+        throw SystemException(errno);
+    return value;
+}
+
+prefix_ void senf::UDPProtocol::mcLoop(bool value)
+    const
+{
+    int ivalue (value);
+    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
+        throw SystemException(errno);
+}
+
+prefix_ void senf::UDPProtocol::mcAddMembership(INet4Address 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(body().fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+        throw SystemException(errno);
+}
+
+prefix_ void senf::UDPProtocol::mcAddMembership(INet4Address const & mcAddr,
+                                                        INet4Address 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(body().fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+        throw SystemException(errno);
+}
+
+prefix_ void senf::UDPProtocol::mcDropMembership(INet4Address 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(body().fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+        throw SystemException(errno);
+}
+
+prefix_ void senf::UDPProtocol::mcDropMembership(INet4Address const & mcAddr,
+                                                         INet4Address 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(body().fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+        throw SystemException(errno);
+}
+
+prefix_ void senf::UDPProtocol::mcIface(std::string 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)
+            throw SystemException(EINVAL);
+    }
+    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
+        throw SystemException(errno);
+}
+
+prefix_ unsigned senf::UDPProtocol::mcTTL()
+    const
+{
+    int value;
+    socklen_t len (sizeof(value));
+    if (::getsockopt(body().fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
+        throw SystemException(errno);
+    return value;
+}
+
+prefix_ void senf::UDPProtocol::mcTTL(unsigned value)
+    const
+{
+    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
+        throw SystemException(errno);
+}
+
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "UDPProtocol.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// End:
diff --git a/Socket/UDPProtocol.hh b/Socket/UDPProtocol.hh
new file mode 100644 (file)
index 0000000..985a32a
--- /dev/null
@@ -0,0 +1,125 @@
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief UDPProtocol public header
+ */
+
+#ifndef HH_UDPProtocol_
+#define HH_UDPProtocol_ 1
+
+// Custom includes
+#include "SocketProtocol.hh"
+#include "INetAddressing.hh"
+
+//#include "UDPProtocol.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+    /// \addtogroup protocol_facets_group
+    /// @{
+
+    /** \brief Protocol facat to support UDP operations
+
+        This protocol facet provides all those protocol functions,
+        which are available on any UDP socket.
+        
+        \todo the multicast add/remove/iface semantics are quite unclear ...
+     */
+    class UDPProtocol
+        : 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(INet4Address 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(INet4Address const & mcAddr, INet4Address 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(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
+                                             \todo fix this as soon as we have a real address class
+                                                 (different from the sockaddress class */
+        void mcDropMembership(INet4Address const & mcAddr, INet4Address 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 iface = std::string()) const;
+                                        ///< set default multicast interface of the socket
+                                        /**< \param[in] iface name of interface */
+    
+
+        ///\name Abstract Interface Implementation
+        ///@{
+
+        unsigned available() const;
+        bool eof() const;
+
+        ///@}
+    };
+
+    /// @}
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "UDPProtocol.cci"
+//#include "UDPProtocol.ct"
+//#include "UDPProtocol.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// End:
diff --git a/Socket/UDPSocketHandle.cc b/Socket/UDPSocketHandle.cc
new file mode 100644 (file)
index 0000000..09aebec
--- /dev/null
@@ -0,0 +1,104 @@
+// $Id$
+//
+// Copyright (C) 2006
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief UDPv4SocketHandle and UDPv6SocketHandle non-inline non-template implementation
+ */
+
+#include "UDPSocketHandle.hh"
+//#include "UDPSocketHandle.ih"
+
+// Custom includes
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include "Utils/Exception.hh"
+
+//#include "UDPSocketHandle.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::UDPv4SocketProtocol
+
+prefix_ void senf::UDPv4SocketProtocol::init_client()
+    const
+{
+    int sock = ::socket(PF_INET,SOCK_DGRAM,0);
+    if (sock < 0)
+        throw SystemException(errno);
+    body().fd(sock);
+}
+
+prefix_ void
+senf::UDPv4SocketProtocol::init_client(INet4Address const & address)
+    const
+{
+    init_client();
+    connect(address);
+}
+
+prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv4SocketProtocol::clone()
+    const
+{
+    return std::auto_ptr<SocketProtocol>(new UDPv4SocketProtocol());
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::UDPv6SocketProtocol::
+
+prefix_ void senf::UDPv6SocketProtocol::init_client()
+    const
+{
+    int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
+    if (sock < 0)
+        throw SystemException(errno);
+    body().fd(sock);
+}
+
+prefix_ void
+senf::UDPv6SocketProtocol::init_client(INet6SocketAddress const & address)
+    const
+{
+    init_client();
+    connect(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"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// End:
diff --git a/Socket/UDPSocketHandle.hh b/Socket/UDPSocketHandle.hh
new file mode 100644 (file)
index 0000000..d45f37c
--- /dev/null
@@ -0,0 +1,200 @@
+// $Id$
+//
+// Copyright (C) 2006
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief UDPv4SocketHandle and UDPv6SocketHandle public header
+
+    \todo Implement possibly non-blocking connect and SO_ERROR in the
+    protocol interface
+ */
+
+#ifndef HH_UDPSocketHandle_
+#define HH_UDPSocketHandle_ 1
+
+// Custom includes
+#include "INetProtocol.hh"
+#include "UDPProtocol.hh"
+#include "BSDSocketProtocol.hh"
+#include "FramingPolicy.hh"
+#include "CommunicationPolicy.hh"
+#include "ReadWritePolicy.hh"
+#include "BufferingPolicy.hh"
+#include "ProtocolClientSocketHandle.hh"
+
+//#include "UDPSocketHandle.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+    /// \addtogroup concrete_protocol_group
+    /// @{
+
+    typedef MakeSocketPolicy<
+        INet4AddressingPolicy,
+        DatagramFramingPolicy,
+        UnconnectedCommunicationPolicy,
+        ReadablePolicy,
+        WriteablePolicy,
+        SocketBufferingPolicy
+        >::policy UDPv4Socket_Policy;   ///< Socket Policy of the UDPv4 Protocol
+
+    /** \brief IPv4 UDP Socket Protocol
+
+        \par Socket Handle typedefs:
+        \ref UDPv4ClientSocketHandle (ProtocolClientSocketHandle)
+
+        \par Policy Interface:
+        ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
+        ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
+        ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
+
+        \par Address Type:
+        INet4Address
+
+        UDPv4SocketProtocol provides an internet protocol stream socket based on the UDP protocol
+        and IPv4 addressing.
+
+        This class is utilized as the protocol class of the ProtocolClientSocketHandle
+        via the Socket Handle typedefs above.
+
+        \see UDPv6SocketProtocol
+     */
+    class UDPv4SocketProtocol
+        : public ConcreteSocketProtocol<UDPv4Socket_Policy>,
+          public IPv4Protocol,
+          public UDPProtocol,
+          public BSDSocketProtocol,
+          public AddressableBSDSocketProtocol
+    {
+    public:
+        ///////////////////////////////////////////////////////////////////////////
+        // internal interface
+
+        ///\name Constructors
+        ///@{
+
+        void init_client() const;       ///< Create unconnected client socket
+                                        /**< \note This member is implicitly called from the
+                                             ProtocolClientSocketHandle::ProtocolClientSocketHandle()
+                                             constructor */
+        void init_client(INet4Address const & address) const;
+                                        ///< Create client socket and connect
+                                        /**< Creates a new client socket and connects to the given
+                                             address.
+
+                                             \param[in] address remote address to connect to */
+                                        /**< \note This member is implicitly called from the
+                                             ProtocolClientSocketHandle::ProtocolClientSocketHandle()
+                                             constructor */
+
+        ///@}
+        ///\name Abstract Interface Implementation
+
+        std::auto_ptr<SocketProtocol> clone() const;
+
+        ///@}
+    };
+
+    typedef ProtocolClientSocketHandle<UDPv4SocketProtocol> UDPv4ClientSocketHandle;
+
+    typedef MakeSocketPolicy<
+        UDPv4Socket_Policy,
+        INet6AddressingPolicy
+        >::policy UDPv6Socket_Policy;
+
+    /** \brief IPv6 UDP Socket Protocol
+
+        \par Socket Handle typedefs:
+        \ref UDPv6ClientSocketHandle (ProtocolClientSocketHandle)
+
+        \par Policy Interface:
+        ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
+        ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
+        ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
+
+        \par Address Type:
+        INet6Address
+
+        UDPv6SocketProtocol provides an internet protocol stream socket based on the UDP protocol
+        and IPv6 addressing.
+
+        This class is utilized as the protocol class of the ProtocolClientSocketHandle
+        via the Socket Handle typedefs above.
+
+        \see UDPv4SocketProtocol
+     */
+    class UDPv6SocketProtocol
+        : public ConcreteSocketProtocol<UDPv6Socket_Policy>,
+          public IPv6Protocol,
+          public UDPProtocol,
+          public BSDSocketProtocol,
+          public AddressableBSDSocketProtocol
+    {
+    public:
+        ///////////////////////////////////////////////////////////////////////////
+        // internal interface
+
+        ///\name Constructors
+        ///@{
+
+        void init_client() const;       ///< Create unconnected client socket
+                                        /**< \note This member is implicitly called from the
+                                             ProtocolClientSocketHandle::ProtocolClientSocketHandle()
+                                             constructor */
+        void init_client(INet6SocketAddress const & address) const;
+                                        ///< Create client socket and connect
+                                        /**< Creates a new client socket and connects to the given
+                                             address.
+
+                                             \param[in] address remote address to connect to */
+                                        /**< \note This member is implicitly called from the
+                                             ProtocolClientSocketHandle::ProtocolClientSocketHandle()
+                                             constructor */
+
+        ///@}
+        ///\name Abstract Interface Implementation
+
+        std::auto_ptr<SocketProtocol> clone() const;
+
+        ///@}
+    };
+
+    typedef ProtocolClientSocketHandle<UDPv6SocketProtocol> UDPv6ClientSocketHandle;
+
+    /// @}
+
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "UDPSocketHandle.cci"
+//#include "UDPSocketHandle.ct"
+//#include "UDPSocketHandle.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// End: