diff options
| author | James Feist <james.feist@linux.intel.com> | 2018-07-16 10:30:08 -0700 |
|---|---|---|
| committer | James Feist <james.feist@linux.intel.com> | 2018-07-24 09:11:13 -0700 |
| commit | b5755185cd4c3a9edcf178655b43faa17c5e0096 (patch) | |
| tree | c1fb558640d079d3ec8d08183659f4853acd00eb | |
| parent | 0db800773e6b690a95a11ab4a79d77337f21bf12 (diff) | |
| download | sdbusplus-b5755185cd4c3a9edcf178655b43faa17c5e0096.tar.gz sdbusplus-b5755185cd4c3a9edcf178655b43faa17c5e0096.zip | |
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>
| -rw-r--r-- | sdbusplus/asio/connection.hpp | 29 | ||||
| -rw-r--r-- | sdbusplus/bus.hpp.in | 3 |
2 files changed, 26 insertions, 6 deletions
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 @@ class connection : public sdbusplus::bus::bus 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 @@ class connection : public sdbusplus::bus::bus 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 @@ struct bus /** @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. |

