5 #ifndef PACKIO_EXTRA_WEBSOCKET_H
6 #define PACKIO_EXTRA_WEBSOCKET_H
15 #include "../internal/config.h"
16 #include "../internal/utils.h"
18 #include <boost/beast/core.hpp>
19 #include <boost/beast/websocket.hpp>
28 template <
typename Websocket,
bool kBinary = false>
31 using protocol_type =
typename Websocket::next_layer_type::protocol_type;
33 template <
typename... Args>
36 Websocket::binary(kBinary);
40 template <
typename Buffer,
typename Handler>
43 internal::set_no_delay(boost::beast::get_lowest_layer(*this).socket());
44 return Websocket::async_write(
45 std::forward<Buffer>(buffer), std::forward<Handler>(handler));
50 template <
typename... Args>
53 return boost::beast::get_lowest_layer(*this).socket().close(
54 std::forward<Args>(args)...);
59 template <
typename... Args>
63 internal::always_false_v<Args...>,
64 "websockets do not support cancel operations");
73 template <
typename Acceptor,
typename WebsocketAdapter>
76 using Acceptor::Acceptor;
85 template <
typename Handler>
88 Acceptor::async_accept([handler = std::forward<Handler>(handler)](
89 auto ec,
auto sock)
mutable {
91 handler(ec, WebsocketAdapter(std::move(sock)));
94 auto ws = std::make_unique<WebsocketAdapter>(std::move(sock));
95 ws->set_option(boost::beast::websocket::stream_base::timeout::suggested(
97 ws->async_accept([handler = std::forward<Handler>(handler),
98 ws = std::move(ws)](
auto ec)
mutable {
99 handler(ec, std::move(*ws));
::packio::server< rpc, Acceptor, Dispatcher > server
The server for JSON-RPC.
Definition: json_rpc.h:42
The packio namespace.
Definition: arg.h:14