| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const nio = @import("nio"); |
| 4 | const nfs = @import("nfs"); |
| 4 | 5 | const sys_linux = @import("sys-linux"); |
| 5 | 6 | |
| 6 | 7 | const os = builtin.target.os.tag; |
| ... | ... | @@ -10,6 +11,8 @@ const sys = switch (os) { |
| 10 | 11 | else => @compileError("TODO"), |
| 11 | 12 | }; |
| 12 | 13 | |
| 14 | pub const off_t = sys.off_t; |
| 15 | |
| 13 | 16 | pub const Address = extern union { |
| 14 | 17 | any: sys.struct_sockaddr, |
| 15 | 18 | in: Ip4Address, |
| ... | ... | @@ -133,6 +136,16 @@ pub const Stream = struct { |
| 133 | 136 | return sys.shutdown(@intCast(@intFromEnum(s.socket)), how); |
| 134 | 137 | } |
| 135 | 138 | |
| 139 | pub fn sendfile(s: Stream, file: nfs.File, offset: off_t, count: ?usize) !void { |
| 140 | const count_actual = count orelse (try file.stat()).size; |
| 141 | var total: u63 = 0; |
| 142 | while (total < count_actual) { |
| 143 | const len = try sys.sendfile(@intCast(@intFromEnum(s.socket)), @intFromEnum(file.fd), &(offset + total), count_actual - total); |
| 144 | total += @intCast(len); |
| 145 | if (len == 0) break; |
| 146 | } |
| 147 | } |
| 148 | |
| 136 | 149 | pub const ReadError = switch (builtin.target.os.tag) { |
| 137 | 150 | .linux => sys.errno.Error, |
| 138 | 151 | else => @compileError("TODO"), |