added more or less meaningful descriptions when throwing SystemExceptions
tho [Mon, 1 Aug 2011 13:47:49 +0000 (13:47 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1802 270642c3-0616-0410-b53a-bc976706d245

21 files changed:
senf/Socket/FileHandle.cc
senf/Socket/Protocols/BSDAddressingPolicy.cc
senf/Socket/Protocols/BSDSocketProtocol.cc
senf/Socket/Protocols/DVB/DVBDemuxSocketProtocol.cc
senf/Socket/Protocols/DVB/DVBFrontendHandle.cc
senf/Socket/Protocols/DatagramSocketProtocol.cc
senf/Socket/Protocols/INet/ConnectedRawINetSocketHandle.cc
senf/Socket/Protocols/INet/MulticastSocketProtocol.cc
senf/Socket/Protocols/INet/RawINetSocketHandle.cc
senf/Socket/Protocols/INet/RawINetSocketProtocol.cc
senf/Socket/Protocols/INet/TCPSocketHandle.cc
senf/Socket/Protocols/INet/TCPSocketProtocol.cc
senf/Socket/Protocols/INet/UDPSocketHandle.cc
senf/Socket/Protocols/INet/UDPSocketProtocol.cc
senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.cc [new file with mode: 0644]
senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.hh [new file with mode: 0644]
senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.test.cc [new file with mode: 0644]
senf/Socket/ReadWritePolicy.cc
senf/Utils/Daemon/Daemon.cc
senf/Utils/Exception.hh
senf/Utils/senfassert.hh

index c8c5975..d99449c 100644 (file)
@@ -76,7 +76,7 @@ prefix_ void senf::FileBody::destroyClose()
 prefix_ void senf::FileBody::v_close()
 {
     if (::close(fd_) != 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not ::close FileBody fd");
 }
 
 prefix_ void senf::FileBody::v_terminate()
@@ -100,17 +100,17 @@ prefix_ bool senf::FileBody::blocking()
     const
 {
     int flags = ::fcntl(fd(),F_GETFL);
-    if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("");
+    if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("::fcntl(F_GETFL)");
     return ! (flags & O_NONBLOCK);
 }
 
 prefix_ void senf::FileBody::blocking(bool status)
 {
     int flags = ::fcntl(fd(),F_GETFL);
-    if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("");
+    if (flags < 0) SENF_THROW_SYSTEM_EXCEPTION("::fcntl(F_GETFL)");
     if (status) flags &= ~O_NONBLOCK;
     else        flags |= O_NONBLOCK;
-    if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION("");
+    if (::fcntl(fd(), F_SETFL, flags) < 0) SENF_THROW_SYSTEM_EXCEPTION("::fcntl(F_SETFL)");
 }
 
 /* We don't take POLLIN/POLLOUT as argument to avoid having to include
@@ -131,7 +131,7 @@ prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, int timeout, bool
             case EINTR:
                 break;
             default:
-                SENF_THROW_SYSTEM_EXCEPTION("");
+                SENF_THROW_SYSTEM_EXCEPTION("could not check ::poll");
             }
     } while (rv<0);
     return rv>0;
index 9ef7386..e77b101 100644 (file)
@@ -46,7 +46,7 @@ prefix_ void senf::BSDAddressingPolicyMixinBase::do_local(FileHandle const & han
                                                                  socklen_t * len)
 {
     if (::getsockname(handle.fd(),addr,len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get sockname");
 }
 
 prefix_ void senf::BSDAddressingPolicyMixinBase::do_peer(FileHandle const & handle,
@@ -54,7 +54,7 @@ prefix_ void senf::BSDAddressingPolicyMixinBase::do_peer(FileHandle const & hand
                                                                 socklen_t * len)
 {
     if (::getpeername(handle.fd(),addr,len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get peername");
 }
 
 prefix_ void senf::BSDAddressingPolicyMixinBase::do_bind(FileHandle const & handle,
@@ -62,7 +62,7 @@ prefix_ void senf::BSDAddressingPolicyMixinBase::do_bind(FileHandle const & hand
                                                                 socklen_t len)
 {
     if (::bind(handle.fd(),addr,len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not bind");
 }
 
 prefix_ void senf::BSDAddressingPolicyMixinBase::do_connect(FileHandle const & handle,
@@ -77,7 +77,7 @@ prefix_ void senf::BSDAddressingPolicyMixinBase::do_connect(FileHandle const & h
                 int err = 0;
                 socklen_t len = sizeof(err);
                 if (::getsockopt(handle.fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
-                    SENF_THROW_SYSTEM_EXCEPTION("");
+                    SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_ERROR)");
                 if (err != 0)
                     throw SystemException(err SENF_EXC_DEBUGINFO);
                 return;
@@ -85,7 +85,7 @@ prefix_ void senf::BSDAddressingPolicyMixinBase::do_connect(FileHandle const & h
             case EINTR:
                 break;
             default:
-                SENF_THROW_SYSTEM_EXCEPTION("");
+                SENF_THROW_SYSTEM_EXCEPTION("could not ::connect");
             }
         else
             return;
index 0947cbb..f075af7 100644 (file)
@@ -47,7 +47,7 @@ prefix_ std::pair<bool,unsigned> senf::BSDSocketProtocol::linger()
     socklen_t len = sizeof(ling);
     ::memset(&ling, 0, sizeof(ling));
     if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_LINGER");
     return std::make_pair(ling.l_onoff, ling.l_linger);
 }
 
@@ -58,7 +58,7 @@ prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
     ling.l_onoff = enable;
     ling.l_linger = timeout;
     if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_LINGER");
 }
 
 prefix_ boost::uint8_t senf::BSDSocketProtocol::priority()
@@ -67,7 +67,7 @@ prefix_ boost::uint8_t senf::BSDSocketProtocol::priority()
     int value;
     socklen_t len (sizeof(value));
     if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_PRIORITY");
     return value;
 }
 
@@ -76,7 +76,7 @@ prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value)
 {
     int ivalue (value);
     if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_PRIORITY");
 }
 
 prefix_ int senf::BSDSocketProtocol::error()
@@ -85,7 +85,7 @@ prefix_ int senf::BSDSocketProtocol::error()
     int err;
     socklen_t len (sizeof(err));
     if (::getsockopt(fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_ERROR");
     return err;
 }
 
@@ -95,7 +95,7 @@ prefix_ unsigned senf::BSDSocketProtocol::rcvbuf()
     unsigned size;
     socklen_t len (sizeof(size));
     if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_RCVBUF");
     // 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;
@@ -105,7 +105,7 @@ prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size)
     const
 {
     if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_RCVBUF");
 }
 
 prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
@@ -114,7 +114,7 @@ prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
     unsigned size;
     socklen_t len (sizeof(size));
     if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_SNDBUF");
     // 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;
@@ -124,7 +124,7 @@ prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size)
     const
 {
     if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_SNDBUF");
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -135,7 +135,7 @@ prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
     int value;
     socklen_t len (sizeof(value));
     if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get socketopt SO_REUSEADDR");
     return value;
 }
 
@@ -144,7 +144,7 @@ prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
 {
     int ivalue (value);
     if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not set socketopt SO_REUSEADDR");
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
index 43d348d..0c36459 100644 (file)
@@ -47,9 +47,9 @@ prefix_ void senf::DVBDemuxSocketProtocol::setBufferSize(unsigned long size)
     const
 {
     if (::ioctl(fd(), DMX_SET_BUFFER_SIZE, size) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("")
-              << "Could not set the size of the buffer on DVB adapter. requested size: "
-              << size << ".";
+        SENF_THROW_SYSTEM_EXCEPTION(
+                "Could not set the size of the buffer on DVB adapter. requested size: ")
+                << size << ".";
 }
 
 prefix_ void senf::DVBDemuxSocketProtocol::startFiltering()
index 7ba476b..d53ef98 100644 (file)
@@ -53,7 +53,7 @@ prefix_ void senf::DVBFrontendSocketProtocol::init_client(unsigned short adapter
     string devFrontend = str( boost::format("/dev/dvb/adapter%d/frontend%d") % adapter % device);
     int f = open(devFrontend.c_str(), flags);
     if (f < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("")<< "Could not open frontend device of DVB adapter " << devFrontend << ".";
+        SENF_THROW_SYSTEM_EXCEPTION("Could not open frontend device of DVB adapter ") << devFrontend << ".";
     fd(f);
 }
 
@@ -74,7 +74,7 @@ prefix_ void senf::DVBFrontendSocketProtocol::tune(const struct dvb_frontend_par
 {
     // tuning
     if (::ioctl(fd(), FE_SET_FRONTEND, &frontend) )
-        SENF_THROW_SYSTEM_EXCEPTION("") << "ioctl FE_SET_FRONTEND failed. Socket should initialized with r/w permissions.";;
+        SENF_THROW_SYSTEM_EXCEPTION("ioctl FE_SET_FRONTEND failed. Socket should initialized with r/w permissions.");
 }
 
 prefix_ void senf::DVBFrontendSocketProtocol::tuneDVB_T(unsigned int frequency,
@@ -173,7 +173,7 @@ prefix_ dvb_frontend_info senf::DVBFrontendSocketProtocol::getInfo()
     ::memset(&info, 0, sizeof(struct dvb_frontend_info));
 
     if (::ioctl(fd(), FE_GET_INFO, &info)) {
-        SENF_THROW_SYSTEM_EXCEPTION("") << "Could not read on fildescriptor.";
+        SENF_THROW_SYSTEM_EXCEPTION("Could not read on fildescriptor.");
     }
     return info;
 }
index 01096e3..39e4430 100644 (file)
@@ -45,7 +45,7 @@ prefix_ senf::ClockService::clock_type senf::DatagramSocketProtocol::timestamp()
 {
     struct timeval tv;
     if (::ioctl(fd(), SIOCGSTAMP, &tv) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get timestamp in DatagramSocketProtocol");
     return ClockService::from_timeval(tv);
 }
 
index 46ed9e5..6bce3da 100644 (file)
@@ -53,7 +53,7 @@ senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol)
 {
     int sock = ::socket(PF_INET, SOCK_RAW, protocol);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open ConnectedRawV4Socket");
     fd(sock);
 }
 
@@ -79,7 +79,7 @@ prefix_ void senf::ConnectedRawV6SocketProtocol::init_client(int const & protoco
 {
     int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open ConnectedRawV6Socket");
     fd(sock);
 }
 
index cc5ffc9..b5bc181 100644 (file)
@@ -68,7 +68,7 @@ prefix_ bool senf::MulticastSocketProtocol::mcLoop()
     int value (0);
     socklen_t len (sizeof(value));
     if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&value,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_LOOP)");
     return value;
 }
 
@@ -77,7 +77,7 @@ prefix_ void senf::MulticastSocketProtocol::mcLoop(bool value)
 {
     int ivalue (value);
     if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_LOOP,&ivalue,sizeof(ivalue)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_LOOP)");
 }
 
 prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface)
@@ -91,7 +91,7 @@ prefix_ void senf::MulticastSocketProtocol::mcIface(std::string const & iface)
             throw SystemException(EINVAL SENF_EXC_DEBUGINFO);
     }
     if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_IF,&mreqn,sizeof(mreqn)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_IF)");
 }
 
 prefix_ unsigned senf::MulticastSocketProtocol::mcTTL()
@@ -100,7 +100,7 @@ prefix_ unsigned senf::MulticastSocketProtocol::mcTTL()
     int value (0);
     socklen_t len (sizeof(value));
     if (::getsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_TTL)");
     return value;
 }
 
@@ -108,7 +108,7 @@ prefix_ void senf::MulticastSocketProtocol::mcTTL(unsigned value)
     const
 {
     if (::setsockopt(fd(),SOL_IP,IP_MULTICAST_TTL,&value,sizeof(value)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(IP_MULTICAST_TTL");
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -159,7 +159,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address c
     mreqn.imr_address.s_addr = htons(INADDR_ANY);
     mreqn.imr_ifindex = 0;
     if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
 }
 
 prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr,
@@ -171,7 +171,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address c
     mreqn.imr_address.s_addr = localAddr.inaddr();
     mreqn.imr_ifindex = 0;
     if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
 }
 
 prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address const & mcAddr,
@@ -185,7 +185,7 @@ prefix_ void senf::INet4MulticastSocketProtocol::mcDropMembership(INet4Address c
     if (mreqn.imr_ifindex == 0)
         throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
     if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
 }
 
 namespace {
@@ -279,14 +279,14 @@ prefix_ void senf::INet6MulticastSocketProtocol::mcDropMembership(INet6Address c
         mreqn.imr_address.s_addr = htons(INADDR_ANY);
         mreqn.imr_ifindex = 0;
         if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-            SENF_THROW_SYSTEM_EXCEPTION("");
+            SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
     }
     else {
         struct ipv6_mreq mreqn;
         std::copy(mcAddr.begin(), mcAddr.end(), mreqn.ipv6mr_multiaddr.s6_addr);
         mreqn.ipv6mr_interface = 0;
         if (::setsockopt(fd(),SOL_IPV6,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-            SENF_THROW_SYSTEM_EXCEPTION("");
+            SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_DROP_MEMBERSHIP");
     }
 }
 
@@ -303,7 +303,7 @@ senf::INet6MulticastSocketProtocol::mcDropMembership(INet6Address const & mcAddr
         if (mreqn.imr_ifindex == 0)
             throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
         if (::setsockopt(fd(),SOL_IP,IP_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-            SENF_THROW_SYSTEM_EXCEPTION("");
+            SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IP_DROP_MEMBERSHIP");
     }
     else {
         struct ipv6_mreq mreqn;
@@ -312,7 +312,7 @@ senf::INet6MulticastSocketProtocol::mcDropMembership(INet6Address const & mcAddr
         if (mreqn.ipv6mr_interface == 0)
             throw SystemException("::if_nametoindex()",ENOENT SENF_EXC_DEBUGINFO);
         if (::setsockopt(fd(),SOL_IPV6,IPV6_DROP_MEMBERSHIP,&mreqn,sizeof(mreqn)) < 0)
-            SENF_THROW_SYSTEM_EXCEPTION("");
+            SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(IPV6_DROP_MEMBERSHIP");
     }
 }
 
index a2f2ac7..13aa54d 100644 (file)
@@ -53,7 +53,7 @@ senf::RawV4SocketProtocol::init_client(int const & protocol)
 {
     int sock = ::socket(PF_INET, SOCK_RAW, protocol);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open RawV4Socket");
     fd(sock);
 }
 
@@ -79,7 +79,7 @@ prefix_ void senf::RawV6SocketProtocol::init_client(int const & protocol)
 {
     int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open RawV6Socket");
     fd(sock);
 }
 
index c0fa475..81d673c 100644 (file)
@@ -41,7 +41,7 @@ prefix_ unsigned senf::RawINetSocketProtocol::available()
 {
     int n;
     if (::ioctl(fd(),SIOCINQ,&n) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not call ::ioctl(SIOCINQ) in RawINetSocketProtocol::available()");
     return n;
 }
 
index d82071c..6e51ee3 100644 (file)
@@ -51,7 +51,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_client()
 {
     int sock = ::socket(PF_INET,SOCK_STREAM,0);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv4Socket");
     fd(sock);
 }
 
@@ -68,7 +68,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server()
 {
     int sock = ::socket(PF_INET,SOCK_STREAM,0);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv4Socket");
     fd(sock);
 }
 
@@ -80,7 +80,7 @@ prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & a
     reuseaddr(true);
     serverHandle().bind(address);
     if (::listen(fd(),backlog) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not listen on TCPv4Socket");
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -91,7 +91,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_client()
 {
     int sock = ::socket(PF_INET6,SOCK_STREAM,0);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv6Socket");
     fd(sock);
 }
 
@@ -108,7 +108,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server()
 {
     int sock = ::socket(PF_INET6,SOCK_STREAM,0);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open TCPv6Socket");
     fd(sock);
 }
 
@@ -120,7 +120,7 @@ prefix_ void senf::TCPv6SocketProtocol::init_server(INet6SocketAddress const & a
     serverHandle().bind(address);
     reuseaddr(true);
     if (::listen(fd(),backlog) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not listen on TCPv6Socket");
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
index 5032f71..6a38b9c 100644 (file)
@@ -49,7 +49,7 @@ prefix_ bool senf::TCPSocketProtocol::nodelay()
     int value;
     socklen_t len (sizeof(value));
     if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not get sockopt TCP_NODELAY");
     return value;
 }
 
@@ -58,7 +58,7 @@ prefix_ void senf::TCPSocketProtocol::nodelay(bool value)
 {
     int ivalue (value);
     if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not set sockopt TCP_NODELAY");
 }
 
 prefix_ unsigned senf::TCPSocketProtocol::siocinq()
@@ -66,7 +66,7 @@ prefix_ unsigned senf::TCPSocketProtocol::siocinq()
 {
     int n;
     if (::ioctl(fd(),SIOCINQ,&n) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::ioctl(SIOCINQ)");
     return n;
 }
 
@@ -75,7 +75,7 @@ prefix_ unsigned senf::TCPSocketProtocol::siocoutq()
 {
     int n;
     if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("::ioctl(SIOCOUTQ)");
     return n;
 }
 
index a07b6be..1cf6a63 100644 (file)
@@ -51,7 +51,7 @@ prefix_ void senf::UDPv4SocketProtocol::init_client()
 {
     int sock = ::socket(PF_INET,SOCK_DGRAM,0);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open UDPv4Socket");
     fd(sock);
 }
 
@@ -72,7 +72,7 @@ prefix_ void senf::UDPv6SocketProtocol::init_client()
 {
     int sock = ::socket(PF_INET6,SOCK_DGRAM,0);
     if (sock < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not open UDPv6Socket");
     fd(sock);
 }
 
index d5f4623..eb4458b 100644 (file)
@@ -45,7 +45,7 @@ prefix_ unsigned senf::UDPSocketProtocol::available()
 {
     int n;
     if (::ioctl(fd(),SIOCINQ,&n) < 0)
-        SENF_THROW_SYSTEM_EXCEPTION("");
+        SENF_THROW_SYSTEM_EXCEPTION("could not call ::ioctl(SIOCINQ) in UDPSocketProtocol::available()");
     return n;
 }
 
diff --git a/senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.cc b/senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.cc
new file mode 100644 (file)
index 0000000..63f3459
--- /dev/null
@@ -0,0 +1,105 @@
+// $Id$
+//
+// Copyright (C) 2011
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
+//
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
+//
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Thorsten Horstmann <tho@berlios.de>
+
+/** \file
+    \brief MmapedPacketSocketProtocol and MmapedPacketSocketHandle non-inline non-template implementation
+ */
+
+#include "MmapedPacketSocketHandle.hh"
+//#include "MmapedPacketSocketHandle.ih"
+
+// Custom includes
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/mman.h>
+#include <linux/if_packet.h>
+#include <net/ethernet.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <errno.h>
+
+//#include "MmapedPacketSocketHandle.mpp"
+#define prefix_
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+prefix_ void senf::MmapedPacketSocketProtocol::init_client(SocketType type, int protocol)
+{
+    /* Setup req */
+    req_.tp_block_size = 4096;
+    req_.tp_frame_size = 2048;
+    req_.tp_block_nr = 32;
+    req_.tp_frame_nr = 2*32;
+    /* Setup socket */
+    int socktype = (type == RawSocket ? SOCK_RAW : SOCK_DGRAM);
+    if (protocol == -1)
+        protocol = ETH_P_ALL;
+    int sock = ::socket(PF_PACKET, socktype, htons(protocol));
+    if (sock < 0)
+        SENF_THROW_SYSTEM_EXCEPTION("::socket(...) failed.");
+    if ( (setsockopt(sock, SOL_PACKET, PACKET_RX_RING, reinterpret_cast<char *>(&req_), sizeof(req_))) != 0 )
+        SENF_THROW_SYSTEM_EXCEPTION("setsockopt(PACKET_RX_RING) failed.");
+    /* Setup mmap */
+    map_ = static_cast<char *>(
+            mmap( NULL, req_.tp_block_size * req_.tp_block_nr, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, sock, 0));
+    if ( map_ == MAP_FAILED )
+        SENF_THROW_SYSTEM_EXCEPTION("mmap failed.");
+    /* Setup our ringbuffer */
+    ring_.resize( req_.tp_frame_nr);
+    for (unsigned i=0; i<req_.tp_frame_nr; i++) {
+        ring_[i].iov_base = (void *) (&map_[i*req_.tp_frame_size]);
+        ring_[i].iov_len = req_.tp_frame_size;
+    }
+    fd( sock);
+}
+
+prefix_ unsigned senf::MmapedPacketSocketProtocol::available()
+    const
+{
+
+}
+
+prefix_ bool senf::MmapedPacketSocketProtocol::eof()
+    const
+{
+    return false;
+}
+
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+#undef prefix_
+//#include "PacketSocketHandle.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
diff --git a/senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.hh b/senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.hh
new file mode 100644 (file)
index 0000000..e5f7c6b
--- /dev/null
@@ -0,0 +1,116 @@
+// $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
+//
+// Copyright (C) 2011
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
+//
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
+//
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Thorsten Horstmann <tho@berlios.de>
+
+/** \file
+    \brief MmapedPacketSocketProtocol and MmapedPacketSocketHandle public header
+ */
+
+#ifndef HH_SENF_Socket_Protocols_Raw_MmapedPacketSocketHandle_
+#define HH_SENF_Socket_Protocols_Raw_MmapedPacketSocketHandle_ 1
+
+// Custom includes
+#include <senf/Socket/SocketPolicy.hh>
+#include <senf/Socket/SocketProtocol.hh>
+#include <senf/Socket/ProtocolClientSocketHandle.hh>
+#include <senf/Socket/FramingPolicy.hh>
+#include <senf/Socket/CommunicationPolicy.hh>
+#include <senf/Socket/ReadWritePolicy.hh>
+#include "LLAddressing.hh"
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+namespace senf {
+
+    /// \addtogroup concrete_protocol_group
+    //\{
+
+    typedef MakeSocketPolicy<
+        LLAddressingPolicy,
+        DatagramFramingPolicy,
+        UnconnectedCommunicationPolicy,
+        NotReadablePolicy,
+        NotWriteablePolicy
+        >::policy MmapedPacket_Policy;        ///< Policy of MmapedPacketSocketProtocol
+
+
+    /** \brief
+     */
+    class MmapedPacketSocketProtocol
+        : public ConcreteSocketProtocol<MmapedPacket_Policy, MmapedPacketSocketProtocol>
+    {
+    public:
+        enum SocketType { RawSocket, DatagramSocket };
+                                        ///< Socket types
+
+        ///\name Constructors
+        //\{
+        void init_client(SocketType type = RawSocket, int protocol = -1);
+        //\}
+
+        ///\name Protocol Interface
+        //\{
+
+        //\}
+
+        ///\name Abstract Interface Implementation
+        //\{
+        unsigned available() const;
+        bool eof() const;
+        //\}
+
+    private:
+        char * map_;
+//        struct iovec * ring_;
+        struct tpacket_req req_;
+        typedef std::vector<struct iovec> iovecRing;
+        iovecRing ring_;
+    };
+
+
+    typedef ProtocolClientSocketHandle<MmapedPacketSocketProtocol> MmapedPacketSocketHandle;
+                                        ///< SocketHandle of the MmapedPacketSocketProtocol
+                                        /**< \related MmapedPacketSocketProtocol */
+
+    //\}
+}
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+//#include "MmapedPacketSocketHandle.cci"
+//#include "MmapedPacketSocketHandle.ct"
+//#include "MmapedPacketSocketHandle.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
diff --git a/senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.test.cc b/senf/Socket/Protocols/Raw/MmapedPacketSocketHandle.test.cc
new file mode 100644 (file)
index 0000000..df29d21
--- /dev/null
@@ -0,0 +1,69 @@
+// $Id$
+//
+// Copyright (C) 2011
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+//
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
+//
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
+//
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Thorsten Horstmann <tho@berlios.de>
+
+/** \file
+    \brief MmapedPacketSocketHandle unit tests */
+
+
+// Custom includes
+#include "MmapedPacketSocketHandle.hh"
+
+#include <senf/Utils/auto_unit_test.hh>
+#include <boost/test/test_tools.hpp>
+
+#define prefix_
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+SENF_AUTO_UNIT_TEST(mmapedPacketSocketHandle)
+{
+    // packet sockets are only allowed for root
+    if (getuid() != 0) {
+        BOOST_WARN_MESSAGE(false, "Cannot test senf::MmapedPacketSocketHandle as non-root user");
+        BOOST_CHECK( true );
+        return;
+    }
+
+    {
+        senf::MmapedPacketSocketHandle sock;
+
+        BOOST_CHECK( ! sock.eof() );
+    }
+}
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
index bc10b74..7d177ab 100644 (file)
@@ -38,7 +38,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-
 //#include "ReadWritePolicy.mpp"
 #define prefix_
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -58,7 +57,7 @@ prefix_ unsigned senf::ReadablePolicy::read(FileHandle & handle, char * buffer,
                 rv = 0;
                 break;
             default:
-                SENF_THROW_SYSTEM_EXCEPTION("");
+                SENF_THROW_SYSTEM_EXCEPTION(":::read");
             }
     } while (rv<0);
     return rv;
@@ -79,7 +78,7 @@ prefix_ unsigned senf::ReadablePolicy::do_readfrom(FileHandle & handle, char * b
                 rv = 0;
                 break;
             default:
-                SENF_THROW_SYSTEM_EXCEPTION("");
+                SENF_THROW_SYSTEM_EXCEPTION("::recvfrom");
             }
     } while (rv<0);
     return rv;
@@ -108,7 +107,7 @@ prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle & handle, char const
                 rv = 0;
                 break;
             default:
-                SENF_THROW_SYSTEM_EXCEPTION("");
+                SENF_THROW_SYSTEM_EXCEPTION("::write");
             }
     } while (rv<0);
     return rv;
