Add return code checking for process discard

From the docs, sd_bus_process should be called until no progress
can be made. When progress is made, a positive integer is returned.
Add read_immediate to bypass setting up the fd watch when process_discard
returns a positive value.

Tested-by: Had C++ Mapper and Entity-Manager call each-other at the same
           time and noticed no longer timed out.

Change-Id: Icab11743c6c5e1486b353fce1d5e3898f2d3f533
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/sdbusplus/asio/connection.hpp b/sdbusplus/asio/connection.hpp
index e306113..8147b7a 100644
--- a/sdbusplus/asio/connection.hpp
+++ b/sdbusplus/asio/connection.hpp
@@ -43,13 +43,13 @@
         sdbusplus::bus::bus(sdbusplus::bus::new_system()), io_(io), socket(io_)
     {
         socket.assign(get_fd());
-        do_read();
+        read_wait();
     }
     connection(boost::asio::io_service& io, sd_bus* bus) :
         sdbusplus::bus::bus(bus), io_(io), socket(io_)
     {
         socket.assign(get_fd());
-        do_read();
+        read_wait();
     }
     ~connection()
     {
@@ -111,15 +111,34 @@
     boost::asio::io_service& io_;
     boost::asio::posix::stream_descriptor socket;
 
-    void do_read(void)
+    void read_wait()
     {
         socket.async_read_some(
             boost::asio::null_buffers(),
             [&](const boost::system::error_code& ec, std::size_t) {
-                process_discard();
-                do_read();
+                if (process_discard())
+                {
+                    read_immediate();
+                }
+                else
+                {
+                    read_wait();
+                }
             });
     }
+    void read_immediate()
+    {
+        io_.post([&] {
+            if (process_discard())
+            {
+                read_immediate();
+            }
+            else
+            {
+                read_wait();
+            }
+        });
+    }
 };
 
 } // namespace asio
diff --git a/sdbusplus/bus.hpp.in b/sdbusplus/bus.hpp.in
index 8417028..9252b73 100644
--- a/sdbusplus/bus.hpp.in
+++ b/sdbusplus/bus.hpp.in
@@ -170,13 +170,14 @@
 
     /** @brief Process waiting dbus messages or signals, discarding unhandled.
      */
-    void process_discard()
+    auto process_discard()
     {
         int r = _intf->sd_bus_process(_bus.get(), nullptr);
         if (r < 0)
         {
             throw exception::SdBusError(-r, "sd_bus_process discard");
         }
+        return r > 0;
     }
 
     /** @brief Claim a service name on the dbus.