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
44class WebSocket {
45 public:
46 static absl::StatusOr<WebSocket> Create(Role role, Options options = {});
47 static absl::StatusOr<std::unique_ptr<WebSocket>> CreateUnique(
48 Role role, Options options = {});
50 WebSocket(WebSocket&& other) noexcept;
51 WebSocket& operator=(WebSocket&& other) noexcept;
52 WebSocket(const WebSocket&) = delete;
53 WebSocket& operator=(const WebSocket&) = delete;
54
55 absl::Status Feed(std::string_view bytes);
56 absl::StatusOr<std::string> TakeOutput();
57 absl::Status Send(std::string_view message);
58 absl::StatusOr<std::optional<std::string>> Receive();
59 absl::Status Close();
60 void Abort();
61 bool open() const;
62 bool closed() const;
63 std::size_t buffered_amount() const;
64
65 private:
66 struct State;
67 explicit WebSocket(std::unique_ptr<State> state);
68 std::unique_ptr<State> state_;
69};
70
71} // namespace symbian::websocket
72#endif // SYMBIAN_WEBSOCKET_WEBSOCKET_H_
Single-owner RFC 8441 WebSocket endpoint over nghttp2.
Definition websocket.h:44
bool closed() const
Definition websocket.cc:287
static absl::StatusOr< std::unique_ptr< WebSocket > > CreateUnique(Role role, Options options={})
Definition websocket.cc:195
absl::StatusOr< std::string > TakeOutput()
Definition websocket.cc:218
std::size_t buffered_amount() const
Definition websocket.cc:291
WebSocket & operator=(const WebSocket &)=delete
void Abort()
Definition websocket.cc:276
absl::StatusOr< std::optional< std::string > > Receive()
Definition websocket.cc:241
WebSocket & operator=(WebSocket &&other) noexcept
absl::Status Close()
Definition websocket.cc:256
WebSocket(const WebSocket &)=delete
absl::Status Feed(std::string_view bytes)
Definition websocket.cc:206
WebSocket(WebSocket &&other) noexcept
bool open() const
Definition websocket.cc:282
static absl::StatusOr< WebSocket > Create(Role role, Options options={})
Definition websocket.cc:172
absl::Status Send(std::string_view message)
Definition websocket.cc:226
Definition framing.h:36
Role
Definition websocket.h:20
std::string_view bytes
Definition exports.cc:76
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:15