diff options
Diffstat (limited to 'meta-openbmc-mods/meta-common/recipes-core/bmcweb/bmcweb/0001-Refine-KVM-websock-proxy.patch')
-rw-r--r-- | meta-openbmc-mods/meta-common/recipes-core/bmcweb/bmcweb/0001-Refine-KVM-websock-proxy.patch | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/meta-openbmc-mods/meta-common/recipes-core/bmcweb/bmcweb/0001-Refine-KVM-websock-proxy.patch b/meta-openbmc-mods/meta-common/recipes-core/bmcweb/bmcweb/0001-Refine-KVM-websock-proxy.patch new file mode 100644 index 000000000..acbfebdee --- /dev/null +++ b/meta-openbmc-mods/meta-common/recipes-core/bmcweb/bmcweb/0001-Refine-KVM-websock-proxy.patch @@ -0,0 +1,119 @@ +From 430bfc33ee396e4aced0514b66703e5c58a7503d Mon Sep 17 00:00:00 2001 +From: Jae Hyun Yoo <jae.hyun.yoo@intel.com> +Date: Tue, 26 Feb 2019 15:46:07 -0800 +Subject: [PATCH] Refine KVM websock proxy + +This commit simplifies input buffer delivering logic by removing +a doWrite() call from readDone(). Input events can be delivered +through websocket's onmessage handler only and it's enough. + +Also, it fixes a suspicious weak point of commit/consume pair on +outputBuffer. + +Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com> +--- + include/kvm_websocket.hpp | 57 +++++++++++++++++++++-------------------------- + 1 file changed, 26 insertions(+), 31 deletions(-) + +diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp +index aa2eaecc3205..447171b9981a 100644 +--- a/include/kvm_websocket.hpp ++++ b/include/kvm_websocket.hpp +@@ -20,53 +20,48 @@ static boost::beast::flat_static_buffer<1024U> inputBuffer; + + static crow::websocket::Connection* session = nullptr; + +-static bool doingWrite = false; ++inline void doWrite(); + +-inline void doWrite() ++inline void WriteDone(const boost::system::error_code& ec, ++ std::size_t bytesWritten) + { +- if (doingWrite) ++ BMCWEB_LOG_DEBUG << "Wrote " << bytesWritten << "bytes"; ++ inputBuffer.consume(bytesWritten); ++ ++ if (session == nullptr) ++ { ++ return; ++ } ++ if (ec == boost::asio::error::eof) ++ { ++ session->close("KVM socket port closed"); ++ return; ++ } ++ if (ec) + { +- BMCWEB_LOG_DEBUG << "Already writing. Bailing out"; ++ session->close("Error in reading to host port"); ++ BMCWEB_LOG_ERROR << "Error in KVM socket write " << ec; + return; + } ++ ++ doWrite(); ++} ++ ++inline void doWrite() ++{ + if (inputBuffer.size() == 0) + { + BMCWEB_LOG_DEBUG << "inputBuffer empty. Bailing out"; + return; + } + +- doingWrite = true; +- hostSocket->async_write_some( +- inputBuffer.data(), +- [](boost::beast::error_code ec, std::size_t bytes_written) { +- BMCWEB_LOG_DEBUG << "Wrote " << bytes_written << "bytes"; +- doingWrite = false; +- inputBuffer.consume(bytes_written); +- +- if (session == nullptr) +- { +- return; +- } +- if (ec == boost::asio::error::eof) +- { +- session->close("KVM socket port closed"); +- return; +- } +- if (ec) +- { +- session->close("Error in reading to host port"); +- BMCWEB_LOG_ERROR << "Error in KVM socket write " << ec; +- return; +- } +- doWrite(); +- }); ++ hostSocket->async_write_some(inputBuffer.data(), WriteDone); + } + + inline void doRead(); + + inline void readDone(const boost::system::error_code& ec, std::size_t bytesRead) + { +- outputBuffer.commit(bytesRead); + BMCWEB_LOG_DEBUG << "read done. Read " << bytesRead << " bytes"; + if (ec) + { +@@ -82,6 +77,7 @@ inline void readDone(const boost::system::error_code& ec, std::size_t bytesRead) + return; + } + ++ outputBuffer.commit(bytesRead); + boost::beast::string_view payload( + static_cast<const char*>(outputBuffer.data().data()), bytesRead); + BMCWEB_LOG_DEBUG << "Sending payload size " << payload.size(); +@@ -112,7 +108,6 @@ inline void connectHandler(const boost::system::error_code& ec) + return; + } + +- doWrite(); + doRead(); + } + +-- +2.7.4 + |