vm_websocket.hpp (c0a1c8a0ecc55aef54e6f44ea89a4dd232e265a2) vm_websocket.hpp (1214b7e7d921e331fb1480c7e5d579ffa5811cda)
1#pragma once
2
3#include <app.h>
4#include <websocket.h>
5
6#include <boost/beast/core/flat_static_buffer.hpp>
7#include <boost/process.hpp>
1#pragma once
2
3#include <app.h>
4#include <websocket.h>
5
6#include <boost/beast/core/flat_static_buffer.hpp>
7#include <boost/process.hpp>
8#include <csignal>
9#include <webserver_common.hpp>
10
8#include <webserver_common.hpp>
9
10#include <csignal>
11
11namespace crow
12{
13namespace obmc_vm
14{
15
16static crow::websocket::Connection* session = nullptr;
17
18// The max network block device buffer size is 128kb plus 16bytes
19// for the message header:
20// https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#simple-reply-message
21static constexpr auto nbdBufferSize = 131088;
22
23class Handler : public std::enable_shared_from_this<Handler>
24{
25 public:
26 Handler(const std::string& mediaIn, boost::asio::io_context& ios) :
27 pipeOut(ios), pipeIn(ios), media(mediaIn), doingWrite(false),
28 outputBuffer(new boost::beast::flat_static_buffer<nbdBufferSize>),
29 inputBuffer(new boost::beast::flat_static_buffer<nbdBufferSize>)
12namespace crow
13{
14namespace obmc_vm
15{
16
17static crow::websocket::Connection* session = nullptr;
18
19// The max network block device buffer size is 128kb plus 16bytes
20// for the message header:
21// https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#simple-reply-message
22static constexpr auto nbdBufferSize = 131088;
23
24class Handler : public std::enable_shared_from_this<Handler>
25{
26 public:
27 Handler(const std::string& mediaIn, boost::asio::io_context& ios) :
28 pipeOut(ios), pipeIn(ios), media(mediaIn), doingWrite(false),
29 outputBuffer(new boost::beast::flat_static_buffer<nbdBufferSize>),
30 inputBuffer(new boost::beast::flat_static_buffer<nbdBufferSize>)
30 {
31 }
31 {}
32
33 ~Handler() = default;
34
35 void doClose()
36 {
37 // boost::process::child::terminate uses SIGKILL, need to send SIGTERM
38 // to allow the proxy to stop nbd-client and the USB device gadget.
39 int rc = kill(proxy.id(), SIGTERM);

--- 110 unchanged lines hidden (view full) ---

150 std::unique_ptr<boost::beast::flat_static_buffer<nbdBufferSize>>
151 outputBuffer;
152 std::unique_ptr<boost::beast::flat_static_buffer<nbdBufferSize>>
153 inputBuffer;
154};
155
156static std::shared_ptr<Handler> handler;
157
32
33 ~Handler() = default;
34
35 void doClose()
36 {
37 // boost::process::child::terminate uses SIGKILL, need to send SIGTERM
38 // to allow the proxy to stop nbd-client and the USB device gadget.
39 int rc = kill(proxy.id(), SIGTERM);

--- 110 unchanged lines hidden (view full) ---

150 std::unique_ptr<boost::beast::flat_static_buffer<nbdBufferSize>>
151 outputBuffer;
152 std::unique_ptr<boost::beast::flat_static_buffer<nbdBufferSize>>
153 inputBuffer;
154};
155
156static std::shared_ptr<Handler> handler;
157
158template <typename... Middlewares> void requestRoutes(Crow<Middlewares...>& app)
158template <typename... Middlewares>
159void requestRoutes(Crow<Middlewares...>& app)
159{
160 BMCWEB_ROUTE(app, "/vm/0/0")
161 .requires({"ConfigureComponents", "ConfigureManager"})
162 .websocket()
163 .onopen([](crow::websocket::Connection& conn,
164 std::shared_ptr<bmcweb::AsyncResp> asyncResp) {
165 BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
166

--- 52 unchanged lines hidden ---
160{
161 BMCWEB_ROUTE(app, "/vm/0/0")
162 .requires({"ConfigureComponents", "ConfigureManager"})
163 .websocket()
164 .onopen([](crow::websocket::Connection& conn,
165 std::shared_ptr<bmcweb::AsyncResp> asyncResp) {
166 BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
167

--- 52 unchanged lines hidden ---