lib/sys/src/event/types.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 const sys = @import("../root.zig");
 3 
 4 pub const AcceptError = error{
 5     Canceled,
 6     Again,
 7     Unexpected,
 8 };
 9 
10 pub const CloseError = error{
11     Canceled,
12     Unexpected,
13 };
14 
15 pub const PollError = error{
16     Canceled,
17     Unexpected,
18 };
19 
20 pub const ReadError = error{
21     EOF,
22     Canceled,
23     ConnectionResetByPeer,
24     Unexpected,
25 };
26 
27 pub const RecvError = error{
28     Canceled,
29     ConnectionResetByPeer,
30     Unexpected,
31 };
32 
33 pub const SendError = error{
34     Canceled,
35     BrokenPipe,
36     ConnectionResetByPeer,
37     MessageTooLarge,
38     Unexpected,
39 };
40 
41 pub const WriteError = error{
42     Canceled,
43     BrokenPipe,
44     ConnectionResetByPeer,
45     Unexpected,
46 };
47 
48 /// Record of one UDP message that arrived, read once a UDP receive completes to
49 /// learn who sent the message and whether all of it arrived. A caller hands a
50 /// buffer to the event loop when it arms a receive. The payload byte count
51 /// reports what landed in that armed buffer and stops at its length, and a
52 /// separate flag reports whether the message ran past the end of it. On Linux
53 /// the flag is exact, because the kernel reports the message's full length and
54 /// the receive compares it against the buffer length, while on every other host
55 /// the flag is set whenever the byte count equals the armed buffer's length, so
56 /// a message that exactly fills the buffer reports as truncated.
57 pub const Datagram = struct {
58     address: sys.net.IpAddress,
59     bytes: usize,
60     truncated: bool,
61 };
62 
63 pub const Options = struct {
64     entries: u32 = 256,
65     allocator: std.mem.Allocator = sys.allocator.processAllocator(),
66     awake_clock: sys.time.AwakeClock = .system(),
67 };
68 
69 pub const RunMode = enum {
70     no_wait,
71     once,
72     until_done,
73 };
74 
75 pub const CallbackAction = enum {
76     disarm,
77     rearm,
78 };
79 
80 pub const PollEvent = enum {
81     read,
82 };
83 
84 pub const ReadBuffer = union(enum) {
85     slice: []u8,
86     array: [32]u8,
87 };
88 
89 pub const WriteBuffer = union(enum) {
90     slice: []const u8,
91     array: struct {
92         array: [32]u8,
93         len: usize,
94     },
95 };