38#include <asio/any_io_executor.hpp>
39#include <asio/awaitable.hpp>
51namespace neograph::async {
53enum class WsOpcode : std::uint8_t {
116 asio::awaitable<void>
send_text(std::string_view payload);
127 asio::awaitable<void>
send_close(std::uint16_t code = 1000, std::string_view reason =
"");
138 asio::awaitable<WsMessage>
recv();
145 friend NEOGRAPH_API asio::awaitable<std::unique_ptr<WsClient>>
ws_connect(
146 asio::any_io_executor,
150 std::vector<std::pair<std::string, std::string>>,
152 friend NEOGRAPH_API asio::awaitable<std::unique_ptr<WsClient>>
ws_connect(
153 asio::any_io_executor,
157 std::vector<std::pair<std::string, std::string>>,
162 std::unique_ptr<Impl> impl_;
164 explicit WsClient(std::unique_ptr<Impl>);
166 asio::awaitable<WsMessage> recv_message();
167 asio::awaitable<void> send_frame_owned(WsOpcode opcode, std::string payload);
168 asio::awaitable<void> send_close_owned(std::uint16_t code, std::string reason);
169 static asio::awaitable<std::unique_ptr<WsClient>> connect_owned(
170 asio::any_io_executor ex,
174 std::vector<std::pair<std::string, std::string>> headers,
177 static asio::awaitable<std::unique_ptr<WsClient>> handshake_owned(
178 asio::any_io_executor ex,
182 std::vector<std::pair<std::string, std::string>> headers,
205NEOGRAPH_API asio::awaitable<std::unique_ptr<WsClient>>
ws_connect(
206 asio::any_io_executor ex,
207 std::string_view host,
208 std::string_view port,
209 std::string_view path,
210 std::vector<std::pair<std::string, std::string>> headers = {},
215NEOGRAPH_API asio::awaitable<std::unique_ptr<WsClient>>
ws_connect(
216 asio::any_io_executor ex,
217 std::string_view host,
218 std::string_view port,
219 std::string_view path,
220 std::vector<std::pair<std::string, std::string>> headers,
227struct WsFrameHeader {
231 std::uint64_t payload_len;
232 std::uint8_t mask_key[4];
234 std::size_t header_size;
242NEOGRAPH_API std::optional<WsFrameHeader> parse_frame_header(std::string_view buf);
246NEOGRAPH_API
void encode_frame_header(std::string& out,
250 std::uint64_t payload_len,
251 const std::uint8_t mask_key[4] =
nullptr);
254NEOGRAPH_API
void apply_mask(
char* data, std::size_t len,
const std::uint8_t mask_key[4])
noexcept;
258NEOGRAPH_API std::string generate_sec_websocket_key();
262NEOGRAPH_API std::string compute_sec_websocket_accept(std::string_view client_key);
NEOGRAPH_API export/import macro for shared-library builds.
asio::awaitable< void > send_close(std::uint16_t code=1000, std::string_view reason="")
Send a close frame with the given status code and optional UTF-8 reason.
asio::awaitable< void > send_binary(std::string_view payload)
Send a binary frame (FIN=1).
asio::awaitable< WsMessage > recv()
Block until the next application message arrives.
asio::awaitable< void > send_text(std::string_view payload)
Send a text frame (FIN=1, no fragmentation).
friend NEOGRAPH_API asio::awaitable< std::unique_ptr< WsClient > > ws_connect(asio::any_io_executor, std::string_view, std::string_view, std::string_view, std::vector< std::pair< std::string, std::string > >, bool)
Establish a WebSocket connection.
friend NEOGRAPH_API asio::awaitable< std::unique_ptr< WsClient > > ws_connect(asio::any_io_executor, std::string_view, std::string_view, std::string_view, std::vector< std::pair< std::string, std::string > >, bool, WsClientOptions)
Establish a WebSocket connection with explicit resource ceilings.
Resource ceilings and deadlines for a WebSocket connection.
std::chrono::milliseconds read_timeout
Longest one recv() call waits for the next application message (pings answered meanwhile do not exten...
std::size_t max_handshake_bytes
Maximum HTTP Upgrade response header size, including the final CRLF CRLF.
std::size_t max_message_payload_bytes
Maximum assembled Text/Binary message size across fragments.
std::size_t max_frame_payload_bytes
Maximum payload size of any individual data or control frame.
std::chrono::milliseconds handshake_timeout
Deadline for the whole opening handshake of ws_connect: name resolution, TCP connect,...
NEOGRAPH_API asio::awaitable< std::unique_ptr< WsClient > > ws_connect(asio::any_io_executor ex, std::string_view host, std::string_view port, std::string_view path, std::vector< std::pair< std::string, std::string > > headers={}, bool tls=true)
Establish a WebSocket connection.