From fc3b68b9e987ddd114feb5da2a883ed7c37c47de Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 26 Feb 2018 23:30:08 -0800 Subject: [PATCH] ircd::server: Add more state for async ops; adjust post points. --- include/ircd/server/link.h | 4 +++- ircd/server.cc | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/ircd/server/link.h b/include/ircd/server/link.h index 833ac83ca..da05c55b8 100644 --- a/include/ircd/server/link.h +++ b/include/ircd/server/link.h @@ -18,7 +18,9 @@ struct ircd::server::link bool init {false}; ///< link is connecting bool fini {false}; ///< link is disconnecting bool exclude {false}; ///< link is excluded - int8_t handles {0}; ///< async operations + bool waiting_write {false}; ///< async operation state + bool waiting_read {false}; ///< async operation state + int8_t handles {0}; ///< async operation state std::shared_ptr node; ///< backreference to node std::shared_ptr socket; ///< link's socket std::list queue; ///< link's work queue diff --git a/ircd/server.cc b/ircd/server.cc index eead240e8..b55e5debc 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -578,6 +578,8 @@ ircd::server::node::handle_link_done(link &link) link.close(); return; } + + link.wait_readable(); } /// This is called when a tag on a link receives an HTTP response head. @@ -990,6 +992,9 @@ ircd::server::link::handle_close(std::exception_ptr eptr) void ircd::server::link::wait_writable() { + if(waiting_write) + return; + auto handler { std::bind(&link::handle_writable, this, ph::_1) @@ -997,6 +1002,7 @@ ircd::server::link::wait_writable() assert(ready()); inc_handles(); + waiting_write = true; net::wait(*socket, net::ready::WRITE, std::move(handler)); } @@ -1007,6 +1013,7 @@ try using namespace boost::system::errc; using boost::system::system_category; + waiting_write = false; const unwind handled{[this] { dec_handles(); @@ -1066,6 +1073,9 @@ ircd::server::link::handle_writable_success() continue; } + if(tag_committed() == 0) + wait_readable(); + if(!process_write(tag)) { wait_writable(); @@ -1090,9 +1100,6 @@ ircd::server::link::process_write(tag &tag) tag_count(), tag.write_total()); - if(tag_committed() == 0) - wait_readable(); - while(tag.write_remaining()) { const const_buffer buffer @@ -1134,6 +1141,9 @@ ircd::server::link::process_write_next(const const_buffer &buffer) void ircd::server::link::wait_readable() { + if(waiting_read) + return; + auto handler { std::bind(&link::handle_readable, this, ph::_1) @@ -1141,6 +1151,7 @@ ircd::server::link::wait_readable() assert(ready()); inc_handles(); + waiting_read = true; net::wait(*socket, net::ready::READ, std::move(handler)); } @@ -1151,6 +1162,7 @@ try using namespace boost::system::errc; using boost::system::system_category; + waiting_read = false; const unwind handled{[this] { dec_handles();