tiny.http.ClientWebSocketStorage
Defined in tiny.http.
API (12)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/http/src/client/websocket/storage.zig:11
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: model.Capacity, bytes: []u8, pub const Limits: type = model.Limits; pub const Capacity: type = model.Capacity; pub const Exhaustion: type = StorageExhaustion; pub const InitError = std.mem.Allocator.Error || error{CapacityOverflow}; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "http.client_websocket_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "one_fixed_inbound_wire_frame_region_for_every_client_websocket", .lifetime = .steady, .detail = "one fixed inbound wire-frame region for every client WebSocket", }, .{ .id = "one_fixed_masked_outbound_wire_frame_region_for_eve_72613139f624", .lifetime = .steady, .detail = "one fixed masked outbound wire-frame region for every client WebSocket", }, }, .excluded = &.{ "URL preparation, HTTP upgrade headers, TLS state, certificate bundles, sockets, and kernel queues", "application payload owners and protocol effects", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "websocket_count", "websocket_count"), alloc_phase.capacity.bindInput(Limits, "frame_payload_bytes_per_websocket", "frame_payload_bytes_per_websocket"), }, .type_selectors = &.{}, .nodes = &.{ .{ .input = 0 }, .{ .scale = .{ .node = 0, .coefficient = .{ .literal = 2 } } }, .{ .constant = 14 }, .{ .input = 1 }, .{ .add = .{ .left = 2, .right = 3 } }, .{ .product = .{ .left = 1, .right = 4 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 5, }}, }, .overload = .{ .kind = .terminal, .detail = "capacity exhaustion rejects before opening a WebSocket or publishing a frame", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "WebSocket frame send and receive allocate no storage after activation", }, .foreign = .{ .status = .excluded, .detail = "TLS and operating-system network owners remain independent", }, }, .obligations = &.{ .{ .key = "http_client_websocket_capacity", .role = .capacity_model }, .{ .key = "http_client_websocket_oom_retry", .role = .custom }, .{ .key = "http_client_websocket_partition", .role = .overload }, .{ .key = "http_client_websocket_sealed", .role = .transitive_risk }, .{ .key = "http_client_websocket_network_overload", .role = .overload }, .{ .key = "http_client_websocket_network_transitive_risk", .role = .transitive_risk }, .{ .key = "http_client_websocket_network_foreign_risk", .role = .foreign_risk }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; pub fn init( allocator: std.mem.Allocator, limits: Limits, ) InitError!Storage { const capacity = try Capacity.derive(limits); const bytes = if (capacity.storage_bytes == 0) @as([]u8, &.{}) else try allocator.alloc(u8, capacity.storage_bytes); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); std.debug.assert( self.bytes.len == self.capacity.storage_bytes, ); self.phase = .steady; } pub fn websocket( self: *Storage, index: usize, ) StorageExhaustion!Scratch { std.debug.assert(self.phase == .steady); if (index >= self.capacity.websocket_count) { return error.ClientWebSocketCapacityExceeded; } const frame_bytes = self.capacity.frame_bytes_per_websocket; const read_start = index * frame_bytes; const write_region_start = self.capacity.websocket_count * frame_bytes; const write_start = write_region_start + index * frame_bytes; return .{ .read = self.bytes[read_start..][0..frame_bytes], .write = self.bytes[write_start..][0..frame_bytes], .frame_payload_bytes = self.capacity.frame_payload_bytes_per_websocket, }; } pub fn deinit( self: *Storage, allocator: std.mem.Allocator, ) void { std.debug.assert(self.phase != .teardown); std.debug.assert( self.bytes.len == self.capacity.storage_bytes, ); self.phase = .teardown; if (self.bytes.len != 0) allocator.free(self.bytes); self.bytes = &.{}; }};Source: lib/http/src/root.zig:82
zig
pub const ClientWebSocketStorage = client.WebSocketStorage;Audit
| Definitions | 10 |
|---|---|
| Public names | 10 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |