A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
in_process_wire_stream.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors.
2
17#ifndef A11_NET_IN_PROCESS_WIRE_STREAM_H_
18#define A11_NET_IN_PROCESS_WIRE_STREAM_H_
19
20#include <memory>
21#include <optional>
22#include <string>
23#include <utility>
24
25#include <absl/base/nullability.h>
26#include <absl/status/status.h>
27#include <absl/status/statusor.h>
28#include <absl/time/time.h>
29
31#include "a11/data/types.h"
32#include "a11/net/wire_stream.h"
33
34namespace a11::net {
35
45 private:
46 struct State;
47
48 struct ConstructorToken {};
49
50 public:
52 using Pair = std::pair<std::shared_ptr<InProcessWireStream>,
53 std::shared_ptr<InProcessWireStream>>;
54
67 static absl::StatusOr<Pair> CreatePair(
68 std::optional<WireStreamOptions> options = std::nullopt,
69 std::optional<WireStreamOptions> first_options = std::nullopt,
70 std::optional<WireStreamOptions> second_options = std::nullopt,
71 std::string preassigned_id = {});
72
73 ~InProcessWireStream() override = default;
74
77
78 absl::Status Send(data::WireMessage message) override;
79 a11::Task Start(OnMessage on_message, OnDone on_done) override;
80 a11::Task Accept(OnMessage on_message, OnDone on_done) override;
81 absl::Status HalfClose(data::ByteMap trailers) override;
83 absl::Status Abort(absl::Status status) override;
84 absl::Status SetDeadline(absl::Time deadline) override;
85
88 a11::Task Done() const;
89
90 [[nodiscard]] absl::Time deadline() const override;
91 [[nodiscard]] absl::Status GetStatus() const override;
92 [[nodiscard]] std::optional<data::ByteMap> GetTrailers() const override;
93 [[nodiscard]] std::string GetId() const override;
94 [[nodiscard]] void* absl_nullable GetImpl() const override;
95
96 explicit InProcessWireStream(ConstructorToken, std::shared_ptr<State> state)
97 : state_(std::move(state)) {}
98
99 private:
100 a11::Task StartEndpoint(OnMessage on_message, OnDone on_done);
101 static void Sender(std::shared_ptr<State> state);
102 static void Receiver(std::shared_ptr<State> state);
103 static void WatchTiming(std::shared_ptr<State> state);
104 static void MarkActivity(const std::shared_ptr<State>& first,
105 const std::shared_ptr<State>& second);
106 static bool ForceAbort(const std::shared_ptr<State>& state,
107 absl::Status status);
108 static void MaybeFinish(const std::shared_ptr<State>& state);
109 static void Finish(const std::shared_ptr<State>& state);
110
111 std::shared_ptr<State> state_;
112};
113
114} // namespace a11::net
115
116#endif // A11_NET_IN_PROCESS_WIRE_STREAM_H_
A WireStream endpoint wired directly to a peer in the same process.
Definition in_process_wire_stream.h:44
~InProcessWireStream() override=default
absl::Status Send(data::WireMessage message) override
Enqueue a message for delivery to the peer.
Definition in_process_wire_stream.cc:163
std::pair< std::shared_ptr< InProcessWireStream >, std::shared_ptr< InProcessWireStream > > Pair
A connected pair of endpoints returned by CreatePair().
Definition in_process_wire_stream.h:53
absl::Status Abort(absl::Status status) override
Abort the stream, discarding buffered work.
Definition in_process_wire_stream.cc:315
std::string GetId() const override
Definition in_process_wire_stream.cc:390
a11::Task Done() const
Definition in_process_wire_stream.cc:361
absl::Status SetDeadline()
Clear any deadline (equivalent to an infinite deadline).
Definition wire_stream.h:154
absl::Status HalfClose()
Half-close with no trailers.
Definition wire_stream.h:125
static absl::StatusOr< Pair > CreatePair(std::optional< WireStreamOptions > options=std::nullopt, std::optional< WireStreamOptions > first_options=std::nullopt, std::optional< WireStreamOptions > second_options=std::nullopt, std::string preassigned_id={})
Creates a connected pair of in-process endpoints.
Definition in_process_wire_stream.cc:120
a11::Task Accept(OnMessage on_message, OnDone on_done) override
Begin the stream as the accepting ("accept") side.
Definition in_process_wire_stream.cc:233
a11::Task DrainOutgoingMessages() override
Await delivery of all buffered outbound messages.
Definition in_process_wire_stream.cc:300
std::optional< data::ByteMap > GetTrailers() const override
Definition in_process_wire_stream.cc:385
absl::Time deadline() const override
Definition in_process_wire_stream.cc:365
void *absl_nullable GetImpl() const override
Definition in_process_wire_stream.cc:394
a11::Task Start(OnMessage on_message, OnDone on_done) override
Begin the stream as the initiating ("start") side.
Definition in_process_wire_stream.cc:229
InProcessWireStream(ConstructorToken, std::shared_ptr< State > state)
Definition in_process_wire_stream.h:96
absl::Status GetStatus() const override
Definition in_process_wire_stream.cc:370
A bidirectional, message-oriented channel between two A11 endpoints.
Definition wire_stream.h:89
absl::Status SetDeadline()
Clear any deadline (equivalent to an infinite deadline).
Definition wire_stream.h:154
absl::Status HalfClose()
Half-close with no trailers.
Definition wire_stream.h:125
Completion values used by every asynchronous A11 operation.
absl::flat_hash_map< std::string, Bytes > ByteMap
String-keyed map of byte values (headers, attributes, etc.).
Definition types.h:42
Definition action.h:46
std::function< a11::Task(std::optional< data::WireMessage > message)> OnMessage
Called for each inbound message; std::nullopt signals the peer half-closed.
Definition wire_stream.h:65
std::function< a11::Task()> OnDone
Called once, when the stream has fully finished (cleanly or via abort).
Definition wire_stream.h:67
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30
The top-level frame exchanged between two A11 endpoints.
Definition types.h:275
Definition in_process_wire_stream.cc:70
A11's core wire value types: chunks, node fragments and messages.
A11's transport abstraction: the bidirectional WireStream channel and the options/callbacks that driv...