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