Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
websocket.h
Go to the documentation of this file.
1// Copyright 2026 The Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0.
3#ifndef SYMBIAN_WEBSOCKET_WEBSOCKET_H_
4#define SYMBIAN_WEBSOCKET_WEBSOCKET_H_
5
6#include <array>
7#include <cstddef>
8#include <cstdint>
9#include <functional>
10#include <memory>
11#include <optional>
12#include <string>
13#include <string_view>
14
15#include "absl/status/status.h"
16#include "absl/status/statusor.h"
17
18namespace symbian::websocket {
19
20enum class Role { kClient, kServer };
21
22struct Options {
23 // Required for clients; invoked only by native work on the owner thread.
24 std::function<absl::StatusOr<std::array<std::uint8_t, 4>>()> mask_provider;
25 std::string path = "/symbian-agent";
26 std::string authority = "symbian";
27 std::size_t maximum_message_bytes = 4100;
28 std::size_t maximum_buffered_bytes = 65536;
29};
30
42class WebSocket {
43 public:
44 static absl::StatusOr<std::unique_ptr<WebSocket>> Create(
45 Role role, Options options = {});
47 WebSocket(const WebSocket&) = delete;
48 WebSocket& operator=(const WebSocket&) = delete;
49
50 absl::Status Feed(std::string_view bytes);
51 absl::StatusOr<std::string> TakeOutput();
52 absl::Status Send(std::string_view message);
53 absl::StatusOr<std::optional<std::string>> Receive();
54 absl::Status Close();
55 void Abort();
56 bool open() const;
57 bool closed() const;
58 std::size_t buffered_amount() const;
59
60 private:
61 struct State;
62 explicit WebSocket(std::unique_ptr<State> state);
63 std::unique_ptr<State> state_;
64};
65
66} // namespace symbian::websocket
67#endif // SYMBIAN_WEBSOCKET_WEBSOCKET_H_
Single-owner RFC 8441 WebSocket endpoint over nghttp2.
Definition websocket.h:42
bool closed() const
Definition websocket.cc:273
absl::StatusOr< std::string > TakeOutput()
Definition websocket.cc:211
std::size_t buffered_amount() const
Definition websocket.cc:277
WebSocket & operator=(const WebSocket &)=delete
void Abort()
Definition websocket.cc:265
absl::StatusOr< std::optional< std::string > > Receive()
Definition websocket.cc:232
absl::Status Close()
Definition websocket.cc:246
WebSocket(const WebSocket &)=delete
absl::Status Feed(std::string_view bytes)
Definition websocket.cc:199
static absl::StatusOr< std::unique_ptr< WebSocket > > Create(Role role, Options options={})
Definition websocket.cc:173
bool open() const
Definition websocket.cc:269
absl::Status Send(std::string_view message)
Definition websocket.cc:218
Definition framing.h:33
Role
Definition websocket.h:20
std::string_view bytes
Definition exports.cc:74
Definition websocket.h:22
std::function< absl::StatusOr< std::array< std::uint8_t, 4 > >()> mask_provider
Definition websocket.h:24
std::string path
Definition websocket.h:25
std::size_t maximum_message_bytes
Definition websocket.h:27
std::string authority
Definition websocket.h:26
std::size_t maximum_buffered_bytes
Definition websocket.h:28
Definition websocket.cc:11