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
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 70253cf..7eaa153 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -75,13 +75,21 @@
             });
     }
 
+    static void afterSendEx(const std::weak_ptr<ConsoleHandler>& weak)
+    {
+        std::shared_ptr<ConsoleHandler> self = weak.lock();
+        if (self == nullptr)
+        {
+            return;
+        }
+        self->doRead();
+    }
+
     void doRead()
     {
-        std::size_t bytes = outputBuffer.capacity() - outputBuffer.size();
-
         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 @@
                 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 @@
 
     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;