authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-12 13:40:18 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-12 13:40:18 -07:00
logf9dae4229a9654fc124424333e0c0909834b6b8b
tree8e7f143116f09b01f0b43dd9c96f5e82d7efd621
parentc4de3cf339352f0885a4a3008e5c041fd7b5a16a
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

AnyWritable: add writev


1 files changed, 16 insertions(+), 0 deletions(-)

AnyWritable.zig+16
......@@ -1,4 +1,11 @@
11const std = @import("std");
2const builtin = @import("builtin");
3const sys_linux = @import("sys-linux");
4
5const sys = switch (builtin.target.os.tag) {
6 .linux => sys_linux,
7 else => unreachable,
8};
29
310const nio = @import("./nio.zig");
411const AnyWritable = @This();
......@@ -13,6 +20,15 @@ pub usingnamespace nio.Writable(@This(), ._const);
1320pub fn write(r: AnyWritable, buffer: []const u8) !usize {
1421 return r.vtable.write(r.state, buffer);
1522}
23pub fn writev(w: AnyWritable, iovec: []const sys.struct_iovec) WriteError!usize {
24 var total: usize = 0;
25 for (iovec) |vec| {
26 const len = try write(w, vec.base[0..vec.len]);
27 total += len;
28 if (len != vec.len) break;
29 }
30 return total;
31}
1632pub fn anyWritable(r: AnyWritable) AnyWritable {
1733 return r;
1834}