Merged revisions 570-572,574-575,578-579,581-595,598-611 via svnmerge from
g0dil [Thu, 17 Jan 2008 08:15:38 +0000 (08:15 +0000)]
https://svn.berlios.de/svnroot/repos/senf/branches/socket-cleanup

........
  r582 | g0dil | 2007-12-18 19:12:46 +0100 (Tue, 18 Dec 2007) | 2 lines

  Socket/Protocols: Move timestamp() (SIOCGSTAMP) into (new) DatagramSocketProtocol facet
  Socket/Protocols/INet: Rename all '*Inet*' classes and files to '*INet*'
........
  r584 | g0dil | 2007-12-19 21:05:41 +0100 (Wed, 19 Dec 2007) | 7 lines

  Socket: Add 'clientHandle()' and 'serverHandle()' members to 'ConcreteSocketProtocol' class
  Socket/Protocols: Removed 'connect()'/'bind()' members from all protocol classes
  Socket/Protoocols: Implemented 'BSDSocketProtocol::priority()'
  Socket/Protocols/INet: Implement 'INetProtocol' policy facet
  Socket/Protocols/INet: Implemented 'MulticastProtocol' and 'INet[46]MulticastProtocol' facets
  Socket/Protocols/INet: Moved all multicast members to the 'MulticastProtocol' facets and changed interface to use INet[46]Address instead of socket addresses
  Socket/Protocols/INet: Added multicast facets to RawV[46]SocketProtocol
........
  r595 | g0dil | 2008-01-14 14:52:16 +0100 (Mon, 14 Jan 2008) | 1 line

  Examples/MCSniffer: Fix address class from INet4SocketAddress to INet4Address
........
  r601 | g0dil | 2008-01-15 12:38:35 +0100 (Tue, 15 Jan 2008) | 1 line

  Add file missing from svnmerge
........
  r603 | g0dil | 2008-01-15 14:22:10 +0100 (Tue, 15 Jan 2008) | 1 line

  doclib: Fix integer field parser names
........
  r605 | g0dil | 2008-01-15 15:03:48 +0100 (Tue, 15 Jan 2008) | 2 lines

  Socket: Remove BufferingPolicy
  Socket: Add sndbuf/rcvbuf to BSDSocketProtocol protocol facet
........

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@612 270642c3-0616-0410-b53a-bc976706d245

52 files changed:
Examples/MCSniffer/MCSniffer.cc
Socket/BufferingPolicy.cc [deleted file]
Socket/BufferingPolicy.hh [deleted file]
Socket/ClientSocketHandle.cti
Socket/ClientSocketHandle.hh
Socket/ClientSocketHandle.test.cc
Socket/ProtocolServerSocketHandle.test.cc
Socket/Protocols/BSDSocketProtocol.cc
Socket/Protocols/BSDSocketProtocol.hh
Socket/Protocols/DVB/DVBDemuxHandles.hh
Socket/Protocols/DVB/DVBDemuxProtocol.hh
Socket/Protocols/DVB/DVBFrontendHandle.hh
Socket/Protocols/DatagramSocketProtocol.cc [copied from Socket/Protocols/INet/RawInetProtocol.cc with 70% similarity]
Socket/Protocols/DatagramSocketProtocol.hh [new file with mode: 0644]
Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc [moved from Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc with 92% similarity]
Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh [moved from Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh with 96% similarity]
Socket/Protocols/INet/ConnectedUDPSocketHandle.cc
Socket/Protocols/INet/ConnectedUDPSocketHandle.hh
Socket/Protocols/INet/INetProtocol.cc
Socket/Protocols/INet/INetProtocol.hh
Socket/Protocols/INet/MulticastProtocol.cc [new file with mode: 0644]
Socket/Protocols/INet/MulticastProtocol.hh [new file with mode: 0644]
Socket/Protocols/INet/RawINetProtocol.cc [moved from Socket/Protocols/INet/RawInetProtocol.cc with 90% similarity]
Socket/Protocols/INet/RawINetProtocol.hh [moved from Socket/Protocols/INet/RawInetProtocol.hh with 95% similarity]
Socket/Protocols/INet/RawINetSocketHandle.cc [moved from Socket/Protocols/INet/RawInetSocketHandle.cc with 93% similarity]
Socket/Protocols/INet/RawINetSocketHandle.hh [moved from Socket/Protocols/INet/RawInetSocketHandle.hh with 93% similarity]
Socket/Protocols/INet/RawINetSocketHandle.test.cc [moved from Socket/Protocols/INet/RawInetSocketHandle.test.cc with 85% similarity]
Socket/Protocols/INet/TCPSocketHandle.cc
Socket/Protocols/INet/TCPSocketHandle.hh
Socket/Protocols/INet/TCPSocketHandle.test.cc
Socket/Protocols/INet/UDPProtocol.cc
Socket/Protocols/INet/UDPProtocol.hh
Socket/Protocols/INet/UDPSocketHandle.cc
Socket/Protocols/INet/UDPSocketHandle.hh
Socket/Protocols/INet/UDPSocketHandle.test.cc
Socket/Protocols/Raw/PacketSocketHandle.hh
Socket/Protocols/Raw/TunTapSocketHandle.hh
Socket/Protocols/SConscript
Socket/Protocols/UN.hh [new file with mode: 0644]
Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc
Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh
Socket/Protocols/UN/UNDatagramSocketHandle.cc
Socket/Protocols/UN/UNDatagramSocketHandle.hh
Socket/Protocols/UN/UNProtocol.cc
Socket/Protocols/UN/UNProtocol.hh
Socket/SocketHandle.test.cc
Socket/SocketPolicy.hh
Socket/SocketPolicy.test.cc
Socket/SocketPolicy.test.hh
Socket/SocketProtocol.cti
Socket/SocketProtocol.hh
doclib/Doxyfile.global

