From: g0dil Date: Thu, 17 Jan 2008 08:15:38 +0000 (+0000) Subject: Merged revisions 570-572,574-575,578-579,581-595,598-611 via svnmerge from X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5ed1fa1c42763aebad06c1e4ac8fc5a19e15519a;p=senf.git Merged revisions 570-572,574-575,578-579,581-595,598-611 via svnmerge from 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 --- diff --git a/Examples/MCSniffer/MCSniffer.cc b/Examples/MCSniffer/MCSniffer.cc index 60bef2f..fbb5fd7 100644 --- a/Examples/MCSniffer/MCSniffer.cc +++ b/Examples/MCSniffer/MCSniffer.cc @@ -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 index 888062a..0000000 --- a/Socket/BufferingPolicy.cc +++ /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 -// -// 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 -#include -#include -#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" - - -// 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 index b871e37..0000000 --- a/Socket/BufferingPolicy.hh +++ /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 -// -// 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 - - -// 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/ClientSocketHandle.cti b/Socket/ClientSocketHandle.cti index 116a060..8bd5ca8 100644 --- a/Socket/ClientSocketHandle.cti +++ b/Socket/ClientSocketHandle.cti @@ -349,37 +349,6 @@ bind(typename boost::call_traits::pa } //////////////////////////////////////// -// Buffering - -// senf::ClientSocketHandle::rcvbuf - -template -prefix_ unsigned senf::ClientSocketHandle::rcvbuf() -{ - return Policy::BufferingPolicy::rcvbuf(*this); -} - -template -prefix_ void senf::ClientSocketHandle::rcvbuf(unsigned size) -{ - Policy::BufferingPolicy::rcvbuf(*this,size); -} - -// senf::ClientSocketHandle::sndbuf - -template -prefix_ unsigned senf::ClientSocketHandle::sndbuf() -{ - return Policy::BufferingPolicy::sndbuf(*this); -} - -template -prefix_ void senf::ClientSocketHandle::sndbuf(unsigned size) -{ - Policy::BufferingPolicy::sndbuf(*this,size); -} - -//////////////////////////////////////// // Casting template diff --git a/Socket/ClientSocketHandle.hh b/Socket/ClientSocketHandle.hh index 4030518..6150e28 100644 --- a/Socket/ClientSocketHandle.hh +++ b/Socket/ClientSocketHandle.hh @@ -63,8 +63,6 @@ namespace senf { bind() AddressingPolicy::bind (\ref senf::AddressingPolicyBase) peer() AddressingPolicy::peer (\ref senf::AddressingPolicyBase) local() AddressingPolicy::local (\ref senf::AddressingPolicyBase) - rcvbuf() BufferingPolicy::sndbuf (\ref senf::BufferingPolicyBase) - sndbuf() BufferingPolicy::rcvbuf (\ref senf::BufferingPolicyBase) 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); diff --git a/Socket/ClientSocketHandle.test.cc b/Socket/ClientSocketHandle.test.cc index 51ad098..a7a253f 100644 --- a/Socket/ClientSocketHandle.test.cc +++ b/Socket/ClientSocketHandle.test.cc @@ -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//////////////////////////////////////// diff --git a/Socket/ProtocolServerSocketHandle.test.cc b/Socket/ProtocolServerSocketHandle.test.cc index fbd539c..e45ed4d 100644 --- a/Socket/ProtocolServerSocketHandle.test.cc +++ b/Socket/ProtocolServerSocketHandle.test.cc @@ -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\n" + "socket.policy: senf::SocketPolicy\n" "socket.protocol: (anonymous namespace)::MyProtocol\n" "socket.server: true\n" ); diff --git a/Socket/Protocols/BSDSocketProtocol.cc b/Socket/Protocols/BSDSocketProtocol.cc index 4af1609..a625fcc 100644 --- a/Socket/Protocols/BSDSocketProtocol.cc +++ b/Socket/Protocols/BSDSocketProtocol.cc @@ -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" diff --git a/Socket/Protocols/BSDSocketProtocol.hh b/Socket/Protocols/BSDSocketProtocol.hh index 87ebd85..988a627 100644 --- a/Socket/Protocols/BSDSocketProtocol.hh +++ b/Socket/Protocols/BSDSocketProtocol.hh @@ -27,8 +27,8 @@ #define HH_BSDSocketProtocol_ 1 // Custom includes -#include #include "../../Socket/SocketProtocol.hh" +#include //#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 */ + }; /// @} diff --git a/Socket/Protocols/DVB/DVBDemuxHandles.hh b/Socket/Protocols/DVB/DVBDemuxHandles.hh index d88f0b5..59fd81a 100644 --- a/Socket/Protocols/DVB/DVBDemuxHandles.hh +++ b/Socket/Protocols/DVB/DVBDemuxHandles.hh @@ -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 diff --git a/Socket/Protocols/DVB/DVBDemuxProtocol.hh b/Socket/Protocols/DVB/DVBDemuxProtocol.hh index b9b5eaa..9601ca7 100644 --- a/Socket/Protocols/DVB/DVBDemuxProtocol.hh +++ b/Socket/Protocols/DVB/DVBDemuxProtocol.hh @@ -57,6 +57,8 @@ namespace senf { ///@} }; + + /// @} } ///////////////////////////////hh.e//////////////////////////////////////// diff --git a/Socket/Protocols/DVB/DVBFrontendHandle.hh b/Socket/Protocols/DVB/DVBFrontendHandle.hh index 158e3d0..f40bab9 100644 --- a/Socket/Protocols/DVB/DVBFrontendHandle.hh +++ b/Socket/Protocols/DVB/DVBFrontendHandle.hh @@ -29,7 +29,6 @@ // Custom includes #include #include -#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 diff --git a/Socket/Protocols/INet/RawInetProtocol.cc b/Socket/Protocols/DatagramSocketProtocol.cc similarity index 70% copy from Socket/Protocols/INet/RawInetProtocol.cc copy to Socket/Protocols/DatagramSocketProtocol.cc index e46b50a..196a0b1 100644 --- a/Socket/Protocols/INet/RawInetProtocol.cc +++ b/Socket/Protocols/DatagramSocketProtocol.cc @@ -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 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // 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 @@ -20,39 +20,33 @@ // 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 #include -#include #include -#include // for SIOCINQ / SIOCOUTQ -#include // 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" // Local Variables: diff --git a/Socket/Protocols/DatagramSocketProtocol.hh b/Socket/Protocols/DatagramSocketProtocol.hh new file mode 100644 index 0000000..98929fc --- /dev/null +++ b/Socket/Protocols/DatagramSocketProtocol.hh @@ -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 +// +// 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 +#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 + + +// 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/ConnectedRawInetSocketHandle.cc b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc similarity index 92% rename from Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc rename to Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc index 32a0108..39bb3dc 100644 --- a/Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc +++ b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc @@ -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 @@ -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::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::ConnectedRawV6SocketProtocol::clone() @@ -100,7 +100,7 @@ prefix_ std::auto_ptr senf::ConnectedRawV6SocketProtocol:: ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ -//#include "ConnectedRawInetSocketHandle.mpp" +//#include "ConnectedRawINetSocketHandle.mpp" // Local Variables: diff --git a/Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh similarity index 96% rename from Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh rename to Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh index 3fb1bd7..5cd86f8 100644 --- a/Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh +++ b/Socket/Protocols/INet/ConnectedRawINetSocketHandle.hh @@ -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) @@ -25,12 +25,11 @@ // 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, public IPv4Protocol, - public RawInetProtocol, + public RawINetProtocol, public BSDSocketProtocol, public AddressableBSDSocketProtocol//, // public senf::pool_alloc_mixin @@ -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, public IPv6Protocol, - public RawInetProtocol, + public RawINetProtocol, public BSDSocketProtocol, public AddressableBSDSocketProtocol//, // public senf::pool_alloc_mixin diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc index bd2052e..d1150ba 100644 --- a/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.cc @@ -55,7 +55,7 @@ senf::ConnectedUDPv4SocketProtocol::init_client(INet4SocketAddress const & addre const { init_client(); - connect(address); + clientHandle().connect(address); } prefix_ std::auto_ptr 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::ConnectedUDPv6SocketProtocol::clone() diff --git a/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh b/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh index 2851094..928cf80 100644 --- a/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh +++ b/Socket/Protocols/INet/ConnectedUDPSocketHandle.hh @@ -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 diff --git a/Socket/Protocols/INet/INetProtocol.cc b/Socket/Protocols/INet/INetProtocol.cc index e8bc8b8..e23230f 100644 --- a/Socket/Protocols/INet/INetProtocol.cc +++ b/Socket/Protocols/INet/INetProtocol.cc @@ -29,6 +29,7 @@ // Custom includes #include #include +#include #include "../../../Utils/Exception.hh" //#include "INetProtocol.mpp" @@ -36,40 +37,32 @@ ///////////////////////////////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" diff --git a/Socket/Protocols/INet/INetProtocol.hh b/Socket/Protocols/INet/INetProtocol.hh index 5d1f44b..89daa57 100644 --- a/Socket/Protocols/INet/INetProtocol.hh +++ b/Socket/Protocols/INet/INetProtocol.hh @@ -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 index 0000000..ee64285 --- /dev/null +++ b/Socket/Protocols/INet/MulticastProtocol.cc @@ -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 +// +// 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 +#include +#include // 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" + + +// 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 index 0000000..1d3d0f6 --- /dev/null +++ b/Socket/Protocols/INet/MulticastProtocol.hh @@ -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 +// +// 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 + + +// 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/RawInetProtocol.cc b/Socket/Protocols/INet/RawINetProtocol.cc similarity index 90% rename from Socket/Protocols/INet/RawInetProtocol.cc rename to Socket/Protocols/INet/RawINetProtocol.cc index e46b50a..be22955 100644 --- a/Socket/Protocols/INet/RawInetProtocol.cc +++ b/Socket/Protocols/INet/RawINetProtocol.cc @@ -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 @@ -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; diff --git a/Socket/Protocols/INet/RawInetProtocol.hh b/Socket/Protocols/INet/RawINetProtocol.hh similarity index 95% rename from Socket/Protocols/INet/RawInetProtocol.hh rename to Socket/Protocols/INet/RawINetProtocol.hh index 9f823fc..e0fb7e2 100644 --- a/Socket/Protocols/INet/RawInetProtocol.hh +++ b/Socket/Protocols/INet/RawINetProtocol.hh @@ -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: diff --git a/Socket/Protocols/INet/RawInetSocketHandle.cc b/Socket/Protocols/INet/RawINetSocketHandle.cc similarity index 93% rename from Socket/Protocols/INet/RawInetSocketHandle.cc rename to Socket/Protocols/INet/RawINetSocketHandle.cc index 6809676..c775948 100644 --- a/Socket/Protocols/INet/RawInetSocketHandle.cc +++ b/Socket/Protocols/INet/RawINetSocketHandle.cc @@ -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 @@ -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::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::RawV6SocketProtocol::clone() @@ -100,7 +100,7 @@ prefix_ std::auto_ptr senf::RawV6SocketProtocol::clone() ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ -//#include "RawInetSocketHandle.mpp" +//#include "RawINetSocketHandle.mpp" // Local Variables: diff --git a/Socket/Protocols/INet/RawInetSocketHandle.hh b/Socket/Protocols/INet/RawINetSocketHandle.hh similarity index 93% rename from Socket/Protocols/INet/RawInetSocketHandle.hh rename to Socket/Protocols/INet/RawINetSocketHandle.hh index 2bbb49a..2886c7f 100644 --- a/Socket/Protocols/INet/RawInetSocketHandle.hh +++ b/Socket/Protocols/INet/RawINetSocketHandle.hh @@ -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) @@ -26,12 +26,12 @@ // 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, public IPv4Protocol, - public RawInetProtocol, + public RawINetProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol//, -// public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol, + public MulticastProtocol, + public INet4MulticastProtocol, + public senf::pool_alloc_mixin { 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, public IPv6Protocol, - public RawInetProtocol, + public RawINetProtocol, public BSDSocketProtocol, - public AddressableBSDSocketProtocol//, -// public senf::pool_alloc_mixin + public AddressableBSDSocketProtocol, + public MulticastProtocol, + public INet4MulticastProtocol, + public senf::pool_alloc_mixin { public: /////////////////////////////////////////////////////////////////////////// diff --git a/Socket/Protocols/INet/RawInetSocketHandle.test.cc b/Socket/Protocols/INet/RawINetSocketHandle.test.cc similarity index 85% rename from Socket/Protocols/INet/RawInetSocketHandle.test.cc rename to Socket/Protocols/INet/RawINetSocketHandle.test.cc index 96b0383..c83f381 100644 --- a/Socket/Protocols/INet/RawInetSocketHandle.test.cc +++ b/Socket/Protocols/INet/RawINetSocketHandle.test.cc @@ -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 #include @@ -29,7 +29,7 @@ #include #include #include -#include "RawInetSocketHandle.hh" +#include "RawINetSocketHandle.hh" #include #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_ + + +// 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/TCPSocketHandle.cc b/Socket/Protocols/INet/TCPSocketHandle.cc index 66296d5..1b38473 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.cc +++ b/Socket/Protocols/INet/TCPSocketHandle.cc @@ -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(); diff --git a/Socket/Protocols/INet/TCPSocketHandle.hh b/Socket/Protocols/INet/TCPSocketHandle.hh index f018473..b3293de 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.hh +++ b/Socket/Protocols/INet/TCPSocketHandle.hh @@ -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 diff --git a/Socket/Protocols/INet/TCPSocketHandle.test.cc b/Socket/Protocols/INet/TCPSocketHandle.test.cc index 9180166..216cadc 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.test.cc +++ b/Socket/Protocols/INet/TCPSocketHandle.test.cc @@ -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 ???? diff --git a/Socket/Protocols/INet/UDPProtocol.cc b/Socket/Protocols/INet/UDPProtocol.cc index d7b680d..3b276b3 100644 --- a/Socket/Protocols/INet/UDPProtocol.cc +++ b/Socket/Protocols/INet/UDPProtocol.cc @@ -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(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(mcAddr.sockaddr_p())->sin_addr; - mreqn.imr_address = reinterpret_cast(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(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(mcAddr.sockaddr_p())->sin_addr; - mreqn.imr_address = reinterpret_cast(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" diff --git a/Socket/Protocols/INet/UDPProtocol.hh b/Socket/Protocols/INet/UDPProtocol.hh index 458bafc..5bb7293 100644 --- a/Socket/Protocols/INet/UDPProtocol.hh +++ b/Socket/Protocols/INet/UDPProtocol.hh @@ -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 ///@{ diff --git a/Socket/Protocols/INet/UDPSocketHandle.cc b/Socket/Protocols/INet/UDPSocketHandle.cc index 28947ca..687ad59 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.cc +++ b/Socket/Protocols/INet/UDPSocketHandle.cc @@ -55,7 +55,7 @@ senf::UDPv4SocketProtocol::init_client(INet4SocketAddress const & address) const { init_client(); - bind(address); + clientHandle().bind(address); } prefix_ std::auto_ptr 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::UDPv6SocketProtocol::clone() diff --git a/Socket/Protocols/INet/UDPSocketHandle.hh b/Socket/Protocols/INet/UDPSocketHandle.hh index 96266c0..13673e8 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.hh +++ b/Socket/Protocols/INet/UDPSocketHandle.hh @@ -33,11 +33,12 @@ // 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, public IPv4Protocol, public UDPProtocol, + public MulticastProtocol, + public INet4MulticastProtocol, public BSDSocketProtocol, + public DatagramSocketProtocol, public AddressableBSDSocketProtocol, public senf::pool_alloc_mixin { @@ -112,6 +115,7 @@ namespace senf { std::auto_ptr clone() const; ///@} + }; typedef ProtocolClientSocketHandle UDPv4ClientSocketHandle; @@ -146,7 +150,10 @@ namespace senf { : public ConcreteSocketProtocol, public IPv6Protocol, public UDPProtocol, + public MulticastProtocol, + public INet6MulticastProtocol, public BSDSocketProtocol, + public DatagramSocketProtocol, public AddressableBSDSocketProtocol, public senf::pool_alloc_mixin { diff --git a/Socket/Protocols/INet/UDPSocketHandle.test.cc b/Socket/Protocols/INet/UDPSocketHandle.test.cc index 4f3fd6f..7e1d73f 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.test.cc +++ b/Socket/Protocols/INet/UDPSocketHandle.test.cc @@ -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" ); diff --git a/Socket/Protocols/Raw/PacketSocketHandle.hh b/Socket/Protocols/Raw/PacketSocketHandle.hh index b159209..a44edf2 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.hh +++ b/Socket/Protocols/Raw/PacketSocketHandle.hh @@ -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 diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.hh b/Socket/Protocols/Raw/TunTapSocketHandle.hh index 86c3668..4e66de0 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.hh +++ b/Socket/Protocols/Raw/TunTapSocketHandle.hh @@ -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 diff --git a/Socket/Protocols/SConscript b/Socket/Protocols/SConscript index 3b7b158..0a99e52 100644 --- a/Socket/Protocols/SConscript +++ b/Socket/Protocols/SConscript @@ -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 index 0000000..759376b --- /dev/null +++ b/Socket/Protocols/UN.hh @@ -0,0 +1,37 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// 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" + + +// 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/UN/ConnectedUNDatagramSocketHandle.cc b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc index 1426648..c4b48b1 100644 --- a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc +++ b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.cc @@ -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::ConnectedUNDatagramSocketProtocol::clone() @@ -59,3 +59,14 @@ prefix_ std::auto_ptr senf::ConnectedUNDatagramSocketProto ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "UNDatagramSocketHandle.mpp" + + +// 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/UN/ConnectedUNDatagramSocketHandle.hh b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh index 3e38768..6a3d8c6 100644 --- a/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh +++ b/Socket/Protocols/UN/ConnectedUNDatagramSocketHandle.hh @@ -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 + + +// 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/UN/UNDatagramSocketHandle.cc b/Socket/Protocols/UN/UNDatagramSocketHandle.cc index e1266b5..77408fa 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.cc +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.cc @@ -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::UNDatagramSocketProtocol::clone() diff --git a/Socket/Protocols/UN/UNDatagramSocketHandle.hh b/Socket/Protocols/UN/UNDatagramSocketHandle.hh index 986acdf..3b7f8a5 100644 --- a/Socket/Protocols/UN/UNDatagramSocketHandle.hh +++ b/Socket/Protocols/UN/UNDatagramSocketHandle.hh @@ -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 diff --git a/Socket/Protocols/UN/UNProtocol.cc b/Socket/Protocols/UN/UNProtocol.cc index d1c1514..507457f 100644 --- a/Socket/Protocols/UN/UNProtocol.cc +++ b/Socket/Protocols/UN/UNProtocol.cc @@ -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" diff --git a/Socket/Protocols/UN/UNProtocol.hh b/Socket/Protocols/UN/UNProtocol.hh index 2475cf9..5314196 100644 --- a/Socket/Protocols/UN/UNProtocol.hh +++ b/Socket/Protocols/UN/UNProtocol.hh @@ -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//////////////////////////////////////// diff --git a/Socket/SocketHandle.test.cc b/Socket/SocketHandle.test.cc index f8494a3..0bcb477 100644 --- a/Socket/SocketHandle.test.cc +++ b/Socket/SocketHandle.test.cc @@ -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 >\n" - "socket.policy: senf::SocketPolicy\n" + "handle: senf::SocketHandle >\n" + "socket.policy: senf::SocketPolicy\n" "socket.protocol: senf::test::SomeProtocol\n" "socket.server: false\n" ); } diff --git a/Socket/SocketPolicy.hh b/Socket/SocketPolicy.hh index 3509acc..bc7ffc7 100644 --- a/Socket/SocketPolicy.hh +++ b/Socket/SocketPolicy.hh @@ -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 SocketPolicy - BufferingPolicyBase WritePolicyBase ReadPolicyBase CommunicationPolicyBase @@ -71,9 +67,6 @@
writePolicy
configures the writability of the socket
-
bufferingPolicy
configures, if and how buffering is configured for a - socket
- 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 framingPolicy @@ -112,7 +105,7 @@ 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, @@ -128,8 +121,7 @@ // StreamFramingPolicy, // ConnectedCommunicationPolicy, // ReadablePolicy, - // WritablePolicy, - // SocketBufferingPolicy>::policy + // WritablePolicy>::policy senf::TCPv4ClientSocketHandle tcpHandle (...); MyReadableHandle myHandle (tcpHandle); // Conversion to more basic socket handle @@ -144,7 +136,7 @@ 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 @@ -176,7 +168,7 @@ derives from SocketPolicyBase. This is simpler than checking the template directly).
\c template \c SocketPolicy < \e addressingPolicy, \e framingPolicy, \e communicationPolicy, - \e readPolicy, \e writePolicy, \e bufferingPolicy >
This is the central SocketPolicy + \e readPolicy, \e writePolicy >
This is the central SocketPolicy template. It combines a complete set of policy classes, one for each axis.
\c template \c MakeSocketPolicy < \e args >
\c MakeSocketPolicy is a template @@ -197,10 +189,10 @@ \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): // diff --git a/Socket/SocketPolicy.test.cc b/Socket/SocketPolicy.test.cc index 78f9297..0a99bdf 100644 --- a/Socket/SocketPolicy.test.cc +++ b/Socket/SocketPolicy.test.cc @@ -56,8 +56,6 @@ namespace { struct WritablePolicy : public WritePolicyBase {}; struct UnwritablePolicy : public WritePolicyBase {}; - struct SocketBufferingPolicy : public BufferingPolicyBase {}; - template 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 )); @@ -109,8 +106,7 @@ BOOST_AUTO_UNIT_TEST(socketPolicy) UnspecifiedFramingPolicy, UnspecifiedCommunicationPolicy, ReadablePolicy, - UnspecifiedWritePolicy, - UnspecifiedBufferingPolicy> Policy4; + UnspecifiedWritePolicy> Policy4; BOOST_MPL_ASSERT(( boost::is_same )); BOOST_MPL_ASSERT_NOT(( boost::is_same )); diff --git a/Socket/SocketPolicy.test.hh b/Socket/SocketPolicy.test.hh index cc726f6..4740f6e 100644 --- a/Socket/SocketPolicy.test.hh +++ b/Socket/SocketPolicy.test.hh @@ -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; }} diff --git a/Socket/SocketProtocol.cti b/Socket/SocketProtocol.cti index 45fc549..1c16b75 100644 --- a/Socket/SocketProtocol.cti +++ b/Socket/SocketProtocol.cti @@ -27,6 +27,7 @@ //#include "SocketProtocol.ih" // Custom includes +#include "SocketHandle.hh" #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// @@ -46,6 +47,25 @@ senf::ConcreteSocketProtocol::policy() return policy_; } +//////////////////////////////////////// +// protected members + +template +prefix_ senf::ClientSocketHandle +senf::ConcreteSocketProtocol::clientHandle() + const +{ + return static_socket_cast< ClientSocketHandle >(fh()); +} + +template +prefix_ senf::ServerSocketHandle +senf::ConcreteSocketProtocol::serverHandle() + const +{ + return static_socket_cast< ServerSocketHandle >(fh()); +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/SocketProtocol.hh b/Socket/SocketProtocol.hh index e05beac..fa8d0ff 100644 --- a/Socket/SocketProtocol.hh +++ b/Socket/SocketProtocol.hh @@ -39,17 +39,17 @@ \htmlonly - SocketPolicy - ConcreteSocketProtocol - SocketProtocol - BSDSocketProtocol - AddressableBSDSocketProtocol - IPv4Protocol - IPv6Protocol - TCPProtocol - TCPv4SocketProtocol - TCPv6SocketProtocol - PacketProtocol + SocketPolicy + ConcreteSocketProtocol + SocketProtocol + BSDSocketProtocol + AddressableBSDSocketProtocol + IPv4Protocol + IPv6Protocol + TCPProtocol + TCPv4SocketProtocol + TCPv6SocketProtocol + PacketProtocol 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 \<\< operator will add add a comma as separator. */ @@ -266,8 +266,10 @@ namespace senf { SocketBody * body_; friend class SocketBody; - }; - + }; + + template class ClientSocketHandle; + template class ServerSocketHandle; /** \brief Concrete Socket Protocol implementation base class @@ -312,6 +314,14 @@ namespace senf { Policy const & policy() const; protected: + ClientSocketHandle clientHandle() const; + ///< Get client handle for associated socket + /**< Returns a client handle for the socket associated with + this protocol instance */ + ServerSocketHandle serverHandle() const; + ///< Get server handle for associated socket + /**< Returns a server handle for the socket associated with + this protocol instance */ private: Policy policy_; diff --git a/doclib/Doxyfile.global b/doclib/Doxyfile.global index cbf545f..8b6455f 100644 --- a/doclib/Doxyfile.global +++ b/doclib/Doxyfile.global @@ -47,9 +47,9 @@ PREDEFINED = \ "SENF_PARSER_LABEL(x)=" \ "SENF_PARSER_INIT()=void init()" \ "SENF_PARSER_FINALIZE(name)=" \ - "ParseField_unsigned(b)=Parse_UIntField" \ - "ParseField_signed(b)=Parse_IntField" \ - "ParseField_bool(b)=Parse_Flag" \ + "ParseField_unsigned(b)=UIntFieldParser" \ + "ParseField_signed(b)=IntFieldParser" \ + "ParseField_bool(b)=FlagParser" \ "SENF_PARSER_ARRAY(name,elt_type,size)=senf::Parse_Array name() const" \ "SENF_PARSER_LIST_B(name,elt_type,size_type)=senf::Parse_ListB::parser name() const" \ "SENF_PARSER_LIST_N(name,elt_type,size_type)=senf::Parse_ListN::parser name() const" \