@@ -132,7 +131,7 @@ prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle & handle,
                 rv = 0;
                 break;
             default:
-                SENF_THROW_SYSTEM_EXCEPTION("");
+                SENF_THROW_SYSTEM_EXCEPTION("::sendto");
             }
     } while (rv<0);
     return rv;
index e2969a9..e2f0fec 100644 (file)
@@ -135,8 +135,8 @@ prefix_ void senf::Daemon::openLog()
     if (! stdoutLog_.empty()) {
         fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
         if (fd < 0)
-            SENF_THROW_SYSTEM_EXCEPTION("")
-                  << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout.";
+            SENF_THROW_SYSTEM_EXCEPTION(
+                  " Could not open \"" + stdoutLog_ + "\" for redirecting stdout.");
         stdout_ = fd;
     }
     if (! stderrLog_.empty()) {
@@ -148,8 +148,8 @@ prefix_ void senf::Daemon::openLog()
         else {
             fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
             if (fd < 0)
-                SENF_THROW_SYSTEM_EXCEPTION("")
-                    << " Could not open \"" << stderrLog_ << "\" for redirecting stderr.";
+                SENF_THROW_SYSTEM_EXCEPTION(
+                    " Could not open \"" + stderrLog_ + "\" for redirecting stderr.");
             stderr_ = fd;
         }
     }