index 60bef2f..fbb5fd7 100644 (file)
@@ -46,10 +46,10 @@ class MCSniffer
     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(
@@ -78,9 +78,9 @@ int main(int argc, char const * argv[])
         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();
     }
diff --git a/Socket/BufferingPolicy.cc b/Socket/BufferingPolicy.cc
deleted file mode 100644 (file)
index 888062a..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-// $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:
diff --git a/Socket/BufferingPolicy.hh b/Socket/BufferingPolicy.hh
deleted file mode 100644 (file)
index b871e37..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-// $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:
index 116a060..8bd5ca8 100644 (file)
@@ -349,37 +349,6 @@ bind(typename boost::call_traits<typename Policy::AddressingPolicy::Address>::pa
 }
 
 ////////////////////////////////////////
-// 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>
index 4030518..6150e28 100644 (file)
@@ -63,8 +63,6 @@ namespace senf {
         <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
@@ -422,24 +420,6 @@ namespace senf {
 
         ///@}
 
-        ///////////////////////////////////////////////////////////////////////////
-        ///\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);
 
index 51ad098..a7a253f 100644 (file)
@@ -130,11 +130,6 @@ BOOST_AUTO_UNIT_TEST(clientSocketHandle)
     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////////////////////////////////////////
index fbd539c..e45ed4d 100644 (file)
@@ -69,7 +69,7 @@ BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle)
                            "file.handle: -1\n"
                            "file.refcount: 2\n"
                            "handle: senf::ProtocolServerSocketHandle<(anonymous namespace)::MyProtocol>\n"
-                           "socket.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy, 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" );
 
index 4af1609..a625fcc 100644 (file)
@@ -57,15 +57,6 @@ prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
         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()
@@ -86,7 +77,63 @@ prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
         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"
 
index 87ebd85..988a627 100644 (file)
@@ -27,8 +27,8 @@
 #define HH_BSDSocketProtocol_ 1
 
 // Custom includes
-#include <sys/time.h>
 #include "../../Socket/SocketProtocol.hh"
+#include <boost/cstdint.hpp>
 
 //#include "BSDSocketProtocol.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
