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