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 @@...@@ -1,4 +1,11 @@
1const std = @import("std");1const 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
3const nio = @import("./nio.zig");10const nio = @import("./nio.zig");
4const AnyWritable = @This();11const AnyWritable = @This();
...@@ -13,6 +20,15 @@ pub usingnamespace nio.Writable(@This(), ._const);...@@ -13,6 +20,15 @@ pub usingnamespace nio.Writable(@This(), ._const);
13pub fn write(r: AnyWritable, buffer: []const u8) !usize {20pub fn write(r: AnyWritable, buffer: []const u8) !usize {
14 return r.vtable.write(r.state, buffer);21 return r.vtable.write(r.state, buffer);
15}22}
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}
16pub fn anyWritable(r: AnyWritable) AnyWritable {32pub fn anyWritable(r: AnyWritable) AnyWritable {
17 return r;33 return r;
18}34}