@@ -60,13 +60,6 @@ namespace senf {
                                              \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
@@ -85,6 +78,33 @@ namespace senf {
                                         /**< 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 */
+        
     };
 
     /// @}
index d88f0b5..59fd81a 100644 (file)
@@ -27,7 +27,6 @@
 #define HH_DVBDemuxHandles_ 1
 
 // Custom includes
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
@@ -47,8 +46,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         ReadablePolicy,
-        NotWriteablePolicy,
-        NoBufferingPolicy
+        NotWriteablePolicy
         >::policy DVBDemux_Policy;   ///< Socket Policy for xxxx
 
     /** \brief xxx
index b9b5eaa..9601ca7 100644 (file)
@@ -57,6 +57,8 @@ namespace senf {
 
         ///@}
     };
+
+    /// @}
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
index 158e3d0..f40bab9 100644 (file)
@@ -29,7 +29,6 @@
 // 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"
@@ -49,8 +48,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         NotReadablePolicy,
-        NotWriteablePolicy,
-        NoBufferingPolicy
+        NotWriteablePolicy
         >::policy DVBFrontend_Policy;   ///< Socket Policy for xxxx
 
     /** \brief xxx
similarity index 70%
copy from Socket/Protocols/INet/RawInetProtocol.cc
copy to Socket/Protocols/DatagramSocketProtocol.cc
index e46b50a..196a0b1 100644 (file)
@@ -1,9 +1,9 @@
 // $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:
diff --git a/Socket/Protocols/DatagramSocketProtocol.hh b/Socket/Protocols/DatagramSocketProtocol.hh
new file mode 100644 (file)
index 0000000..98929fc
--- /dev/null
@@ -0,0 +1,77 @@
+// $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:
@@ -1,4 +1,4 @@
-// $Id$
+// $Id: ConnectedRawINetSocketHandle.cc 597 2008-01-15 09:16:20Z g0dil $
 //
 // Copyright (C) 2007 
 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
@@ -20,7 +20,7 @@
 // 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>
@@ -57,7 +57,7 @@ senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol, INet4Socke
     const
 {
     init_client(protocol);
-    connect(address);
+    clientHandle().connect(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV4SocketProtocol::clone()
@@ -89,7 +89,7 @@ senf::ConnectedRawV6SocketProtocol::init_client(int const & protocol, INet6Socke
     const
 {
     init_client(protocol);
-    connect(address);
+    clientHandle().connect(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV6SocketProtocol::clone()
@@ -100,7 +100,7 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV6SocketProtocol::
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
-//#include "ConnectedRawInetSocketHandle.mpp"
+//#include "ConnectedRawINetSocketHandle.mpp"
 
 \f
 // Local Variables:
@@ -1,4 +1,4 @@
-// $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"
 
 
@@ -46,8 +45,7 @@ namespace senf {
         DatagramFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy ConnectedRawV4Socket_Policy;   ///< Socket Policy of the Connected RawV4 Protocol
 
     /** \brief IPv4 RAW Socket Protocol, connected
@@ -78,7 +76,7 @@ namespace senf {
     class ConnectedRawV4SocketProtocol
         : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy>,
           public IPv4Protocol,
-          public RawInetProtocol,
+          public RawINetProtocol,
           public BSDSocketProtocol,
           public AddressableBSDSocketProtocol//,
 //          public senf::pool_alloc_mixin<RawV4Socket_Policy>
@@ -122,8 +120,7 @@ namespace senf {
         DatagramFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy ConnectedRawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
 
     /** \brief IPv6 RAW Socket Protocol, connected
@@ -154,7 +151,7 @@ namespace senf {
     class ConnectedRawV6SocketProtocol
         : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy>,
           public IPv6Protocol,
-          public RawInetProtocol,
+          public RawINetProtocol,
           public BSDSocketProtocol,
           public AddressableBSDSocketProtocol//,
 //          public senf::pool_alloc_mixin<RawV6SocketProtocol>
index bd2052e..d1150ba 100644 (file)
@@ -55,7 +55,7 @@ senf::ConnectedUDPv4SocketProtocol::init_client(INet4SocketAddress const & addre
     const
 {
     init_client();
-    connect(address);
+    clientHandle().connect(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv4SocketProtocol::clone()
@@ -81,7 +81,7 @@ senf::ConnectedUDPv6SocketProtocol::init_client(INet6SocketAddress const & addre
     const
 {
     init_client();
-    connect(address);
+    clientHandle().connect(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUDPv6SocketProtocol::clone()
index 2851094..928cf80 100644 (file)
@@ -37,7 +37,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/ProtocolClientSocketHandle.hh"
 
 //#include "ConnectedUDPSocketHandle.mpp"
@@ -53,8 +52,7 @@ namespace senf {
         DatagramFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy ConnectedUDPv4Socket_Policy;   ///< Socket Policy of the UDPv4 Protocol
 
     /** \brief IPv4 UDP Socket Protocol, connected
index e8bc8b8..e23230f 100644 (file)
@@ -29,6 +29,7 @@
 // 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"
index 5d1f44b..89daa57 100644 (file)
@@ -47,6 +47,28 @@ namespace senf {
     /// \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
@@ -62,14 +84,6 @@ namespace senf {
         : 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
@@ -81,14 +95,6 @@ namespace senf {
         : 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 */
     };
 
     /// @}
