Changed available() method according after chat whith Stefan.
[senf.git] / Socket / Protocols / Raw / TunTapSocketHandle.cc
index cd46920..9e02d6f 100644 (file)
@@ -50,7 +50,7 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name,
 {
     int fd;
     if ( (fd = ::open("/dev/net/tun", O_RDWR)) < 0 )
-        throw SystemException(errno);
+        throwErrno();
     struct ifreq ifr;
     ::memset( &ifr, 0, sizeof(ifr));
     ifr.ifr_flags = IFF_TAP;
@@ -58,7 +58,7 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name,
         ifr.ifr_flags |= IFF_NO_PI;
     interface_name.copy( ifr.ifr_name, IFNAMSIZ);
     if (::ioctl(fd, TUNSETIFF, (void *) &ifr) < 0 )
-        throw SystemException(errno);
+        throwErrno();
     body().fd(fd);
 }
 
@@ -69,15 +69,31 @@ prefix_ std::auto_ptr<senf::SocketProtocol> senf::TapProtocol::clone()
 }
 
 prefix_ unsigned senf::TapProtocol::available()
-    const
+  const
+{
+  if (! body().readable())
+      return 0;
+  ssize_t l = ::recv(body().fd(),0,0,MSG_PEEK | MSG_TRUNC);
+  if (l < 0)
+      //throwErrno();
+      return 1588;
+  return l;
+}
+
+/*
+#include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
+
+prefix_ unsigned senf::TapProtocol::available()
+  const
 {
-    if (! body().readable())
-        return 0;
-    ssize_t l = ::recv(body().fd(),0,0,MSG_PEEK | MSG_TRUNC);
-    if (l < 0)
-        throw SystemException(errno);
-    return l;
+  if (! body().readable())
+      return 0;
+  int n;
+  if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
+      throwErrno();
+  return n;
 }
+*/
 
 prefix_ bool senf::TapProtocol::eof()
     const