Merged revisions 570-575,577-578 via svnmerge from
g0dil [Tue, 18 Dec 2007 13:42:38 +0000 (13:42 +0000)]
https://svn.berlios.de/svnroot/repos/senf/branches/socket-cleanup

........
  r573 | g0dil | 2007-12-18 12:15:23 +0100 (Tue, 18 Dec 2007) | 6 lines

  Socket: Replace 'SocketProtocol::body()' member with 'fh()' and 'fd()' members
  Socket: Rename ConvertibleString to StreamableString and use 'operator<<' instead of 'operator='
  Socket: some minor documentation clarifications
  Socket/Protocols/UN: Removed unneeded UNAddress
  Socket/Protocols/UN: Fixed UNSocketAddress to adhere to the GenericAddressingPolicy requirements
........
  r577 | g0dil | 2007-12-18 13:08:27 +0100 (Tue, 18 Dec 2007) | 1 line

  Socket/Protocols/UN: Add all_includes.hh to svn:ignore
........

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

40 files changed:
Socket/FileHandle.cci
Socket/FileHandle.hh
Socket/FileHandle.ih
Socket/Protocols/BSDSocketProtocol.cc
Socket/Protocols/DVB/DVBDemuxHandles.cc
Socket/Protocols/DVB/DVBDemuxProtocol.cc
Socket/Protocols/DVB/DVBFrontendHandle.cc
Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc
Socket/Protocols/INet/ConnectedUDPSocketHandle.cc
Socket/Protocols/INet/INetAddressing.hh
Socket/Protocols/INet/INetProtocol.cc
Socket/Protocols/INet/RawInetProtocol.cc
Socket/Protocols/INet/RawInetSocketHandle.cc
Socket/Protocols/INet/TCPProtocol.cc
Socket/Protocols/INet/TCPSocketHandle.cc
Socket/Protocols/INet/TCPSocketHandle.hh
Socket/Protocols/INet/UDPProtocol.cc
Socket/Protocols/INet/UDPSocketHandle.cc
Socket/Protocols/Raw/PacketSocketHandle.cc
Socket/Protocols/Raw/TunTapSocketHandle.cc
Socket/Protocols/UN/UNAddress.cc [deleted file]
Socket/Protocols/UN/UNAddress.hh [deleted file]
Socket/Protocols/UN/UNAddress.test.cc [deleted file]
Socket/Protocols/UN/UNAddressing.cc
Socket/Protocols/UN/UNAddressing.hh
Socket/Protocols/UN/UNDatagramSocketHandle.cc
Socket/Protocols/UN/UNDatagramSocketHandle.hh
Socket/Protocols/UN/UNProtocol.cc
Socket/Protocols/UN/all_includes.hh [deleted file]
Socket/SocketHandle.cc
Socket/SocketHandle.cci
Socket/SocketHandle.ct
Socket/SocketHandle.cti
Socket/SocketHandle.hh
Socket/SocketHandle.ih
Socket/SocketPolicy.ct
Socket/SocketPolicy.hh
Socket/SocketProtocol.cci
Socket/SocketProtocol.cti
Socket/SocketProtocol.hh

index 62b9304..62cbfaf 100644 (file)
@@ -67,6 +67,11 @@ prefix_ void senf::FileBody::terminate()
     }
 }
 
+prefix_ senf::FileHandle senf::FileBody::handle()
+{
+    return FileHandle(ptr(this));
+}
+
 prefix_ int senf::FileBody::fd()
     const
 {
@@ -194,6 +199,10 @@ prefix_  senf::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
     : body_(body.release())
 {}
 
+prefix_ senf::FileHandle::FileHandle(FileBody::ptr body)
+    : body_(body)
+{}
+
 prefix_ senf::FileBody & senf::FileHandle::body()
 {
     BOOST_ASSERT(body_);
index 0091552..8afbd48 100644 (file)
@@ -182,6 +182,8 @@ namespace senf {
                                        \c new. To configure the FileHandle behavior, A derived class
                                        may provide any class derived from FileBody here. */
 
+        explicit FileHandle(FileBody::ptr body);
+
         FileBody & body();          ///< Access body
         FileBody const & body() const; ///< Access body in const context
         static FileBody & body(FileHandle & handle); ///< Access body of another FileHandle instance
@@ -192,6 +194,8 @@ namespace senf {
 
     private:
         FileBody::ptr body_;
+
+        friend class FileBody;
     };
 
     /** \brief Adapt FileHandle to senf::Scheduler
index bd5b1c7..02c6b71 100644 (file)
@@ -36,6 +36,7 @@
 
 namespace senf {
 
+    class FileHandle;
 
     /** \brief FileHandle referenced body
 
@@ -90,6 +91,8 @@ namespace senf {
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
+        FileHandle handle();
+
         int fd() const;
         void fd(int fd);
 
index 56fd6a4..543f119 100644 (file)
@@ -42,7 +42,7 @@ prefix_ std::pair<bool,unsigned> senf::BSDSocketProtocol::linger()
     struct linger ling;
     socklen_t len = sizeof(ling);
     ::memset(&ling,sizeof(ling),0);
-    if (::getsockopt(body().fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
+    if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
         throwErrno();
     return std::make_pair(ling.l_onoff, ling.l_linger);
 }
@@ -53,7 +53,7 @@ prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
     struct linger ling;
     ling.l_onoff = enable;
     ling.l_linger = timeout;
-    if (::setsockopt(body().fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
+    if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
         throwErrno();
 }
 
@@ -61,7 +61,7 @@ prefix_ struct timeval senf::BSDSocketProtocol::timestamp()
     const
 {
     struct timeval tv;
-    if (::ioctl(body().fd(), SIOCGSTAMP, &tv) < 0)
+    if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
         throwErrno();
     return tv;
 }
@@ -73,7 +73,7 @@ prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
 {
     int value;
     socklen_t len (sizeof(value));
-    if (::getsockopt(body().fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
+    if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
         throwErrno();
     return value;
 }
@@ -82,7 +82,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
     const
 {
     int ivalue (value);
-    if (::setsockopt(body().fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
+    if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
         throwErrno();
 }
 
index c24a40f..3d473ec 100644 (file)
@@ -45,10 +45,10 @@ prefix_ void senf::DVBDemuxSectionProtocol::init_client(unsigned short adapter,
 {
     std::string devDemux = str( boost::format(
             "/dev/dvb/adapter%d/demux%d") % adapter % device);
-    int fd = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
-    if (fd < 0)
+    int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
+    if (f < 0)
         throwErrno();
-    body().fd(fd);
+    fd(f);
 }
 
 prefix_ unsigned senf::DVBDemuxSectionProtocol::available()
@@ -66,7 +66,7 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDemuxSectionProtocol::clone
 prefix_ void senf::DVBDemuxSectionProtocol::setSectionFilter(struct dmx_sct_filter_params *filter)
     const
 {
-    if (::ioctl(body().fd(), DMX_SET_FILTER, filter) < 0)
+    if (::ioctl(fd(), DMX_SET_FILTER, filter) < 0)
         throwErrno();
 }
 
@@ -77,10 +77,10 @@ prefix_ void senf::DVBDemuxPESProtocol::init_client(unsigned short adapter, unsi
 {
     std::string devDemux = str( boost::format(
             "/dev/dvb/adapter%d/demux%d") % adapter % device);
-    int fd = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
-    if (fd < 0)
+    int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
+    if (f < 0)
         throwErrno();
-    body().fd(fd);
+    fd(f);
 }
 
 prefix_ unsigned senf::DVBDemuxPESProtocol::available()
@@ -98,7 +98,7 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDemuxPESProtocol::clone()
 prefix_ void senf::DVBDemuxPESProtocol::setPESFilter(struct dmx_pes_filter_params *filter)
     const
 {
-    if (::ioctl(body().fd(), DMX_SET_PES_FILTER, filter) < 0)
+    if (::ioctl(fd(), DMX_SET_PES_FILTER, filter) < 0)
         throwErrno();
 }
 
@@ -109,10 +109,10 @@ prefix_ void senf::DVBDvrProtocol::init_client(unsigned short adapter, unsigned
 {
     std::string devDvr = str( boost::format(
             "/dev/dvb/adapter%d/dvr%d") % adapter % device);
-    int fd = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
-    if (fd < 0)
+    int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
+    if (f < 0)
         throwErrno();
-    body().fd(fd);
+    fd(f);
 }
 
 prefix_ unsigned senf::DVBDvrProtocol::available()
index 1a2c70e..21745b8 100644 (file)
 prefix_ void senf::DVBDemuxProtocol::setBufferSize(unsigned long size)
     const
 {
-    if (::ioctl(body().fd(), DMX_SET_BUFFER_SIZE, size) < 0)
+    if (::ioctl(fd(), DMX_SET_BUFFER_SIZE, size) < 0)
         throwErrno();
 }
 
 prefix_ void senf::DVBDemuxProtocol::startFiltering()
     const
 {
-    if (::ioctl(body().fd(), DMX_START) < 0)
+    if (::ioctl(fd(), DMX_START) < 0)
         throwErrno();
 }
 
 prefix_ void senf::DVBDemuxProtocol::stopFiltering()
     const
 {
-    if (::ioctl(body().fd(), DMX_STOP) < 0)
+    if (::ioctl(fd(), DMX_STOP) < 0)
         throwErrno();
 }
 
index 7b121eb..43dcd1c 100644 (file)
@@ -45,10 +45,10 @@ prefix_ void senf::DVBFrontendProtocol::init_client(uint8_t adapter, boost::uint
 {
     std::string devFrontend = str( boost::format(
             "/dev/dvb/adapter%d/frontend%d") % adapter % device);
-    int fd = open(devFrontend.c_str(), O_RDONLY | O_NONBLOCK);
-    if (fd < 0)
+    int f = open(devFrontend.c_str(), O_RDONLY | O_NONBLOCK);
+    if (f < 0)
         throwErrno();
-    body().fd(fd);
+    fd(f);
 }
 
 prefix_ unsigned senf::DVBFrontendProtocol::available()
@@ -73,7 +73,7 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBFrontendProtocol::clone()
 prefix_ void senf::DVBFrontendProtocol::signalStrength(int16_t *strength)
     const
 {
-    if (::ioctl(body().fd(), FE_READ_SIGNAL_STRENGTH, strength) < 0)
+    if (::ioctl(fd(), FE_READ_SIGNAL_STRENGTH, strength) < 0)
         throwErrno();
 }
 
index 3963ccd..79f00cd 100644 (file)
@@ -47,7 +47,7 @@ senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol)
     int sock = ::socket(PF_INET, SOCK_RAW, protocol);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -79,7 +79,7 @@ prefix_ void senf::ConnectedRawV6SocketProtocol::init_client(int const & protoco
     int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -98,3 +98,15 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::ConnectedRawV6SocketProtocol::
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
+//#include "ConnectedRawInetSocketHandle.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
index ef74194..84b665c 100644 (file)
@@ -47,7 +47,7 @@ prefix_ void senf::ConnectedUDPv4SocketProtocol::init_client()
     int sock = ::socket(PF_INET,SOCK_DGRAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -73,7 +73,7 @@ prefix_ void senf::ConnectedUDPv6SocketProtocol::init_client()
     int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
index 9fd1281..e1095fd 100644 (file)
@@ -83,7 +83,7 @@ namespace senf {
         INet4Address address() const;   ///< Return address
         unsigned port() const;          ///< Return port number
 
-        bool boolean_test() const;      ///< \c true, if address is empty (i.e. 0.0.0.0:0)
+        bool boolean_test() const;      ///< \c true, if address is not empty (i.e. 0.0.0.0:0)
 
         void clear();                   ///< Clear address/port to 0.0.0.0:0
 
index 477e9ac..6ddc307 100644 (file)
 prefix_ void senf::IPv4Protocol::connect(INet4SocketAddress const & address)
     const
 {
-    if (::connect(body().fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
+    if (::connect(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
         throwErrno();
 }
 
 prefix_ void senf::IPv4Protocol::bind(INet4SocketAddress const & address)
     const
 {
-    if (::bind(body().fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
+    if (::bind(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
         throwErrno();
 }
 
@@ -59,14 +59,14 @@ prefix_ void senf::IPv4Protocol::bind(INet4SocketAddress const & address)
 prefix_ void senf::IPv6Protocol::connect(INet6SocketAddress const & address)
     const
 {
-    if (::connect(body().fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
+    if (::connect(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
         throwErrno();
 }
 
 prefix_ void senf::IPv6Protocol::bind(INet6SocketAddress const & address)
     const
 {
-    if (::bind(body().fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
+    if (::bind(fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
         throwErrno();
 }
 
index 1603bf4..80fe9f7 100644 (file)
@@ -37,7 +37,7 @@ prefix_ unsigned senf::RawInetProtocol::available()
     const
 {
     int n;
-    if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
+    if (::ioctl(fd(),SIOCINQ,&n) < 0)
         throwErrno();
     return n;
 }
@@ -47,4 +47,18 @@ prefix_ bool senf::RawInetProtocol::eof()
 {
     return false;
 }
+
+///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
+//#include "UDPProtocol.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
index 720a785..c623ed7 100644 (file)
@@ -47,7 +47,7 @@ senf::RawV4SocketProtocol::init_client(int const & protocol)
     int sock = ::socket(PF_INET, SOCK_RAW, protocol);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -79,7 +79,7 @@ prefix_ void senf::RawV6SocketProtocol::init_client(int const & protocol)
     int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -98,3 +98,15 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV6SocketProtocol::clone()
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
+//#include "RawInetSocketHandle.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
index 79646be..c1431e4 100644 (file)
@@ -44,7 +44,7 @@ prefix_ bool senf::TCPProtocol::nodelay()
 {
     int value;
     socklen_t len (sizeof(value));
-    if (::getsockopt(body().fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
+    if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
         throwErrno();
     return value;
 }
@@ -53,7 +53,7 @@ prefix_ void senf::TCPProtocol::nodelay(bool value)
     const
 {
     int ivalue (value);
-    if (::setsockopt(body().fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
+    if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
         throwErrno();
 }
 
@@ -61,7 +61,7 @@ prefix_ unsigned senf::TCPProtocol::siocinq()
     const
 {
     int n;
-    if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
+    if (::ioctl(fd(),SIOCINQ,&n) < 0)
         throwErrno();
     return n;
 }
@@ -70,7 +70,7 @@ prefix_ unsigned senf::TCPProtocol::siocoutq()
     const
 {
     int n;
-    if (::ioctl(body().fd(),SIOCOUTQ,&n) < 0)
+    if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
         throwErrno();
     return n;
 }
@@ -84,7 +84,7 @@ prefix_ unsigned senf::TCPProtocol::available()
 prefix_ bool senf::TCPProtocol::eof()
     const
 {
-    return body().readable() && available()==0;
+    return fh().readable() && available()==0;
 }
 
 
index 0825295..ccc9b78 100644 (file)
@@ -47,7 +47,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_client()
     int sock = ::socket(PF_INET,SOCK_STREAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -64,7 +64,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server()
     int sock = ::socket(PF_INET,SOCK_STREAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & address,
@@ -74,7 +74,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & a
     init_server();
     bind(address);
     reuseaddr(true);
-    if (::listen(body().fd(),backlog) < 0)
+    if (::listen(fd(),backlog) < 0)
         throwErrno();
 }
 
@@ -93,7 +93,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_client()
     int sock = ::socket(PF_INET6,SOCK_STREAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -110,7 +110,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server()
     int sock = ::socket(PF_INET6,SOCK_STREAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & address,
@@ -120,7 +120,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & a
     init_server();
     bind(address);
     reuseaddr(true);
-    if (::listen(body().fd(),backlog) < 0)
+    if (::listen(fd(),backlog) < 0)
         throwErrno();
 }
 
index b6ffa81..5e11cdd 100644 (file)
@@ -62,16 +62,16 @@ namespace senf {
     /** \brief IPv4 TCP Socket Protocol
 
         \par Socket Handle typedefs:
-        \ref TCPv4ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv4ServerSocketHandle
-        (ProtocolServerSocketHandle)
-
+            \ref TCPv4ClientSocketHandle (ProtocolClientSocketHandle), \ref TCPv4ServerSocketHandle
+            (ProtocolServerSocketHandle)
+        
         \par Policy Interface:
-        ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
-        ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
-        ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
+            ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
+            ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
+            ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
 
         \par Address Type:
-        INet4Address
+            INet4Address
 
         TCPv4SocketProtocol provides an internet protocol stream socket based on the TCP protocol
         and IPv4 addressing.
index 22f1ac5..fa3c5e7 100644 (file)
@@ -44,7 +44,7 @@ prefix_ unsigned senf::UDPProtocol::available()
     const
 {
     int n;
-    if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
+    if (::ioctl(fd(),SIOCINQ,&n) < 0)
         throwErrno();
     return n;
 }
@@ -60,7 +60,7 @@ prefix_ bool senf::UDPProtocol::mcLoop()
 {
     int value;
     socklen_t len (sizeof(value));
-    if (::getsockopt(body().fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
+    if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
         throwErrno();
     return value;
 }
@@ -69,7 +69,7 @@ prefix_ void senf::UDPProtocol::mcLoop(bool value)
     const
 {
     int ivalue (value);
-    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
         throwErrno();
 }
 
@@ -80,7 +80,7 @@ prefix_ void senf::UDPProtocol::mcAddMembership(INet4SocketAddress const & mcAdd
     mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
     mreqn.imr_address.s_addr = htons(INADDR_ANY);
     mreqn.imr_ifindex = 0;
-    if (::setsockopt(body().fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
         throwErrno();
 }
 
@@ -92,7 +92,7 @@ prefix_ void senf::UDPProtocol::mcAddMembership(INet4SocketAddress const & mcAdd
     mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
     mreqn.imr_address = reinterpret_cast<struct sockaddr_in const *>(localAddr.sockaddr_p())->sin_addr;
     mreqn.imr_ifindex = 0;
-    if (::setsockopt(body().fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_ADD_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
         throwErrno();
 }
 
@@ -103,7 +103,7 @@ prefix_ void senf::UDPProtocol::mcDropMembership(INet4SocketAddress const & mcAd
     mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
     mreqn.imr_address.s_addr = htons(INADDR_ANY);
     mreqn.imr_ifindex = 0;
-    if (::setsockopt(body().fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
         throwErrno();
 }
 
@@ -115,7 +115,7 @@ prefix_ void senf::UDPProtocol::mcDropMembership(INet4SocketAddress const & mcAd
     mreqn.imr_multiaddr = reinterpret_cast<struct sockaddr_in const *>(mcAddr.sockaddr_p())->sin_addr;
     mreqn.imr_address = reinterpret_cast<struct sockaddr_in const *>(localAddr.sockaddr_p())->sin_addr;
     mreqn.imr_ifindex = 0;
-    if (::setsockopt(body().fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
         throwErrno();
 }
 
@@ -129,7 +129,7 @@ prefix_ void senf::UDPProtocol::mcIface(std::string const & iface)
         if (mreqn.imr_ifindex == 0)
             throwErrno(EINVAL);
     }
-    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
         throwErrno();
 }
 
@@ -138,7 +138,7 @@ prefix_ unsigned senf::UDPProtocol::mcTTL()
 {
     int value;
     socklen_t len (sizeof(value));
-    if (::getsockopt(body().fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
+    if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
         throwErrno();
     return value;
 }
@@ -146,7 +146,7 @@ prefix_ unsigned senf::UDPProtocol::mcTTL()
 prefix_ void senf::UDPProtocol::mcTTL(unsigned value)
     const
 {
-    if (::setsockopt(body().fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
+    if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
         throwErrno();
 }
 
index 3d7f3d2..9079f81 100644 (file)
@@ -47,7 +47,7 @@ prefix_ void senf::UDPv4SocketProtocol::init_client()
     int sock = ::socket(PF_INET,SOCK_DGRAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
@@ -73,7 +73,7 @@ prefix_ void senf::UDPv6SocketProtocol::init_client()
     int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void
index ca9a07a..d0f8e5a 100644 (file)
@@ -51,7 +51,7 @@ prefix_ void senf::PacketProtocol::init_client(SocketType type, int protocol)
     int sock = ::socket(PF_PACKET, socktype, htons(protocol));
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::PacketProtocol::clone()
@@ -63,9 +63,9 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::PacketProtocol::clone()
 prefix_ unsigned senf::PacketProtocol::available()
     const
 {
-    if (! body().readable())
+    if (! fh().readable())
         return 0;
-    ssize_t l = ::recv(body().fd(),0,0,MSG_PEEK | MSG_TRUNC);
+    ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC);
     if (l < 0)
         throwErrno();
     return l;
@@ -100,14 +100,14 @@ prefix_ void senf::PacketProtocol::mcAdd(std::string const & interface,
                                          MACAddress const & address)
     const
 {
-    do_mc(body().fd(),interface,address,true);
+    do_mc(fd(),interface,address,true);
 }
 
 prefix_ void senf::PacketProtocol::mcDrop(std::string const & interface,
                                           MACAddress const & address)
     const
 {
-    do_mc(body().fd(),interface,address,false);
+    do_mc(fd(),interface,address,false);
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
index 81ef80d..80d72bc 100644 (file)
@@ -48,8 +48,8 @@ prefix_ void senf::TapProtocol::init_client()
 prefix_ void senf::TapProtocol::init_client(std::string const & interface_name, bool const NO_PI) 
     const
 {
-    int fd;
-    if ( (fd = ::open("/dev/net/tun", O_RDWR)) < 0 )
+    int f;
+    if ( (f = ::open("/dev/net/tun", O_RDWR)) < 0 )
         throwErrno();
     struct ifreq ifr;
     ::memset( &ifr, 0, sizeof(ifr));
@@ -57,9 +57,9 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name,
     if (NO_PI)
         ifr.ifr_flags |= IFF_NO_PI;
     interface_name.copy( ifr.ifr_name, IFNAMSIZ);
-    if (::ioctl(fd, TUNSETIFF, (void *) &ifr) < 0 )
+    if (::ioctl(f, TUNSETIFF, (void *) &ifr) < 0 )
         throwErrno();
-    body().fd(fd);
+    fd(f);
 }
 
 prefix_ std::auto_ptr<senf::SocketProtocol> senf::TapProtocol::clone()
@@ -71,9 +71,9 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::TapProtocol::clone()
 prefix_ unsigned senf::TapProtocol::available()
   const
 {
-  if (! body().readable())
+  if (! fh().readable())
       return 0;
-  ssize_t l = ::recv(body().fd(),0,0,MSG_PEEK | MSG_TRUNC);
+  ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC);
   if (l < 0)
       //throwErrno();
       return 1588;
diff --git a/Socket/Protocols/UN/UNAddress.cc b/Socket/Protocols/UN/UNAddress.cc
deleted file mode 100644 (file)
index feb9570..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum NETwork research (NET)
-//     David Wagner <david.wagner@fokus.fraunhofer.de>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/** \file
-    \brief UNAddress non-inline non-template implementation */
-
-#include "UNAddress.hh"
-//#include "UNAddress.ih"
-
-// Custom includes
-
-//#include "UNAddress.mpp"
-#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
-
-prefix_ senf::UNAddress::UNAddress()
-    //:path("")
-{
-    path = "";
-}
-
-prefix_ senf::UNAddress::UNAddress(std::string p)
-{
-    path = p; 
-}
-
-
-prefix_ senf::UNAddress::UNAddress senf::UNAddress::fromString(std::string &  s)
-{
-    return senf::UNAddress::UNAddress(s);
-}
-
-
-prefix_  std::string senf::UNAddress::pathString()
-    const
-{
-    return  path;
-}
-
-prefix_ senf::UNAddress::UNAddress senf::UNAddress::clone()
-{
-    senf::UNAddress::UNAddress local_addr = senf::UNAddress::UNAddress(pathString());
-    return  local_addr;
-}
-
-prefix_ std::ostream & senf::operator<<(std::ostream & os, UNAddress const & addr)
-{
-    os << addr.pathString();
-    return os;
-}
-
-///////////////////////////////cc.e////////////////////////////////////////
-#undef prefix_
-//#include "UNAddress.mpp"
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// comment-column: 40
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// End:
diff --git a/Socket/Protocols/UN/UNAddress.hh b/Socket/Protocols/UN/UNAddress.hh
deleted file mode 100644 (file)
index 1dfdeea..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum NETwork research (NET)
-//     David Wagner <david.wagner@fokus.fraunhofer.de>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/** \file
-    \brief UNAddress public header */
-
-#ifndef HH_UNAddress_
-#define HH_UNAddress_ 1
-
-// Custom includes
-#include <string>
-#include <boost/operators.hpp>
-#include "../../../Utils/safe_bool.hh"
-
-//#include "UNAddress.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
-namespace senf {
-    /** \brief Unix domain address
-        
-        UNAddress represents a simple unix domain address which is given by a path to a socket. 
-        It is modelled as a boost::filesystem::path.
-
-        \ingroup addr_group
-      */
-    class UNAddress 
-        : public comparable_safe_bool<UNAddress>
-    {   
-    public: 
-        UNAddress(); ///< Construct an empty address
-        explicit UNAddress(std::string);///< Construct an address constant from given path
-        static UNAddress fromString(std::string & s); ///< Convert string to address by interpreting the string as path
-        UNAddress clone(); ///< Clone object 
-        std::string pathString() const; ///< Return the path of the address as string
-
-        /** \brief Base-class for UNAddress exceptions */
-        struct AddressException : public std::exception {}; 
-
-    private:
-        std::string path;
-    };
-
-std::ostream & operator<<(std::ostream & os, UNAddress const & addr);
-}
-
-///////////////////////////////hh.e////////////////////////////////////////
-//#include "UNAddress.cci"
-//#include "UNAddress.ct"
-//#include "UNAddress.cti"
-#endif
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// comment-column: 40
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// End:
diff --git a/Socket/Protocols/UN/UNAddress.test.cc b/Socket/Protocols/UN/UNAddress.test.cc
deleted file mode 100644 (file)
index d21e706..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum NETwork research (NET)
-//     David Wagner <david.wagner@fokus.fraunhofer.de>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/** \file
-    \brief UNAddress.test unit tests */
-
-//#include "UNAddress.test.hh"
-//#include "UNAddress.test.ih"
-
-// Custom includes
-#include "UNAddress.hh"
-#include <boost/filesystem/path.hpp>
-#include "../../../Utils/auto_unit_test.hh"
-#include <boost/test/test_tools.hpp>
-
-#include <iostream>
-#define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
-
-BOOST_AUTO_UNIT_TEST(unAddress)
-{
-//    TODO: muss wieder rein. 
-//    std::string testS = "/tmp/senfTestSocket";
-//    boost::filesystem::path testp = boost::filesystem::path(testS); 
-//    senf::UNAddress addr1 = senf::UNAddress::fromString(testS);
-//    senf::UNAddress addr2 = senf::UNAddress::fromPath(testp);
-//    BOOST_CHECK( testS == addr1.pathString());
-//    BOOST_CHECK( testS == addr2.pathString());
-}
-
-///////////////////////////////cc.e////////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// comment-column: 40
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// End:
index 9a98b10..4af13c0 100644 (file)
 
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
+
+prefix_ senf::UNSocketAddress::UNSocketAddress()
+{}
+
 prefix_ senf::UNSocketAddress::UNSocketAddress(std::string p)
 {
-       sockAddr.sun_family = AF_UNIX;
-       strcpy(sockAddr.sun_path, p.c_str());
+    clear();
+    ::strncpy(addr_.sun_path, p.c_str(), sizeof(addr_.sun_path));
+    addr_.sun_path[sizeof(addr_.sun_path)-1] = 0;
 }
 
-prefix_ senf::UNSocketAddress fromString(std::string s) {
+prefix_ senf::UNSocketAddress fromString(std::string s) 
+{
     return senf::UNSocketAddress::UNSocketAddress(s);
 }
 
+prefix_ bool senf::UNSocketAddress::operator==(UNSocketAddress const & other)
+    const
+{
+    return path() == other.path();
+}
 
 prefix_ std::string senf::UNSocketAddress::path()
         const
 {
-    return std::string(sockAddr.sun_path);
+    return std::string(addr_.sun_path);
 }
 
-prefix_ sockaddr_un senf::UNSocketAddress::sockaddr()
+prefix_ bool senf::UNSocketAddress::boolean_test()
+    const
 {
-    struct sockaddr_un out; 
-    out.sun_family = sockAddr.sun_family;
-    strncpy(out.sun_path, sockAddr.sun_path, sizeof( out.sun_path));
-    return out; 
+    return addr_.sun_path[0] != 0;
 }
 
-prefix_ sockaddr * senf::UNSocketAddress::sockaddr_p()
+prefix_ void senf::UNSocketAddress::clear()
 {
-    return reinterpret_cast <struct sockaddr  *> (&sockAddr); 
+    ::memset(&addr_, 0, sizeof(addr_));
+    addr_.sun_family = AF_UNIX;
 }
 
+prefix_ sockaddr * senf::UNSocketAddress::sockaddr_p()
+{
+    return reinterpret_cast <struct sockaddr  *> (&addr_); 
+}
 
 prefix_ sockaddr const  * senf::UNSocketAddress::sockaddr_p()
     const
 {
-    return reinterpret_cast <struct sockaddr const  *> (&sockAddr); 
+    return reinterpret_cast <struct sockaddr const  *> (&addr_); 
 }
 
 prefix_ unsigned senf::UNSocketAddress::sockaddr_len()
        const
 {
-    return sizeof(sockAddr);
+    return sizeof(addr_);
 }
 
-prefix_ std::ostream & operator<<(std::ostream & os, senf::UNSocketAddress::UNSocketAddress const & addr){
+prefix_ std::ostream & operator<<(std::ostream & os,
+                                  senf::UNSocketAddress::UNSocketAddress const & addr)
+{
     os << addr.path();
     return os;
 }
 
-
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "UNAddressing.mpp"
index 837adb7..22e1671 100644 (file)
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/Protocols/GenericAddressingPolicy.hh"
 #include "../../../Utils/safe_bool.hh"
-#include "UNAddress.hh"
 
 //#include "UNAddressing.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
+
 namespace senf {
+
     /** \brief Unix domain socket address
 
         UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
@@ -49,26 +50,37 @@ namespace senf {
         \implementation This implementation is based on sockaddr_un.
 
         \ingroup addr_group
+
+        \fixme Why both std::string constructor and from_string member ?
      */
     class UNSocketAddress
         : public comparable_safe_bool<UNSocketAddress>
     {
     public:
-
-        //UNSocketAddress(); 
+        UNSocketAddress(); 
         explicit UNSocketAddress(std::string p);
                                         ///< Construct an address constant from given path
-        static UNSocketAddress from_string(std::string const s); ///< Create UNSocketAddress from string
-        std::string path() const ;  ///< Return path as string
-        struct sockaddr_un sockaddr(); 
+        static UNSocketAddress from_string(std::string const s); 
+                                        ///< Create UNSocketAddress from string
+
+        bool operator==(UNSocketAddress const & other) const;
+                                        ///< Compare UNSocketAddress for equality
+
+        std::string path() const ;      ///< Return path as string
+
+        bool boolean_test() const;      ///< \c true, if address is not empty
+        
+        void clear();                   ///< Clear address
+
         struct sockaddr * sockaddr_p() ;
         struct sockaddr const * sockaddr_p() const;
         unsigned sockaddr_len() const;
+
     private:
-        struct sockaddr_un sockAddr;
+        struct sockaddr_un addr_;
     };
 
-    /** \brief Write path  os
+    /** \brief Write path to os
 
         \related UNSocketAddress
      */
@@ -100,7 +112,10 @@ namespace senf {
         using GenericAddressingPolicy<UNSocketAddress>::connect;
         using GenericAddressingPolicy<UNSocketAddress>::bind;
     };
+
+    ///@}
 }
+
 ///////////////////////////////hh.e////////////////////////////////////////
 //#include "UNAddressing.cci"
 //#include "UNAddressing.ct"
index a91f49e..4d21aec 100644 (file)
@@ -40,7 +40,7 @@ prefix_ void senf::UNDatagramSocketProtocol::init_client() const
     int sock = ::socket(PF_UNIX,SOCK_DGRAM,0);
     if (sock < 0)
         throwErrno();
-    body().fd(sock);
+    fd(sock);
 }
 
 prefix_ void senf::UNDatagramSocketProtocol::init_client(UNSocketAddress const & address) const 
index 30e7b6b..606c43b 100644 (file)
@@ -64,11 +64,11 @@ namespace senf {
         \par Address Type:
             UNAddress
 
-        UNDatagramSocketProtocol provides an datagram protocol socket based on the unix domain  addressing.
-
-        This class is utilized as the protocol class of the ProtocolClientSocketHandle
-        via the Socket Handle typedefs above.
+        UNDatagramSocketProtocol provides an datagram protocol socket based on the unix domain
+        addressing.
 
+        This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
+        Socket Handle typedefs above.
     */
     class UNDatagramSocketProtocol
         : public ConcreteSocketProtocol<UNDatagramSocket_Policy>,
@@ -106,6 +106,8 @@ namespace senf {
 
     typedef ProtocolClientSocketHandle<UNDatagramSocketProtocol> UNDatagramClientSocketHandle;
 
+    ///@}
+
 }
 ///////////////////////////////hh.e////////////////////////////////////////
 //#include "UNDatagramSocketHandle.cci"
index 7e2f49e..c0bab25 100644 (file)
@@ -38,7 +38,7 @@ prefix_ unsigned senf::UNProtocol::available()
     const
 {
     int n;
-    if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
+    if (::ioctl(fd(),SIOCINQ,&n) < 0)
         throwErrno();
     return n;
 }
@@ -52,14 +52,14 @@ prefix_ bool senf::UNProtocol::eof()
 prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address) 
     const 
 {
-    if(::connect(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
+    if(::connect(fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
         throwErrno();
 }
 
 prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address) 
     const 
 {
-    if(::bind(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
+    if(::bind(fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
         throwErrno();
     
 }
@@ -85,27 +85,35 @@ prefix_ void senf::UNProtocol::terminate()
 prefix_ void senf::UNProtocol::check_and_unlink()
     const
 {
-//  struct sockaddr_un test;
-//  socklen_t len;
-//  memset( (char*)&test, 0xff, sizeof( test));
-//  int fd = inputSocket.fd() ;
-////    printf( "fd: %d\n", fd);
-//
-//  int r = getsockname( fd, (struct sockaddr *)&test, &len);
-//  if( r < 0){
-//    perror( "bla:");
-//  }
-//  else{
-//    printf( "name: %d %d %s\n", r, len , test.sun_path);
-//    unsigned char *p = (unsigned char*) &test;for( r=0; r< len; r++) printf( "%2.2x ", (int)(p[r])); printf ("\n");
-//  }
-    struct sockaddr_un test;
-    socklen_t len = sizeof( test);
-    int r = ::getsockname( body().fd(), (struct sockaddr *)&test, &len);
-    if( r == 0 && ::strlen(test.sun_path) > 0){
-      ::unlink( test.sun_path);
+    typedef ClientSocketHandle<MakeSocketPolicy<UNAddressingPolicy>::policy> UNSocketHandle;
+    try {
+        UNSocketAddress una (static_socket_cast<UNSocketHandle>(fh()).local());
+        ::unlink(una.path().c_str());
+    }
+    catch (SystemException & e) {
     }
 }
+    
+// //  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_
diff --git a/Socket/Protocols/UN/all_includes.hh b/Socket/Protocols/UN/all_includes.hh
deleted file mode 100644 (file)
index 16d8a1f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#include "UNAddress.hh"
-#include "UNAddressing.hh"
-#include "UNDatagramSocketHandle.hh"
-#include "UNProtocol.hh"
index 3878a36..64735f2 100644 (file)
@@ -54,11 +54,11 @@ prefix_ bool senf::SocketBody::v_eof()
 
 prefix_ void senf::SocketBody::state(SocketStateMap & map, unsigned lod)
 {
-    map["file.handle"] = fd();
-    map["file.refcount"] = refcount();
-    map["socket.server"] = isServer();
-    map["socket.protocol"] = prettyName(typeid(protocol()));
-    map["socket.policy"] = prettyName(typeid(protocol().policy()));
+    map["file.handle"]     << fd();
+    map["file.refcount"]   << refcount();
+    map["socket.server"]   << isServer();
+    map["socket.protocol"] << prettyName(typeid(protocol()));
+    map["socket.policy"]   << prettyName(typeid(protocol().policy()));
     protocol().state(map,lod);
 }
 
index a465f19..20d3a9d 100644 (file)
@@ -61,14 +61,12 @@ prefix_ bool senf::SocketBody::isServer()
 }
 
 ///////////////////////////////////////////////////////////////////////////
-// senf::detail::ConvertibleString
+// senf::detail::StreamableString
 
-prefix_ senf::detail::ConvertibleString::ConvertibleString()
-{}
-
-prefix_ senf::detail::ConvertibleString::ConvertibleString(bool v)
-    : std::string(v ? "true" : "false")
-{}
+prefix_ senf::detail::StreamableString & senf::detail::StreamableString::operator<<(bool v)
+{
+    return (*this) << std::string(v ? "true" : "false");
+}
 
 ///////////////////////////////cci.e///////////////////////////////////////
 #undef prefix_
index 96c5b13..56f9346 100644 (file)
 #define prefix_
 ///////////////////////////////ct.p////////////////////////////////////////
 
+///////////////////////////////////////////////////////////////////////////
+// senf::detail::StreamableString
+
 template <class T>
-prefix_ senf::detail::ConvertibleString &
-senf::detail::ConvertibleString::operator+=(ConvertibleString const & other)
+prefix_ senf::detail::StreamableString &
+senf::detail::StreamableString::operator<<(T const & other)
 {
     if (!empty())
-        this->std::string::operator+=(", ");
-    this->std::string::operator+=(other);
+        (*this) += ", ";
+    (*this) += boost::lexical_cast<std::string>(other);
     return *this;
 }
 
index aa618bc..604f456 100644 (file)
@@ -169,7 +169,7 @@ prefix_ void senf::SocketHandle<SocketPolicy>::state(SocketStateMap & map, unsig
     // automatically include the SocketPolicy template parameter in
     // the type name and therefore show the \e static policy of the
     // socket handle.
-    map["handle"] = prettyName(typeid(*this));
+    map["handle"] << prettyName(typeid(*this));
     body().state(map,lod);
 }
 
@@ -181,14 +181,6 @@ prefix_ std::string senf::SocketHandle<SocketPolicy>::dumpState(unsigned lod)
     return detail::dumpState(map);
 }
 
-///////////////////////////////////////////////////////////////////////////
-// senf::detail::ConvertibleString
-
-template <class T>
-prefix_ senf::detail::ConvertibleString::ConvertibleString(T const & other)
-    : std::string(boost::lexical_cast<std::string>(other))
-{}
-
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_
 
index 808b3c1..be6e23a 100644 (file)
@@ -126,8 +126,8 @@ namespace senf {
 
                                              \param map string to string mapping to be filled with
                                                  state information
-                                             \param lod level of detail requested. The interpretation
-                                                 of this value is protocol specific
+                                             \param lod level of detail requested. The
+                                                 interpretation of this value is protocol specific
 
                                              \implementation This member will be re-implemented in
                                                  every derived class. This is very important since
@@ -139,9 +139,9 @@ namespace senf {
                                         /**< Formats the complete state map value and returns it as
                                              a single multi-line string.
 
-                                             param lod  level of detail requested. The interpretation
-                                                of this value is protocol specific
-
+                                             \param lod level of detail requested. The
+                                                interpretation of this value is protocol specific
+                                             
                                              \implementation This member will be re-implemented in
                                                  every derived class. See the state()
                                                  documentation. */
@@ -169,8 +169,7 @@ namespace senf {
                                              \param isChecked has to be \c true
 
                                              \todo Answer, why the heck I need the \c isChecked
-                                                 parameter ??
-                                        */
+                                                 parameter ?? */
 
         SocketBody & body();            ///< Access socket body
                                         /**< This member replaces the corresponding FileHandle
index 5e9fae4..3e3663a 100644 (file)
@@ -44,8 +44,8 @@ namespace senf {
 
         /** \brief String supporting automatic type conversion
 
-            The ConvertibleString class is used to simplify creating a text representation of
-            arbitrary values. ConvertibleString is an ordinary string with an additional constructor
+            The StreamableString class is used to simplify creating a text representation of
+            arbitrary values. StreamableString is an ordinary string with an additional constructor
             which allows constructing the string from any arbitrary, streamable type.
 
             \note It is generally not advisable to derive from the standard library container
@@ -53,36 +53,30 @@ namespace senf {
             additional functionality is added. It is absolutely safe to convert the derived class
             back to the base type.
          */
-        class ConvertibleString : public std::string
+        class StreamableString : public std::string
         {
         public:
-            ConvertibleString();
-            ConvertibleString(bool v);  ///< Bool conversion constructor
-                                        /**< The bool conversion is defined explicitly to use a
-                                           specialized representation (the strings 'true' and
-                                           'false') */
-            template <class T>
-            ConvertibleString(T const & other);
-                                        ///< Conversion constructor
-                                        /**< This constructor will assign the string from any
-                                           arbitrary type. It will use boost::lexical_cast to
-                                           convert the argument to its string representation. */
+            using std::string::operator=;
 
             template <class T>
-            ConvertibleString & operator+= (ConvertibleString const & other);
-                                        ///< Add additional values with separator
-                                        /**< This operator facilitates the representation of
-                                           multiple values in a single string. Each value is first
-                                           converted to a string (using the type conversion
-                                           machinery of C++ and the ConvertibleString conversion
-                                           constructors). It is then appended to the current string
-                                           with ', ' as a separator (if the current string is
-                                           non-empty). */
+            StreamableString & operator<<(T const & other);
+                                        ///< Value assigment
+                                        /**< This operator will assign the string from any
+                                             arbitrary type. It will use boost::lexical_cast to
+                                             convert the argument to its string representation. 
+
+                                             If the string is non-empty, an additional separating
+                                             comma is added to the string. */
+
+            StreamableString & operator<<(bool v);  ///< Bool assignment
+                                        /**< The bool assignment is defined explicitly to use a
+                                             specialized representation (the strings 'true' and
+                                             'false'). */
         };
 
     }
 
-    typedef std::map< std::string, detail::ConvertibleString > SocketStateMap;
+    typedef std::map< std::string, detail::StreamableString > SocketStateMap;
 
     namespace detail {
         /** \brief Helper to convert SocketStateMap to multiline string representation
index 6a56e31..3488d53 100644 (file)
@@ -41,8 +41,13 @@ checkBaseOf(SocketPolicyBase const & other)
     // check, wether each policy of other is (dynamically!) convertible
     // to the corresponding (static) policy of this class. Throws
     // std::bad_cast on failure
-#   define SP_CheckPolicy(x1,x2,SomePolicy) (void) dynamic_cast<BOOST_PP_CAT(SomePolicy,_) const &>(other.BOOST_PP_CAT(the,SomePolicy)());
+
+#   define SP_CheckPolicy(x1,x2,SomePolicy)                                                       \
+        (void) dynamic_cast<BOOST_PP_CAT(SomePolicy,_) const &>(                                  \
+            other.BOOST_PP_CAT(the,SomePolicy)());
+
     BOOST_PP_SEQ_FOR_EACH( SP_CheckPolicy, , SENF_SOCKET_POLICIES )
+
 #   undef SP_CheckPolicy
 }
 
index e4cf253..859686e 100644 (file)
@@ -505,10 +505,15 @@ namespace senf {
     {
         /** \brief Check dynamic policy compatibility
 
-            This method will check the socket policy \a other against this policy. It will check,
-            whether \a other is a base policy (or the same) of this policy. This check is done
-            against the \e dynamic type of \a other using RTTI. It will throw \c std::bad_cast, if
-            the policy is not compatible.
+            This check will validate, that a socket with \a other as it's policy is convertible to a
+            socket with the current SocketPolicy as it's policy. This is true, if for each policy
+            axis, the policy class of that axis as defined in the \a other policy is convertible to
+            the policy class of that same axis in the current SocketPolicy instance (as is defined
+            by the template arguments). This again is true, if the \a other policy class is derived
+            from (or is the same as) the policy class taken from the current SocketPolicy instance.
+
+            In other words, this call checks, that the current SocketPolicy (as defined via the
+            template arguments) is more generic than the \a other socket policy.
 
             \param[in] other SocketPolicy to check
             \throws std::bad_cast if \a other is not a compatible policy
index 7ecf0b0..1a55451 100644 (file)
 #define prefix_ inline
 ///////////////////////////////cci.p///////////////////////////////////////
 
+///////////////////////////////////////////////////////////////////////////
+// senf::SocketProtocol
+
+prefix_ senf::FileHandle senf::SocketProtocol::fh()
+    const
+{
+    return body().handle();
+}
+
+prefix_ int senf::SocketProtocol::fd()
+    const
+{
+    return body().fd();
+}
+
+prefix_ void senf::SocketProtocol::fd(int fd)
+    const
+{
+    BOOST_ASSERT(! body().valid());
+    body().fd(fd);
+}
+
 prefix_ senf::SocketProtocol::SocketProtocol()
     : body_(0)
 {}
index df1c823..c474949 100644 (file)
@@ -31,6 +31,9 @@
 #define prefix_ inline
 ///////////////////////////////cti.p///////////////////////////////////////
 
+///////////////////////////////////////////////////////////////////////////
+// senf::ConcreteSocketProtocol<SocketPolicy>
+
 template <class SocketPolicy>
 prefix_ senf::ConcreteSocketProtocol<SocketPolicy>::~ConcreteSocketProtocol()
 {}
index f2046c8..5ca81db 100644 (file)
@@ -147,11 +147,6 @@ namespace senf {
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
-        SocketBody & body() const;      ///< Access the socket body
-                                        /**< \todo we don't need body(), we should better provide a
-                                             handle() member which will return a simple FIleHandle
-                                             object (we cannot return some other derived class since
-                                             we don't know the Protocol or Policy at this point) */
         virtual SocketPolicyBase const & policy() const = 0;
                                         ///< Access the policy instance
 
@@ -165,15 +160,25 @@ namespace senf {
                                              \attention This member must be implemented in every \e
                                                  leaf protocol class to return a new instance of the
                                                  appropriate type. */
+
         virtual unsigned available() const = 0;
                                         ///< Return number of bytes available for reading without
                                         ///< blocking
                                         /**< This member will check in a (very, sigh) protocol
-                                             dependent way, how many bytes are guaranteed to be
-                                             readable from the socket without blocking even if the
-                                             socket is blocking. If the socket does not support
-                                             reading (viz. NotReadablePolicy is set), this member
-                                             should always return \c 0.*/
+                                             dependent way, how many bytes may be read from a socket
+                                             in a single (non-blocking) read operation. If the
+                                             socket does not support reading (viz. NotReadablePolicy
+                                             is set), this member should always return \c 0.
+                                             
+                                             Depending on the protocol, it may not be possible to
+                                             return a good value. In this case, an upper bound may
+                                             be returned (e.g.: When reading from a socket which
+                                             returns ethernet frames, returning 1500 from
+                                             available() is ok). However, this should only be done
+                                             as a last resort. Also beware, that this number should
+                                             not be to large since the socket layer will always need
+                                             to allocate that number of bytes for the data to be
+                                             read. */
 
         virtual bool eof() const = 0;   ///< Check for end-of-file condition
                                         /**< This is another check which (like available()) is
@@ -186,12 +191,13 @@ namespace senf {
                                         /**< This override will automatically \c shutdown() the
                                              socket whenever it is closed.
                                              \throws senf::SystemException */
+
         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 therefore safe to be
+                                           failures and will never throw. It is therefore safe to be
                                            called from a destructor. */
 
         virtual void state(SocketStateMap & map, unsigned lod) const;
@@ -221,23 +227,43 @@ namespace senf {
                                              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.
 
-                                             The operator "+=" also has been reimplemented to
-                                             simplify adding multiple values to a single entry: It
-                                             will automatically add a ", " separator if the string
-                                             is non-empty. */
+                                             Additionally, if the slot the date is written to is not
+                                             empty, the <tt>\<\<</tt> operator will add add a comma
+                                             as separator. */
 
     protected:
+        FileHandle fh() const;          ///< Get a FileHandle for this instance
+                                        /**< This member will re turn a FileHandle instance for this
+                                             protocol instance. You may cast this FileHandle
+                                             instance to a ClientSocketHandle / ServerSocketHandle
+                                             as long as you know some of the socket policy using
+                                             static_socket_cast or dynamic_socket_cast */
+
+        int fd() const;                 ///< Get file descriptor
+                                        /**< Returns the file descriptor this protocol instance
+                                             references. This is the same as <tt>fh().fd()</tt> but
+                                             is implemented here since it is needed so often. */
+
+        void fd(int) const;             ///< Initialize file descriptor
+                                        /**< Assigns the file descriptor to the file handle, this
+                                             protocol instance references. Only valid, if the file
+                                             handle has not yet been assigned any descriptor (To
+                                             change the file descriptor association later, use \c
+                                             ::dup2()). */
 
     private:
         // backpointer to owning SocketBody instance
+        
+        SocketBody & body() const;
+
         SocketBody * body_;
         friend class SocketBody;
    };