diff --git a/Socket/Protocols/INet/MulticastProtocol.cc b/Socket/Protocols/INet/MulticastProtocol.cc
new file mode 100644 (file)
index 0000000..ee64285
--- /dev/null
@@ -0,0 +1,245 @@
+// $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:
diff --git a/Socket/Protocols/INet/MulticastProtocol.hh b/Socket/Protocols/INet/MulticastProtocol.hh
new file mode 100644 (file)
index 0000000..1d3d0f6
--- /dev/null
@@ -0,0 +1,196 @@
+// $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:
similarity index 90%
rename from Socket/Protocols/INet/RawInetProtocol.cc
rename to Socket/Protocols/INet/RawINetProtocol.cc
index e46b50a..be22955 100644 (file)
@@ -1,4 +1,4 @@
-// $Id$
+// $Id: RawINetProtocol.cc 597 2008-01-15 09:16:20Z g0dil $
 //
 // Copyright (C) 2007 
 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
@@ -21,7 +21,7 @@
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 
-#include "RawInetProtocol.hh"
+#include "RawINetProtocol.hh"
 
 // Custom includes
 #include <sys/socket.h>
@@ -35,7 +35,7 @@
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-prefix_ unsigned senf::RawInetProtocol::available()
+prefix_ unsigned senf::RawINetProtocol::available()
     const
 {
     int n;
@@ -44,7 +44,7 @@ prefix_ unsigned senf::RawInetProtocol::available()
     return n;
 }
 
