Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
byte_stream.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_BYTE_STREAM_H_
4#define SYMBIAN_API_CONNECTIVITY_BYTE_STREAM_H_
5#include <algorithm>
6#include <memory>
7
11
14class TcpByteStream final : public net::ByteStream {
15 public:
16 explicit TcpByteStream(TcpClient client) : client_(std::move(client)) {}
17
18 absl::StatusOr<std::size_t> Read(std::span<std::uint8_t> bytes,
19 absl::Time deadline) override {
20 auto count = client_.Receive(
21 bytes.first(std::min<std::size_t>(bytes.size(), 32768)), deadline);
22 // RSocket's KErrEof is an orderly receive shutdown. Disconnect/reset remains
23 // an error; it must not complete an HTTP or TLS body successfully.
24 if (!count.ok() && NativeErrorFromStatus(count.status()) == -25) {
25 return std::size_t{0};
26 }
27 return count;
28 }
29
30 absl::Status Write(std::span<const std::uint8_t> bytes,
31 absl::Time deadline) override {
32 while (!bytes.empty()) {
33 auto count = std::min<std::size_t>(bytes.size(), 32768);
34 auto status = client_.Send(bytes.first(count), deadline);
35 if (!status.ok()) {
36 return status;
37 }
38 bytes = bytes.subspan(count);
39 }
40 return absl::OkStatus();
41 }
42
43 void Close() override { client_.Close(); }
44
45 private:
46 TcpClient client_;
47};
48} // namespace symbian::api::connectivity
49#endif
Owning TCP transport for both HTTP and WebSocket streams.
Definition byte_stream.h:14
void Close() override
Definition byte_stream.h:43
absl::Status Write(std::span< const std::uint8_t > bytes, absl::Time deadline) override
Definition byte_stream.h:30
TcpByteStream(TcpClient client)
Definition byte_stream.h:16
absl::StatusOr< std::size_t > Read(std::span< std::uint8_t > bytes, absl::Time deadline) override
Definition byte_stream.h:18
One connected IPv4 TCP stream backed by Symbian RSocket.
Definition tcp_client.h:31
absl::Status Send(std::span< const std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture())
Complete one native send request of at most 32 KiB by a deadline.
Definition tcp_client.cc:97
absl::StatusOr< std::size_t > Receive(std::span< std::uint8_t > bytes, absl::Time deadline=absl::InfiniteFuture())
Receive at least one byte into a buffer of at most 32 KiB.
Definition tcp_client.cc:115
void Close()
Close on the owner thread; repeated calls are harmless.
Definition tcp_client.cc:85
Single-owner transport shared by HTTP and WebSocket connections.
Definition byte_stream.h:19
Definition exception_count.cc:8
Definition active_tcp_listener.cc:11
int NativeErrorFromStatus(const absl::Status &status)
Definition native_status.h:88
std::string_view bytes
Definition exports.cc:74