@@ -445,17 +445,15 @@ prefix_ bool senf::Daemon::pidfileCreate()
         {
             std::ofstream pidf (tempname.c_str());
             if (! pidf)
-                SENF_THROW_SYSTEM_EXCEPTION("")
-                      << " Could not open pidfile \"" << tempname << "\" for output.";
+                SENF_THROW_SYSTEM_EXCEPTION(" Could not open pidfile \"" + tempname + "\" for output.");
             pidf << ::getpid() << std::endl;
             if (! pidf)
-                SENF_THROW_SYSTEM_EXCEPTION("")
-                      << " Could not write to pidfile \"" << tempname << "\".";
+                SENF_THROW_SYSTEM_EXCEPTION(" Could not write to pidfile \"" + tempname + "\".");
         }
 
         if (::link(tempname.c_str(), pidfile_.c_str()) < 0) {
             if (errno != EEXIST)
-                SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % pidfile_ % tempname;
+                SENF_THROW_SYSTEM_EXCEPTION((linkErrorFormat % pidfile_ % tempname).str());
         }
         else {
             struct ::stat s;
@@ -488,7 +486,7 @@ prefix_ bool senf::Daemon::pidfileCreate()
         LIBC_CALL( ::unlink, (tempname.c_str() ));
         if (::link(pidfile_.c_str(), tempname.c_str()) < 0) {
             if (errno != ENOENT)
-                SENF_THROW_SYSTEM_EXCEPTION("") << linkErrorFormat % tempname % pidfile_;
+                SENF_THROW_SYSTEM_EXCEPTION( (linkErrorFormat % tempname % pidfile_).str());
             // Hmm ... the pidfile mysteriously disappeared ... try again.
             continue;
         }
index df47d2b..9bca764 100644 (file)
 #include <string>
 #include <iostream>
 #include <sstream>
-#include <boost/preprocessor/repeat.hpp>
-#include <boost/preprocessor/cat.hpp>
 #include <boost/utility.hpp>
 #include <boost/type_traits/is_convertible.hpp>
 #include <senf/config.hh>
+#include "senfassert.hh"
+
 
 //#include "Exception.mpp"
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -318,7 +318,10 @@ namespace senf {
 #       define SENF_EXC_DEBUGINFO
 #   endif
 
-#   define SENF_THROW_SYSTEM_EXCEPTION(desc) throw senf::SystemException(desc SENF_EXC_DEBUGINFO)
+#   define SENF_THROW_SYSTEM_EXCEPTION(desc)                        \
+        SENF_STATIC_ASSERT( sizeof(desc) > 1,                       \
+            EMPTY_DESCRIPTION_FOR_SYSTEM_EXCEPTION_NOT_ALLOWED);    \
+        throw senf::SystemException(desc SENF_EXC_DEBUGINFO)
 
 }
 
index dd1ac50..ef27006 100644 (file)
 
 #endif
 
+
+/* Lifted direct from:
+   Modern C++ Design: Generic Programming and Design Patterns Applied Section 2.1
+   by Andrei Alexandrescu
+*/
+namespace senf {
+namespace detail {
+    template<bool> class compile_time_check
+    {
+    public:
+        compile_time_check(...) {}
+    };
+
+    template<> class compile_time_check<false>
+    {
+    };
+}}
+
+    /*
+    SENF_STATIC_ASSERT is only in operation when SENF_DEBUG is defined. It will test its first
+    argument at compile time and on failure report the error message of the second argument,
+    which must be a valid c++ classname. i.e. no spaces, punctuation or reserved keywords.
+    */
+#ifdef SENF_DEBUG
+#   define SENF_STATIC_ASSERT(expr, msg)                                    \
+    do {                                                                    \
+        struct STATIC_ASSERT_FAILED_##msg {};                               \
+        typedef senf::detail::compile_time_check< (expr) != 0 > tmplimpl;   \
+        tmplimpl aTemp = tmplimpl(STATIC_ASSERT_FAILED_##msg());            \
+        (void)sizeof(aTemp);                                                      \
+    } while (0)
+#else
+#   define SENF_STATIC_ASSERT(expr, msg)
+#endif
+
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
 //#include "senfassert.cci"
 //#include "senfassert.ct"