From 700dc3be57770c24971b285eb8fe5be2d509a27f Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Wed, 3 Dec 2008 13:12:31 +0000
Subject: [PATCH] Socket: Add oobReadable() and waitOOBReadable() FileHandle
 members

---
 Packets/PacketImpl.cc  | 15 ---------------
 Packets/PacketImpl.cci | 16 ++++++++++++++++
 Socket/FileHandle.cc   |  4 ++--
 Socket/FileHandle.cci  | 24 ++++++++++++++++++++++++
 Socket/FileHandle.hh   |  4 ++++
 Socket/FileHandle.ih   |  4 +++-
 6 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/Packets/PacketImpl.cc b/Packets/PacketImpl.cc
index f6d06ae65..647d37f14 100644
--- a/Packets/PacketImpl.cc
+++ b/Packets/PacketImpl.cc
@@ -51,21 +51,6 @@ prefix_ senf::detail::PacketImpl::~PacketImpl()
             delete i->p;
 }
 
-// This function has a problem being inlined. Somehow, often when calling this, the size of the 
-// resulting inlined code would be huge. Need to further debug this. (Disabled inliningfor now)
-
-prefix_ void senf::detail::PacketImpl::release(refcount_t n)
-{
-    SENF_ASSERT(refcount_ >= n);
-    // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
-    // however the destructor will remove all PacketInterpreters from the list and will thereby
-    // decrement refcount -> only decrenebt refcount_ when *not* caling delete
-    if (refcount_ == n)
-        delete this;
-    else
-        refcount_ -= n;
-}
-
 // interpreter chain
 
 prefix_ void senf::detail::PacketImpl::appendInterpreter(PacketInterpreterBase * p)
diff --git a/Packets/PacketImpl.cci b/Packets/PacketImpl.cci
index 4bd2bf31d..e3c532eb0 100644
--- a/Packets/PacketImpl.cci
+++ b/Packets/PacketImpl.cci
@@ -186,6 +186,22 @@ prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::capacity()
     return data_.capacity();
 }
 
+// This function has a problem being inlined. Somehow, often when calling this, the size of the 
+// resulting inlined code would be huge?
+
+prefix_ void senf::detail::PacketImpl::release(refcount_t n)
+{
+    SENF_ASSERT(refcount_ >= n);
+    // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
+    // however the destructor will remove all PacketInterpreters from the list and will thereby
+    // decrement refcount -> only decrenebt refcount_ when *not* caling delete
+    if (refcount_ == n)
+        delete this;
+    else
+        refcount_ -= n;
+}
+
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::detail::PacketImpl::Guard
 
diff --git a/Socket/FileHandle.cc b/Socket/FileHandle.cc
index baafe7a58..5ee1afeda 100644
--- a/Socket/FileHandle.cc
+++ b/Socket/FileHandle.cc
@@ -111,13 +111,13 @@ prefix_ void senf::FileBody::blocking(bool status)
 /* We don't take POLLIN/POLLOUT as argument to avoid having to include
    sys/poll.h in the .cci file (and therefore indirectly into the .hh
    and then every file which uses FileHandle) */
-prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block)
+prefix_ bool senf::FileBody::pollCheck(int fd, bool incoming, bool block, bool oob)
     const
 {
     struct ::pollfd pfd;
     ::memset(&pfd,0,sizeof(pfd));
     pfd.fd = fd;
-    pfd.events = incoming?POLLIN:POLLOUT;
+    pfd.events = incoming?(oob?POLLPRI:POLLIN):POLLOUT;
     int rv = -1;
     do {
         rv = ::poll(&pfd,1,block?-1:0);
diff --git a/Socket/FileHandle.cci b/Socket/FileHandle.cci
index e04980a3a..5cbfce4cc 100644
--- a/Socket/FileHandle.cci
+++ b/Socket/FileHandle.cci
@@ -93,6 +93,18 @@ prefix_ void senf::FileBody::waitWriteable()
     pollCheck(fd(),false,true);
 }
 
+prefix_ bool senf::FileBody::oobReadable()
+    const
+{
+    return pollCheck(fd(),true,false,true);
+}
+
+prefix_ void senf::FileBody::waitOOBReadable()
+    const
+{
+    pollCheck(fd(),true,true,true);
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::FileHandle
 
@@ -143,6 +155,18 @@ prefix_ void senf::FileHandle::waitWriteable()
     body().waitWriteable();
 }
 
+prefix_ bool senf::FileHandle::oobReadable()
+    const
+{
+    return body().oobReadable();
+}
+
+prefix_ void senf::FileHandle::waitOOBReadable()
+    const
+{
+    body().waitOOBReadable();
+}
+
 prefix_ bool senf::FileHandle::blocking()
     const
 {
diff --git a/Socket/FileHandle.hh b/Socket/FileHandle.hh
index 7dbe5ba0a..cf3fc6766 100644
--- a/Socket/FileHandle.hh
+++ b/Socket/FileHandle.hh
@@ -143,6 +143,10 @@ namespace senf {
                                      ///< (ignoring blocking state)
         void waitWriteable() const;  ///< Wait, until a write on the handle would not block
                                      ///< (ignoring blocking state)
+        bool oobReadable() const;    ///< Check, whether a read of prioritized data on the handle 
+                                     ///< would not block (ignoring blocking state)
+        void waitOOBReadable() const; ///< Wait, until read of prioritized data on the handle does
+                                     ///< not block (ignoring blocking state)
 
         bool blocking() const;       ///< Return current blocking state
         void blocking(bool status);  ///< Set blocking state
diff --git a/Socket/FileHandle.ih b/Socket/FileHandle.ih
index b1940c69e..87b1920ea 100644
--- a/Socket/FileHandle.ih
+++ b/Socket/FileHandle.ih
@@ -108,6 +108,8 @@ namespace senf {
         void waitReadable() const;
         bool writeable() const;
         void waitWriteable() const;
+        bool oobReadable() const;
+        void waitOOBReadable() const;
 
         bool blocking() const;
         void blocking(bool status);
@@ -140,7 +142,7 @@ namespace senf {
     protected:
 
     private:
-        bool pollCheck(int fd, bool incoming, bool block=false) const;
+        bool pollCheck(int fd, bool incoming, bool block=false, bool oob=false) const;
 
         int fd_;
     };
-- 
GitLab