| ... | ... | @@ -10,6 +10,9 @@ const os = builtin.target.os.tag; |
| 10 | 10 | |
| 11 | 11 | const sys = switch (os) { |
| 12 | 12 | .linux => sys_linux, |
| 13 | .freebsd => @import("sys-freebsd"), |
| 14 | .netbsd => @import("sys-netbsd"), |
| 15 | .openbsd => @import("sys-openbsd"), |
| 13 | 16 | else => @compileError("TODO"), |
| 14 | 17 | }; |
| 15 | 18 | |
| ... | ... | @@ -164,6 +167,9 @@ pub const Ip6Address = extern struct { |
| 164 | 167 | |
| 165 | 168 | pub const Socket = switch (os) { |
| 166 | 169 | .linux => enum(c_uint) { _ }, |
| 170 | .freebsd => enum(c_uint) { _ }, |
| 171 | .netbsd => enum(c_uint) { _ }, |
| 172 | .openbsd => enum(c_uint) { _ }, |
| 167 | 173 | else => @compileError("TODO"), |
| 168 | 174 | }; |
| 169 | 175 | |
| ... | ... | @@ -180,6 +186,21 @@ pub const Stream = struct { |
| 180 | 186 | } |
| 181 | 187 | |
| 182 | 188 | pub fn sendfile(s: Stream, file: nfs.File, offset: off_t, count: ?usize) !void { |
| 189 | switch (os) { |
| 190 | .freebsd, |
| 191 | .netbsd, |
| 192 | .openbsd, |
| 193 | => { |
| 194 | const count_actual = count orelse (try file.stat()).size; |
| 195 | const region = try file.mmapRegion(offset, count_actual); |
| 196 | defer nfs.munmap(region); |
| 197 | try s.writeAll(region); |
| 198 | return; |
| 199 | }, |
| 200 | .linux, |
| 201 | => {}, |
| 202 | else => comptime unreachable, |
| 203 | } |
| 183 | 204 | const count_actual = count orelse (try file.stat()).size; |
| 184 | 205 | var total: u63 = 0; |
| 185 | 206 | while (total < count_actual) { |
| ... | ... | @@ -204,10 +225,7 @@ pub const Stream = struct { |
| 204 | 225 | pub const readInt = R.readInt; |
| 205 | 226 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 206 | 227 | |
| 207 | | pub const ReadError = switch (builtin.target.os.tag) { |
| 208 | | .linux => sys.errno.Error, |
| 209 | | else => @compileError("TODO"), |
| 210 | | }; |
| 228 | pub const ReadError = sys.errno.Error; |
| 211 | 229 | pub fn read(s: Stream, buffer: []u8) ReadError!usize { |
| 212 | 230 | return sys.recv(@intFromEnum(s.socket), buffer, 0); |
| 213 | 231 | } |
| ... | ... | @@ -234,10 +252,7 @@ pub const Stream = struct { |
| 234 | 252 | pub const writeIntPretty = W.writeIntPretty; |
| 235 | 253 | pub const print = W.print; |
| 236 | 254 | |
| 237 | | pub const WriteError = switch (builtin.target.os.tag) { |
| 238 | | .linux => sys.errno.Error, |
| 239 | | else => @compileError("TODO"), |
| 240 | | }; |
| 255 | pub const WriteError = sys.errno.Error; |
| 241 | 256 | pub fn write(s: Stream, bytes: []const u8) WriteError!usize { |
| 242 | 257 | return sys.send(@intFromEnum(s.socket), bytes, 0); |
| 243 | 258 | } |