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_API_CONNECTIVITY_WEBSOCKET_H_
4#define SYMBIAN_API_CONNECTIVITY_WEBSOCKET_H_
5#include <memory>
6#include <span>
7#include <string>
8#include <utility>
9
10#include "absl/time/time.h"
14
25 public:
26 static absl::StatusOr<WebSocketStream> Connect(
27 TcpClient client, websocket::Options options,
28 absl::Time deadline = absl::InfiniteFuture());
29 static absl::StatusOr<WebSocketStream> Accept(
30 TcpClient client, websocket::Options options = {},
31 absl::Time deadline = absl::InfiniteFuture());
32 static absl::StatusOr<WebSocketStream> Connect(
33 std::unique_ptr<net::ByteStream> transport, websocket::Options options,
34 absl::Time deadline = absl::InfiniteFuture());
35 static absl::StatusOr<WebSocketStream> Accept(
36 std::unique_ptr<net::ByteStream> transport,
37 websocket::Options options = {},
38 absl::Time deadline = absl::InfiniteFuture());
39 WebSocketStream(WebSocketStream&&) noexcept = default;
40 WebSocketStream& operator=(WebSocketStream&&) noexcept = default;
41 absl::Status Send(std::span<const std::uint8_t> bytes,
42 absl::Time deadline = absl::InfiniteFuture());
43 absl::StatusOr<std::size_t> Receive(
44 std::span<std::uint8_t> bytes,
45 absl::Time deadline = absl::InfiniteFuture());
46 absl::Status Close(absl::Time deadline);
47 void Abort();
48
49 private:
50 WebSocketStream(std::unique_ptr<net::ByteStream> transport,
51 std::unique_ptr<websocket::WebSocket> codec);
52 static absl::StatusOr<WebSocketStream> Open(
53 std::unique_ptr<net::ByteStream> transport, websocket::Role role,
54 websocket::Options options, absl::Time deadline);
55 absl::Status Flush(absl::Time deadline);
56 absl::Status Pump(absl::Time deadline);
57 std::unique_ptr<net::ByteStream> transport_;
58 std::unique_ptr<websocket::WebSocket> codec_;
59 std::string pending_;
60 std::size_t offset_ = 0;
61};
62
65 public:
66 static absl::StatusOr<WebSocketServer> ListenIpv4(
67 std::array<std::uint8_t, 4> address, std::uint16_t port,
68 websocket::Options options = {});
69 absl::StatusOr<WebSocketStream> Accept(absl::Time deadline);
70
71 private:
73 : listener_(std::move(listener)), options_(std::move(options)) {}
74
75 TcpListener listener_;
76 websocket::Options options_;
77};
78} // namespace symbian::api::connectivity
79#endif
One connected IPv4 TCP stream backed by Symbian RSocket.
Definition tcp_client.h:31
One bounded IPv4 listener backed by Symbian RSocket.
Definition tcp_listener.h:28
Reusable bounded IPv4 WebSocket listener on a worker thread.
Definition websocket.h:64
Synchronous worker-owned WebSocket using the SDK TCP runtime.
Definition websocket.h:24
static absl::StatusOr< WebSocketStream > Connect(TcpClient client, websocket::Options options, absl::Time deadline=absl::InfiniteFuture())
Definition websocket.cc:14
void Abort()
Definition websocket.cc:162
static absl::StatusOr< WebSocketStream > Accept(TcpClient client, websocket::Options options={}, absl::Time deadline=absl::InfiniteFuture())
Definition websocket.cc:20
WebSocketStream(WebSocketStream &&) noexcept=default
absl::Status Close(absl::Time deadline)
Definition websocket.cc:143
absl::Status Send(std::span< const std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture())
Definition websocket.cc:104
absl::StatusOr< std::size_t > Receive(std::span< std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture())
Definition websocket.cc:111
Definition exception_count.cc:8
Definition active_tcp_listener.cc:11
uint32_t address
Definition exports.cc:69
std::string_view bytes
Definition exports.cc:74
Definition websocket.h:22