bmcweb: fixes virtual media buffer overflow

The bmcweb is implementated as async i/o access, sometimes the input
buffer still has unprocessed data, and the next websocket message comes
in. The input buffer originally reserved only 1 nbd request packet size,
so it will cause buffer overflow exception. Extend the buffer size and
correctly check the remaining buffer size.

v8: fix coding style
v7: remove debug log and proxy.wait() change to keep this change simple
v4: fix coding style
v3: fix coding style
v2: fix coding style

Signed-off-by: Troy Lee <troy_lee@aspeedtech.com>
Change-Id: I8df2445503393f63401678d9f2486a80d31aee16
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 6c97f85..2dbdaf6 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -19,7 +19,7 @@
 // The max network block device buffer size is 128kb plus 16bytes
 // for the message header:
 // https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#simple-reply-message
-static constexpr auto nbdBufferSize = 131088;
+static constexpr auto nbdBufferSize = (128 * 1024 + 16) * 4;
 
 class Handler : public std::enable_shared_from_this<Handler>
 {
@@ -203,7 +203,8 @@
         })
         .onmessage([](crow::websocket::Connection& conn,
                       const std::string& data, bool) {
-            if (data.length() > handler->inputBuffer->capacity())
+            if (data.length() >
+                handler->inputBuffer->capacity() - handler->inputBuffer->size())
             {
                 BMCWEB_LOG_ERROR << "Buffer overrun when writing "
                                  << data.length() << " bytes";