-prefix_ bool senf::RawInetProtocol::eof()
+prefix_ bool senf::RawINetProtocol::eof()
     const
 {
     return false;
similarity index 95%
rename from Socket/Protocols/INet/RawInetProtocol.hh
rename to Socket/Protocols/INet/RawINetProtocol.hh
index 9f823fc..e0fb7e2 100644 (file)
@@ -1,4 +1,4 @@
-// $Id$
+// $Id: RawINetProtocol.hh 597 2008-01-15 09:16:20Z g0dil $
 //
 // Copyright (C) 2007 
 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
@@ -30,7 +30,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/ProtocolClientSocketHandle.hh"
 
 namespace senf {
@@ -44,7 +43,7 @@ namespace senf {
         which are available on a PF_INET[6]/RAW socket.
         
      */
-    class RawInetProtocol
+    class RawINetProtocol
         : public virtual SocketProtocol
     {
     public:
similarity index 93%
rename from Socket/Protocols/INet/RawInetSocketHandle.cc
rename to Socket/Protocols/INet/RawINetSocketHandle.cc
index 6809676..c775948 100644 (file)
@@ -1,4 +1,4 @@
-// $Id$
+// $Id: RawINetSocketHandle.cc 597 2008-01-15 09:16:20Z g0dil $
 //
 // Copyright (C) 2007 
 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
@@ -20,7 +20,7 @@
 // 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>
@@ -57,7 +57,7 @@ senf::RawV4SocketProtocol::init_client(int const & protocol, INet4SocketAddress
     const
 {
     init_client(protocol);
-    bind(address);
+    clientHandle().bind(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV4SocketProtocol::clone()
@@ -89,7 +89,7 @@ senf::RawV6SocketProtocol::init_client(int const & protocol, INet6SocketAddress
     const
 {
     init_client(protocol);
-    bind(address);
+    clientHandle().bind(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV6SocketProtocol::clone()
@@ -100,7 +100,7 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV6SocketProtocol::clone()
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
-//#include "RawInetSocketHandle.mpp"
+//#include "RawINetSocketHandle.mpp"
 
 \f
 // Local Variables:
similarity index 93%
rename from Socket/Protocols/INet/RawInetSocketHandle.hh
rename to Socket/Protocols/INet/RawINetSocketHandle.hh
index 2bbb49a..2886c7f 100644 (file)
@@ -1,4 +1,4 @@
-// $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"
 
 
@@ -47,8 +47,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy RawV4Socket_Policy;   ///< Socket Policy of the RawV4 Protocol
 
     /** \brief IPv4 RAW Socket Protocol
@@ -77,10 +76,12 @@ namespace senf {
     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:
         ///////////////////////////////////////////////////////////////////////////
@@ -121,8 +122,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy RawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
 
     /** \brief IPv6 RAW Socket Protocol
@@ -151,10 +151,12 @@ namespace senf {
     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:
         ///////////////////////////////////////////////////////////////////////////
@@ -1,4 +1,4 @@
-// $Id$
+// $Id: RawINetSocketHandle.test.cc 597 2008-01-15 09:16:20Z g0dil $
 //
 // Copyright (C) 2007 
 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
@@ -21,7 +21,7 @@
 // 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>
@@ -29,7 +29,7 @@
 #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"
@@ -148,10 +148,10 @@ BOOST_AUTO_UNIT_TEST(RawV4ClientSocketHandle)
         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();
@@ -178,10 +178,10 @@ BOOST_AUTO_UNIT_TEST(RawV6ClientSocketHandle)
         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();
@@ -193,3 +193,17 @@ BOOST_AUTO_UNIT_TEST(RawV6ClientSocketHandle)
         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:
index 66296d5..1b38473 100644 (file)
@@ -55,7 +55,7 @@ senf::TCPv4SocketProtocol::init_client(INet4SocketAddress const & address)
     const
 {
     init_client();
-    connect(address);
+    clientHandle().connect(address);
 }
 
 prefix_ void senf::TCPv4SocketProtocol::init_server()
@@ -72,7 +72,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & a
     const
 {
     init_server();
-    bind(address);
+    serverHandle().bind(address);
     reuseaddr(true);
     if (::listen(fd(),backlog) < 0)
         throwErrno();
@@ -101,7 +101,7 @@ senf::TCPv6SocketProtocol::init_client(INet6SocketAddress const & address)
     const
 {
     init_client();
-    connect(address);
+    clientHandle().connect(address);
 }
 
 prefix_ void senf::TCPv6SocketProtocol::init_server()
@@ -118,7 +118,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & a
     const
 {
     init_server();
-    bind(address);
+    serverHandle().bind(address);
     reuseaddr(true);
     if (::listen(fd(),backlog) < 0)
         throwErrno();
index f018473..b3293de 100644 (file)
@@ -38,7 +38,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/ProtocolClientSocketHandle.hh"
 #include "../../../Socket/ProtocolServerSocketHandle.hh"
 
@@ -55,8 +54,7 @@ namespace senf {
         StreamFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy TCPv4Socket_Policy;   ///< Socket Policy of the TCPv4 Protocol
 
     /** \brief IPv4 TCP Socket Protocol
index 9180166..216cadc 100644 (file)
@@ -159,8 +159,6 @@ BOOST_AUTO_UNIT_TEST(tcpv4ClientSocketHandle)
 
         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 {
@@ -172,10 +170,10 @@ BOOST_AUTO_UNIT_TEST(tcpv4ClientSocketHandle)
         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() );
@@ -243,10 +241,10 @@ BOOST_AUTO_UNIT_TEST(tcpv6ClientSocketHandle)
         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 ????
index d7b680d..3b276b3 100644 (file)
@@ -55,102 +55,6 @@ prefix_ bool senf::UDPProtocol::eof()
     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"
index 458bafc..5bb7293 100644 (file)
@@ -50,53 +50,6 @@ namespace senf {
         : 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
         ///@{
 
index 28947ca..687ad59 100644 (file)
@@ -55,7 +55,7 @@ senf::UDPv4SocketProtocol::init_client(INet4SocketAddress const & address)
     const
 {
     init_client();
-    bind(address);
+    clientHandle().bind(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv4SocketProtocol::clone()
@@ -81,7 +81,7 @@ senf::UDPv6SocketProtocol::init_client(INet6SocketAddress const & address)
     const
 {
     init_client();
-    bind(address);
+    clientHandle().bind(address);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::UDPv6SocketProtocol::clone()
index 96266c0..13673e8 100644 (file)
 // 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"
@@ -53,8 +54,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy UDPv4Socket_Policy;   ///< Socket Policy of the UDPv4 Protocol
 
     /** \brief IPv4 UDP Socket Protocol
@@ -82,7 +82,10 @@ namespace senf {
         : public ConcreteSocketProtocol<UDPv4Socket_Policy>,
           public IPv4Protocol,
           public UDPProtocol,
+          public MulticastProtocol,
+          public INet4MulticastProtocol,
           public BSDSocketProtocol,
+          public DatagramSocketProtocol,
           public AddressableBSDSocketProtocol,
           public senf::pool_alloc_mixin<UDPv4SocketProtocol>
     {
@@ -112,6 +115,7 @@ namespace senf {
         std::auto_ptr<SocketProtocol> clone() const;
 
         ///@}
+
     };
 
     typedef ProtocolClientSocketHandle<UDPv4SocketProtocol> UDPv4ClientSocketHandle;
@@ -146,7 +150,10 @@ namespace senf {
         : public ConcreteSocketProtocol<UDPv6Socket_Policy>,
           public IPv6Protocol,
           public UDPProtocol,
+          public MulticastProtocol,
+          public INet6MulticastProtocol,
           public BSDSocketProtocol,
+          public DatagramSocketProtocol,
           public AddressableBSDSocketProtocol,
           public senf::pool_alloc_mixin<UDPv6SocketProtocol>
     {
index 4f3fd6f..7e1d73f 100644 (file)
@@ -146,10 +146,10 @@ BOOST_AUTO_UNIT_TEST(udpv4ClientSocketHandle)
         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" );
index b159209..a44edf2 100644 (file)
@@ -36,7 +36,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
 #include "LLAddressing.hh"
 
@@ -54,8 +53,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy Packet_Policy;        ///< Policy of PacketProtocol
 
     /** \brief Raw Packet-Socket access (Linux)
@@ -125,6 +123,7 @@ namespace senf {
         void mcDrop(std::string const & interface, MACAddress const & address) const;
                                         ///< Disable reception of a multicast group
                                         /**< \see \ref mcAdd() */
+
         ///@}
 
         ///\name Abstract Interface Implementation
index 86c3668..4e66de0 100644 (file)
@@ -36,7 +36,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
 #include "LLAddressing.hh"
 
@@ -54,8 +53,7 @@ namespace senf {
         DatagramFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy Tap_Policy;        ///< Policy for TAP
 
     /** \brief TAP
index 3b7b158..0a99e52 100644 (file)
@@ -14,6 +14,6 @@ for sc in glob.glob("*/SConscript"):
     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')
diff --git a/Socket/Protocols/UN.hh b/Socket/Protocols/UN.hh
new file mode 100644 (file)
index 0000000..759376b
--- /dev/null
@@ -0,0 +1,37 @@
+// $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:
index 1426648..c4b48b1 100644 (file)
@@ -47,7 +47,7 @@ prefix_ void senf::ConnectedUNDatagramSocketProtocol::init_client() const
 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()
@@ -59,3 +59,14 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedUNDatagramSocketProto
 ///////////////////////////////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:
index 3e38768..6a3d8c6 100644 (file)
@@ -33,7 +33,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/ProtocolClientSocketHandle.hh"
 
 //#include "UNDatagramSocketHandle.mpp"
@@ -49,8 +48,7 @@ namespace senf {
         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)
@@ -111,4 +109,19 @@ namespace senf {
 
 }
 
-#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:
index e1266b5..77408fa 100644 (file)
@@ -48,7 +48,7 @@ prefix_ void senf::UNDatagramSocketProtocol::init_client() const
 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()
index 986acdf..3b7f8a5 100644 (file)
@@ -33,7 +33,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/ProtocolClientSocketHandle.hh"
 
 //#include "UNDatagramSocketHandle.mpp"
@@ -49,8 +48,7 @@ namespace senf {
         DatagramFramingPolicy,
         UnconnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
+        WriteablePolicy
         >::policy UNDatagramSocket_Policy;   ///< Socket Policy of the Unix Domain Datagram Protocol
 
     /** \brief Unix Domain Datagram Socket Protocol
index d1c1514..507457f 100644 (file)
@@ -51,23 +51,6 @@ prefix_ bool senf::UNProtocol::eof()
     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
 {
@@ -96,27 +79,6 @@ prefix_ void senf::UNProtocol::check_and_unlink()
     }
 }
     
-// //  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"
index 2475cf9..5314196 100644 (file)
@@ -44,23 +44,11 @@ namespace senf {
 
         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.
@@ -82,6 +70,8 @@ namespace senf {
       
         std::string path_;
     };
+
+    ///@}
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
index f8494a3..0bcb477 100644 (file)
@@ -90,8 +90,8 @@ BOOST_AUTO_UNIT_TEST(socketHandle)
     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" );
 }
index 3509acc..bc7ffc7 100644 (file)
@@ -23,9 +23,6 @@
 /** \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?
 
@@ -41,7 +38,6 @@
     \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" />
@@ -71,9 +67,6 @@
 
     <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
@@ -280,8 +272,7 @@ namespace senf {
         (FramingPolicy)                         \
         (CommunicationPolicy)                   \
         (ReadPolicy)                            \
-        (WritePolicy)                           \
-        (BufferingPolicy)
+        (WritePolicy)
 
     // Wer define these classes explicitly (and not with some macro
     // magic) because
@@ -396,18 +387,6 @@ namespace senf {
         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):
     //
index 78f9297..0a99bdf 100644 (file)
@@ -56,8 +56,6 @@ namespace {
     struct WritablePolicy : public WritePolicyBase {};
     struct UnwritablePolicy : public WritePolicyBase {};
 
-    struct SocketBufferingPolicy : public BufferingPolicyBase {};
-
     template <class Policy>
     struct ConvertibleValue
     {
@@ -95,8 +93,7 @@ BOOST_AUTO_UNIT_TEST(socketPolicy)
         UnspecifiedFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        UnspecifiedWritePolicy,
-        UnspecifiedBufferingPolicy> Policy2;
+        UnspecifiedWritePolicy> Policy2;
 
     BOOST_MPL_ASSERT(( boost::is_same<Policy1,Policy2> ));
 
@@ -109,8 +106,7 @@ BOOST_AUTO_UNIT_TEST(socketPolicy)
         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> ));
index cc726f6..4740f6e 100644 (file)
@@ -94,26 +94,12 @@ namespace test {
             }
     };
 
-    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;
 
 }}
index 45fc549..1c16b75 100644 (file)
@@ -27,6 +27,7 @@
 //#include "SocketProtocol.ih"
 
 // Custom includes
+#include "SocketHandle.hh"
 
 #define prefix_ inline
 ///////////////////////////////cti.p///////////////////////////////////////
@@ -46,6 +47,25 @@ senf::ConcreteSocketProtocol<SocketPolicy>::policy()
     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_
 
index e05beac..fa8d0ff 100644 (file)
 
     \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
@@ -148,7 +148,7 @@ namespace senf {
         ///////////////////////////////////////////////////////////////////////////
 
         virtual SocketPolicyBase const & policy() const = 0;
-                                        ///< Access the policy instance
+        ///< Access the policy instance
 
         ///////////////////////////////////////////////////////////////////////////
         // Virtual interface
@@ -187,18 +187,18 @@ namespace senf {
                                              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
@@ -209,7 +209,7 @@ namespace senf {
                                              \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
@@ -220,21 +220,21 @@ namespace senf {
                                              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. */
@@ -266,8 +266,10 @@ namespace senf {
 
         SocketBody * body_;
         friend class SocketBody;
-   };
-
+    };
+    
+    template <class Policy> class ClientSocketHandle;
+    template <class Policy> class ServerSocketHandle;
 
     /** \brief Concrete Socket Protocol implementation base class
 
@@ -312,6 +314,14 @@ namespace senf {
         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_;
index cbf545f..8b6455f 100644 (file)
@@ -47,9 +47,9 @@ PREDEFINED             = \
     "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" \