A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
websocket_wire_stream.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors.
2
16#ifndef A11_NET_WEBSOCKET_WIRE_STREAM_H_
17#define A11_NET_WEBSOCKET_WIRE_STREAM_H_
18
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <string>
23
24#include <absl/base/nullability.h>
25#include <absl/status/status.h>
26#include <absl/status/statusor.h>
27
30#include "a11/net/http2.h"
31#include "a11/net/wire_stream.h"
32
33namespace a11::net {
34
50
60 private:
61 struct ConstructorToken {};
62
63 public:
74 static absl::StatusOr<std::shared_ptr<WebSocketWireStream>> CreateClient(
75 std::string url, WireStreamOptions options = {},
77
78 explicit WebSocketWireStream(ConstructorToken, std::shared_ptr<State> state)
79 : ChannelWireStream(std::move(state)) {}
80
81 private:
82 static absl::StatusOr<std::shared_ptr<WebSocketWireStream>> CreateAccepted(
83 HttpRequest request, std::shared_ptr<Http2ResponseWriter> response,
85
86 friend class WebSocketWireServer;
87};
88
98 std::string path = "/a11";
99 std::string bind_address = "127.0.0.1";
100 std::uint16_t port = 0;
104
106 absl::Status Validate() const;
107};
108
111 std::function<a11::Task(std::shared_ptr<WebSocketWireStream>)>;
112
121 : public std::enable_shared_from_this<WebSocketWireServer> {
122 public:
130 static absl::StatusOr<std::shared_ptr<WebSocketWireServer>> Create(
131 OnWebSocketStream on_stream, WebSocketServerOptions options = {});
133
135 absl::Status Stop();
137 absl::StatusOr<std::uint16_t> port() const;
139 [[nodiscard]] bool running() const;
141 [[nodiscard]] void* absl_nullable GetImpl() const;
142
143 private:
144 struct State;
145
146 explicit WebSocketWireServer(std::shared_ptr<State> state)
147 : state_(std::move(state)) {}
148
149 std::shared_ptr<State> state_;
150};
151
152} // namespace a11::net
153
154#endif // A11_NET_WEBSOCKET_WIRE_STREAM_H_
Shared WireStream lifecycle and framing for binary channels.
Definition channel_wire_stream.h:55
Accepts inbound WebSocket connections and hands each to a callback.
Definition websocket_wire_stream.h:121
bool running() const
Definition websocket_wire_stream.cc:259
absl::StatusOr< std::uint16_t > port() const
Definition websocket_wire_stream.cc:252
~WebSocketWireServer()
Definition websocket_wire_stream.cc:239
absl::Status Stop()
Stops the server and closes the listening socket.
Definition websocket_wire_stream.cc:243
void *absl_nullable GetImpl() const
Definition websocket_wire_stream.cc:264
static absl::StatusOr< std::shared_ptr< WebSocketWireServer > > Create(OnWebSocketStream on_stream, WebSocketServerOptions options={})
Starts a WebSocket server accepting A11 connections.
Definition websocket_wire_stream.cc:184
A WireStream that carries A11 traffic over a client or accepted WebSocket.
Definition websocket_wire_stream.h:59
WebSocketWireStream(ConstructorToken, std::shared_ptr< State > state)
Definition websocket_wire_stream.h:78
static absl::StatusOr< std::shared_ptr< WebSocketWireStream > > CreateClient(std::string url, WireStreamOptions options={}, WebSocketClientOptions websocket_options={})
Dials a WebSocket endpoint and returns a WireStream over it.
Definition websocket_wire_stream.cc:115
Completion values used by every asynchronous A11 operation.
A11's nghttp2 HTTP/2 client, server, and streaming primitives.
Definition action.h:46
std::function< a11::Task(std::shared_ptr< WebSocketWireStream >)> OnWebSocketStream
Callback invoked with a fresh WireStream for each accepted connection.
Definition websocket_wire_stream.h:111
std::vector< std::pair< std::string, std::string > > HttpHeaders
An ordered list of (name, value) HTTP/2 header fields.
Definition http2.h:45
Future< Unit > Task
Asynchronous operation whose only successful result is completion itself.
Definition future.h:403
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
Packetisation and incomplete-message bounds for a binary WireStream.
Definition channel_wire_stream.h:32
Body-size limits, buffering thresholds, deadline, and TLS for an HTTP/2 client or server.
Definition http2.h:103
A parsed HTTP/2 request: pseudo-headers, fields, and body.
Definition http2.h:64
Client-side tuning for a WebSocketWireStream connection.
Definition websocket_wire_stream.h:42
HttpHeaders headers
Extra WebSocket handshake headers.
Definition websocket_wire_stream.h:44
absl::Status Validate() const
Definition websocket_wire_stream.cc:108
ChannelFramingOptions framing
Packet splitting and reassembly bounds.
Definition websocket_wire_stream.h:45
Http2Options http2_options
HTTP/2 connection and TLS policy.
Definition websocket_wire_stream.h:43
Listen address, path, and per-stream defaults for a WebSocketWireServer.
Definition websocket_wire_stream.h:97
std::uint16_t port
Listen port; zero requests an ephemeral port.
Definition websocket_wire_stream.h:100
std::string bind_address
Local listen address.
Definition websocket_wire_stream.h:99
ChannelFramingOptions framing
Framing for accepted streams.
Definition websocket_wire_stream.h:102
Http2Options http2_options
Server HTTP/2 and TLS policy.
Definition websocket_wire_stream.h:103
std::string path
WebSocket endpoint path.
Definition websocket_wire_stream.h:98
WireStreamOptions stream_options
Defaults for accepted streams.
Definition websocket_wire_stream.h:101
absl::Status Validate() const
Definition websocket_wire_stream.cc:158
Definition websocket_wire_stream.cc:172
Buffering, sizing, and deadline limits for a WireStream endpoint.
Definition wire_stream.h:44
A11's transport abstraction: the bidirectional WireStream channel and the options/callbacks that driv...