summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-05-31 18:54:26 +0300
committerEd Tanous <ed@tanous.net>2023-06-01 19:04:12 +0300
commit099793f4fd4754940b7dcada75c055c5d86449a0 (patch)
treeed71ec8770d13d1cb0f74dc43c9ba52caf27bc2c /include
parent6f8273e49cffdd347c223b9538558edfb05e818a (diff)
downloadbmcweb-099793f4fd4754940b7dcada75c055c5d86449a0.tar.xz
Simplify obmc console buffers
Backpressure on incoming bytes helps both to simplify the layering of the console, as well as prevent some cases of OOM crashes. Similar to what we did with nbd_proxy, move obmc console over to the new sendEx interface, allowing for backpressure, and fixed size std::array buffers. Tested: Made sure single console can see the data. Made sure two consoles can see the data. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I63d142fc5e8f8a734f3a7b8d0aa3f0d8c263d5ba
Diffstat (limited to 'include')
-rw-r--r--include/obmc_console.hpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 70253cf825..7eaa15360f 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -75,13 +75,21 @@ class ConsoleHandler : public std::enable_shared_from_this<ConsoleHandler>
});
}
- void doRead()
+ static void afterSendEx(const std::weak_ptr<ConsoleHandler>& weak)
{
- std::size_t bytes = outputBuffer.capacity() - outputBuffer.size();
+ std::shared_ptr<ConsoleHandler> self = weak.lock();
+ if (self == nullptr)
+ {
+ return;
+ }
+ self->doRead();
+ }
+ void doRead()
+ {
BMCWEB_LOG_DEBUG << "Reading from socket";
hostSocket.async_read_some(
- outputBuffer.prepare(bytes),
+ boost::asio::buffer(outputBuffer),
[this, weakSelf(weak_from_this())](
const boost::system::error_code& ec, std::size_t bytesRead) {
BMCWEB_LOG_DEBUG << "read done. Read " << bytesRead << " bytes";
@@ -97,13 +105,9 @@ class ConsoleHandler : public std::enable_shared_from_this<ConsoleHandler>
conn.close("Error connecting to host port");
return;
}
- outputBuffer.commit(bytesRead);
- std::string_view payload(
- static_cast<const char*>(outputBuffer.data().data()),
- bytesRead);
- conn.sendBinary(payload);
- outputBuffer.consume(bytesRead);
- doRead();
+ std::string_view payload(outputBuffer.data(), bytesRead);
+ self->conn.sendEx(crow::websocket::MessageType::Binary, payload,
+ std::bind_front(afterSendEx, weak_from_this()));
});
}
@@ -129,7 +133,7 @@ class ConsoleHandler : public std::enable_shared_from_this<ConsoleHandler>
boost::asio::local::stream_protocol::socket hostSocket;
- boost::beast::flat_static_buffer<4096> outputBuffer;
+ std::array<char, 4096> outputBuffer{};
std::string inputBuffer;
bool doingWrite = false;