| author | |
| committer | |
| log | 9d4eaf1e07525a72fa54cfaa346a18bf18953af4 |
| tree | ccac84631127e309d5fb500c4407e8e40c444aff |
| parent | ba78ae0ae73ac38a2bb32c618cd145b4d2f9602e |
| signature | Commit is signed but in an unrecognized format. |
std.io.FileInStream -> std.os.File.InStream
std.io.FileInStream.init(file) -> file.inStream()
std.io.FileOutStream -> std.os.File.OutStream
std.io.FileOutStream.init(file) -> file.outStream()
remove a lot of error code possibilities from os functions
std.event.net.socketRead -> std.event.net.read
std.event.net.socketWrite -> std.event.net.write
add std.event.net.readv
add std.event.net.writev
add std.event.net.readvPosix
add std.event.net.writevPosix
add std.event.net.OutStream
add std.event.net.InStream
add std.event.io.InStream
add std.event.io.OutStream28 files changed, 437 insertions(+), 257 deletions(-)
CMakeLists.txt+1| ... | @@ -470,6 +470,7 @@ set(ZIG_STD_FILES | ... | @@ -470,6 +470,7 @@ set(ZIG_STD_FILES |
| 470 | "event/fs.zig" | 470 | "event/fs.zig" |
| 471 | "event/future.zig" | 471 | "event/future.zig" |
| 472 | "event/group.zig" | 472 | "event/group.zig" |
| 473 | "event/io.zig" | ||
| 473 | "event/lock.zig" | 474 | "event/lock.zig" |
| 474 | "event/locked.zig" | 475 | "event/locked.zig" |
| 475 | "event/loop.zig" | 476 | "event/loop.zig" |
doc/docgen.zig+3-3| ... | @@ -41,12 +41,12 @@ pub fn main() !void { | ... | @@ -41,12 +41,12 @@ pub fn main() !void { |
| 41 | var out_file = try os.File.openWrite(out_file_name); | 41 | var out_file = try os.File.openWrite(out_file_name); |
| 42 | defer out_file.close(); | 42 | defer out_file.close(); |
| 43 | 43 | ||
| 44 | var file_in_stream = io.FileInStream.init(in_file); | 44 | var file_in_stream = in_file.inStream(); |
| 45 | 45 | ||
| 46 | const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size); | 46 | const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size); |
| 47 | 47 | ||
| 48 | var file_out_stream = io.FileOutStream.init(out_file); | 48 | var file_out_stream = out_file.outStream(); |
| 49 | var buffered_out_stream = io.BufferedOutStream(io.FileOutStream.Error).init(&file_out_stream.stream); | 49 | var buffered_out_stream = io.BufferedOutStream(os.File.WriteError).init(&file_out_stream.stream); |
| 50 | 50 | ||
| 51 | var tokenizer = Tokenizer.init(in_file_name, input_file_bytes); | 51 | var tokenizer = Tokenizer.init(in_file_name, input_file_bytes); |
| 52 | var toc = try genToc(allocator, &tokenizer); | 52 | var toc = try genToc(allocator, &tokenizer); |
example/guess_number/main.zig+1-2| ... | @@ -6,8 +6,7 @@ const os = std.os; | ... | @@ -6,8 +6,7 @@ const os = std.os; |
| 6 | 6 | ||
| 7 | pub fn main() !void { | 7 | pub fn main() !void { |
| 8 | var stdout_file = try io.getStdOut(); | 8 | var stdout_file = try io.getStdOut(); |
| 9 | var stdout_file_stream = io.FileOutStream.init(stdout_file); | 9 | const stdout = &stdout_file.outStream().stream; |
| 10 | const stdout = &stdout_file_stream.stream; | ||
| 11 | 10 | ||
| 12 | try stdout.print("Welcome to the Guess Number Game in Zig.\n"); | 11 | try stdout.print("Welcome to the Guess Number Game in Zig.\n"); |
| 13 | 12 |
src-self-hosted/errmsg.zig+1-1| ... | @@ -278,7 +278,7 @@ pub const Msg = struct { | ... | @@ -278,7 +278,7 @@ pub const Msg = struct { |
| 278 | Color.On => true, | 278 | Color.On => true, |
| 279 | Color.Off => false, | 279 | Color.Off => false, |
| 280 | }; | 280 | }; |
| 281 | var stream = &std.io.FileOutStream.init(file).stream; | 281 | var stream = &file.outStream().stream; |
| 282 | return msg.printToStream(stream, color_on); | 282 | return msg.printToStream(stream, color_on); |
| 283 | } | 283 | } |
| 284 | }; | 284 | }; |
src-self-hosted/libc_installation.zig+2-2| ... | @@ -30,7 +30,7 @@ pub const LibCInstallation = struct { | ... | @@ -30,7 +30,7 @@ pub const LibCInstallation = struct { |
| 30 | self: *LibCInstallation, | 30 | self: *LibCInstallation, |
| 31 | allocator: *std.mem.Allocator, | 31 | allocator: *std.mem.Allocator, |
| 32 | libc_file: []const u8, | 32 | libc_file: []const u8, |
| 33 | stderr: *std.io.OutStream(std.io.FileOutStream.Error), | 33 | stderr: *std.io.OutStream(std.os.File.WriteError), |
| 34 | ) !void { | 34 | ) !void { |
| 35 | self.initEmpty(); | 35 | self.initEmpty(); |
| 36 | 36 | ||
| ... | @@ -100,7 +100,7 @@ pub const LibCInstallation = struct { | ... | @@ -100,7 +100,7 @@ pub const LibCInstallation = struct { |
| 100 | } | 100 | } |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(std.io.FileOutStream.Error)) !void { | 103 | pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(std.os.File.WriteError)) !void { |
| 104 | @setEvalBranchQuota(4000); | 104 | @setEvalBranchQuota(4000); |
| 105 | try out.print( | 105 | try out.print( |
| 106 | \\# The directory that contains `stdlib.h`. | 106 | \\# The directory that contains `stdlib.h`. |
src-self-hosted/main.zig+5-5| ... | @@ -21,8 +21,8 @@ const errmsg = @import("errmsg.zig"); | ... | @@ -21,8 +21,8 @@ const errmsg = @import("errmsg.zig"); |
| 21 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; | 21 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 22 | 22 | ||
| 23 | var stderr_file: os.File = undefined; | 23 | var stderr_file: os.File = undefined; |
| 24 | var stderr: *io.OutStream(io.FileOutStream.Error) = undefined; | 24 | var stderr: *io.OutStream(os.File.WriteError) = undefined; |
| 25 | var stdout: *io.OutStream(io.FileOutStream.Error) = undefined; | 25 | var stdout: *io.OutStream(os.File.WriteError) = undefined; |
| 26 | 26 | ||
| 27 | const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB | 27 | const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB |
| 28 | 28 | ||
| ... | @@ -55,11 +55,11 @@ pub fn main() !void { | ... | @@ -55,11 +55,11 @@ pub fn main() !void { |
| 55 | const allocator = std.heap.c_allocator; | 55 | const allocator = std.heap.c_allocator; |
| 56 | 56 | ||
| 57 | var stdout_file = try std.io.getStdOut(); | 57 | var stdout_file = try std.io.getStdOut(); |
| 58 | var stdout_out_stream = std.io.FileOutStream.init(stdout_file); | 58 | var stdout_out_stream = stdout_file.outStream(); |
| 59 | stdout = &stdout_out_stream.stream; | 59 | stdout = &stdout_out_stream.stream; |
| 60 | 60 | ||
| 61 | stderr_file = try std.io.getStdErr(); | 61 | stderr_file = try std.io.getStdErr(); |
| 62 | var stderr_out_stream = std.io.FileOutStream.init(stderr_file); | 62 | var stderr_out_stream = stderr_file.outStream(); |
| 63 | stderr = &stderr_out_stream.stream; | 63 | stderr = &stderr_out_stream.stream; |
| 64 | 64 | ||
| 65 | const args = try os.argsAlloc(allocator); | 65 | const args = try os.argsAlloc(allocator); |
| ... | @@ -619,7 +619,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { | ... | @@ -619,7 +619,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 619 | } | 619 | } |
| 620 | 620 | ||
| 621 | var stdin_file = try io.getStdIn(); | 621 | var stdin_file = try io.getStdIn(); |
| 622 | var stdin = io.FileInStream.init(stdin_file); | 622 | var stdin = stdin_file.inStream(); |
| 623 | 623 | ||
| 624 | const source_code = try stdin.stream.readAllAlloc(allocator, max_src_size); | 624 | const source_code = try stdin.stream.readAllAlloc(allocator, max_src_size); |
| 625 | defer allocator.free(source_code); | 625 | defer allocator.free(source_code); |
std/atomic/queue.zig+1-1| ... | @@ -114,7 +114,7 @@ pub fn Queue(comptime T: type) type { | ... | @@ -114,7 +114,7 @@ pub fn Queue(comptime T: type) type { |
| 114 | 114 | ||
| 115 | fn dumpRecursive(optional_node: ?*Node, indent: usize) void { | 115 | fn dumpRecursive(optional_node: ?*Node, indent: usize) void { |
| 116 | var stderr_file = std.io.getStdErr() catch return; | 116 | var stderr_file = std.io.getStdErr() catch return; |
| 117 | const stderr = &std.io.FileOutStream.init(stderr_file).stream; | 117 | const stderr = &stderr_file.outStream().stream; |
| 118 | stderr.writeByteNTimes(' ', indent) catch return; | 118 | stderr.writeByteNTimes(' ', indent) catch return; |
| 119 | if (optional_node) |node| { | 119 | if (optional_node) |node| { |
| 120 | std.debug.warn("0x{x}={}\n", @ptrToInt(node), node.data); | 120 | std.debug.warn("0x{x}={}\n", @ptrToInt(node), node.data); |
std/coff.zig+4-4| ... | @@ -41,7 +41,7 @@ pub const Coff = struct { | ... | @@ -41,7 +41,7 @@ pub const Coff = struct { |
| 41 | pub fn loadHeader(self: *Coff) !void { | 41 | pub fn loadHeader(self: *Coff) !void { |
| 42 | const pe_pointer_offset = 0x3C; | 42 | const pe_pointer_offset = 0x3C; |
| 43 | 43 | ||
| 44 | var file_stream = io.FileInStream.init(self.in_file); | 44 | var file_stream = self.in_file.inStream(); |
| 45 | const in = &file_stream.stream; | 45 | const in = &file_stream.stream; |
| 46 | 46 | ||
| 47 | var magic: [2]u8 = undefined; | 47 | var magic: [2]u8 = undefined; |
| ... | @@ -77,7 +77,7 @@ pub const Coff = struct { | ... | @@ -77,7 +77,7 @@ pub const Coff = struct { |
| 77 | try self.loadOptionalHeader(&file_stream); | 77 | try self.loadOptionalHeader(&file_stream); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | fn loadOptionalHeader(self: *Coff, file_stream: *io.FileInStream) !void { | 80 | fn loadOptionalHeader(self: *Coff, file_stream: *os.File.InStream) !void { |
| 81 | const in = &file_stream.stream; | 81 | const in = &file_stream.stream; |
| 82 | self.pe_header.magic = try in.readIntLe(u16); | 82 | self.pe_header.magic = try in.readIntLe(u16); |
| 83 | // For now we're only interested in finding the reference to the .pdb, | 83 | // For now we're only interested in finding the reference to the .pdb, |
| ... | @@ -115,7 +115,7 @@ pub const Coff = struct { | ... | @@ -115,7 +115,7 @@ pub const Coff = struct { |
| 115 | const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; | 115 | const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; |
| 116 | try self.in_file.seekTo(file_offset + debug_dir.size); | 116 | try self.in_file.seekTo(file_offset + debug_dir.size); |
| 117 | 117 | ||
| 118 | var file_stream = io.FileInStream.init(self.in_file); | 118 | var file_stream = self.in_file.inStream(); |
| 119 | const in = &file_stream.stream; | 119 | const in = &file_stream.stream; |
| 120 | 120 | ||
| 121 | var cv_signature: [4]u8 = undefined; // CodeView signature | 121 | var cv_signature: [4]u8 = undefined; // CodeView signature |
| ... | @@ -146,7 +146,7 @@ pub const Coff = struct { | ... | @@ -146,7 +146,7 @@ pub const Coff = struct { |
| 146 | 146 | ||
| 147 | self.sections = ArrayList(Section).init(self.allocator); | 147 | self.sections = ArrayList(Section).init(self.allocator); |
| 148 | 148 | ||
| 149 | var file_stream = io.FileInStream.init(self.in_file); | 149 | var file_stream = self.in_file.inStream(); |
| 150 | const in = &file_stream.stream; | 150 | const in = &file_stream.stream; |
| 151 | 151 | ||
| 152 | var name: [8]u8 = undefined; | 152 | var name: [8]u8 = undefined; |
std/crypto/throughput_test.zig+1-1| ... | @@ -130,7 +130,7 @@ fn printPad(stdout: var, s: []const u8) !void { | ... | @@ -130,7 +130,7 @@ fn printPad(stdout: var, s: []const u8) !void { |
| 130 | 130 | ||
| 131 | pub fn main() !void { | 131 | pub fn main() !void { |
| 132 | var stdout_file = try std.io.getStdOut(); | 132 | var stdout_file = try std.io.getStdOut(); |
| 133 | var stdout_out_stream = std.io.FileOutStream.init(stdout_file); | 133 | var stdout_out_stream = stdout_file.outStream(); |
| 134 | const stdout = &stdout_out_stream.stream; | 134 | const stdout = &stdout_out_stream.stream; |
| 135 | 135 | ||
| 136 | var buffer: [1024]u8 = undefined; | 136 | var buffer: [1024]u8 = undefined; |
std/debug/index.zig+11-11| ... | @@ -34,10 +34,10 @@ const Module = struct { | ... | @@ -34,10 +34,10 @@ const Module = struct { |
| 34 | /// Tries to write to stderr, unbuffered, and ignores any error returned. | 34 | /// Tries to write to stderr, unbuffered, and ignores any error returned. |
| 35 | /// Does not append a newline. | 35 | /// Does not append a newline. |
| 36 | var stderr_file: os.File = undefined; | 36 | var stderr_file: os.File = undefined; |
| 37 | var stderr_file_out_stream: io.FileOutStream = undefined; | 37 | var stderr_file_out_stream: os.File.OutStream = undefined; |
| 38 | 38 | ||
| 39 | /// TODO multithreaded awareness | 39 | /// TODO multithreaded awareness |
| 40 | var stderr_stream: ?*io.OutStream(io.FileOutStream.Error) = null; | 40 | var stderr_stream: ?*io.OutStream(os.File.WriteError) = null; |
| 41 | var stderr_mutex = std.Mutex.init(); | 41 | var stderr_mutex = std.Mutex.init(); |
| 42 | pub fn warn(comptime fmt: []const u8, args: ...) void { | 42 | pub fn warn(comptime fmt: []const u8, args: ...) void { |
| 43 | const held = stderr_mutex.acquire(); | 43 | const held = stderr_mutex.acquire(); |
| ... | @@ -46,12 +46,12 @@ pub fn warn(comptime fmt: []const u8, args: ...) void { | ... | @@ -46,12 +46,12 @@ pub fn warn(comptime fmt: []const u8, args: ...) void { |
| 46 | stderr.print(fmt, args) catch return; | 46 | stderr.print(fmt, args) catch return; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | pub fn getStderrStream() !*io.OutStream(io.FileOutStream.Error) { | 49 | pub fn getStderrStream() !*io.OutStream(os.File.WriteError) { |
| 50 | if (stderr_stream) |st| { | 50 | if (stderr_stream) |st| { |
| 51 | return st; | 51 | return st; |
| 52 | } else { | 52 | } else { |
| 53 | stderr_file = try io.getStdErr(); | 53 | stderr_file = try io.getStdErr(); |
| 54 | stderr_file_out_stream = io.FileOutStream.init(stderr_file); | 54 | stderr_file_out_stream = stderr_file.outStream(); |
| 55 | const st = &stderr_file_out_stream.stream; | 55 | const st = &stderr_file_out_stream.stream; |
| 56 | stderr_stream = st; | 56 | stderr_stream = st; |
| 57 | return st; | 57 | return st; |
| ... | @@ -876,7 +876,7 @@ fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DebugInfo { | ... | @@ -876,7 +876,7 @@ fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DebugInfo { |
| 876 | } | 876 | } |
| 877 | 877 | ||
| 878 | pub fn findElfSection(elf: *Elf, name: []const u8) ?*elf.Shdr { | 878 | pub fn findElfSection(elf: *Elf, name: []const u8) ?*elf.Shdr { |
| 879 | var file_stream = io.FileInStream.init(elf.in_file); | 879 | var file_stream = elf.in_file.inStream(); |
| 880 | const in = &file_stream.stream; | 880 | const in = &file_stream.stream; |
| 881 | 881 | ||
| 882 | section_loop: for (elf.section_headers) |*elf_section| { | 882 | section_loop: for (elf.section_headers) |*elf_section| { |
| ... | @@ -1068,7 +1068,7 @@ pub const DebugInfo = switch (builtin.os) { | ... | @@ -1068,7 +1068,7 @@ pub const DebugInfo = switch (builtin.os) { |
| 1068 | } | 1068 | } |
| 1069 | 1069 | ||
| 1070 | pub fn readString(self: *DebugInfo) ![]u8 { | 1070 | pub fn readString(self: *DebugInfo) ![]u8 { |
| 1071 | var in_file_stream = io.FileInStream.init(self.self_exe_file); | 1071 | var in_file_stream = self.self_exe_file.inStream(); |
| 1072 | const in_stream = &in_file_stream.stream; | 1072 | const in_stream = &in_file_stream.stream; |
| 1073 | return readStringRaw(self.allocator(), in_stream); | 1073 | return readStringRaw(self.allocator(), in_stream); |
| 1074 | } | 1074 | } |
| ... | @@ -1405,7 +1405,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 | ... | @@ -1405,7 +1405,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 1405 | 1405 | ||
| 1406 | fn parseAbbrevTable(st: *DebugInfo) !AbbrevTable { | 1406 | fn parseAbbrevTable(st: *DebugInfo) !AbbrevTable { |
| 1407 | const in_file = st.self_exe_file; | 1407 | const in_file = st.self_exe_file; |
| 1408 | var in_file_stream = io.FileInStream.init(in_file); | 1408 | var in_file_stream = in_file.inStream(); |
| 1409 | const in_stream = &in_file_stream.stream; | 1409 | const in_stream = &in_file_stream.stream; |
| 1410 | var result = AbbrevTable.init(st.allocator()); | 1410 | var result = AbbrevTable.init(st.allocator()); |
| 1411 | while (true) { | 1411 | while (true) { |
| ... | @@ -1456,7 +1456,7 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con | ... | @@ -1456,7 +1456,7 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con |
| 1456 | 1456 | ||
| 1457 | fn parseDie(st: *DebugInfo, abbrev_table: *const AbbrevTable, is_64: bool) !Die { | 1457 | fn parseDie(st: *DebugInfo, abbrev_table: *const AbbrevTable, is_64: bool) !Die { |
| 1458 | const in_file = st.self_exe_file; | 1458 | const in_file = st.self_exe_file; |
| 1459 | var in_file_stream = io.FileInStream.init(in_file); | 1459 | var in_file_stream = in_file.inStream(); |
| 1460 | const in_stream = &in_file_stream.stream; | 1460 | const in_stream = &in_file_stream.stream; |
| 1461 | const abbrev_code = try readULeb128(in_stream); | 1461 | const abbrev_code = try readULeb128(in_stream); |
| 1462 | const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo; | 1462 | const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo; |
| ... | @@ -1682,7 +1682,7 @@ fn getLineNumberInfoLinux(di: *DebugInfo, compile_unit: *const CompileUnit, targ | ... | @@ -1682,7 +1682,7 @@ fn getLineNumberInfoLinux(di: *DebugInfo, compile_unit: *const CompileUnit, targ |
| 1682 | var this_offset = di.debug_line.offset; | 1682 | var this_offset = di.debug_line.offset; |
| 1683 | var this_index: usize = 0; | 1683 | var this_index: usize = 0; |
| 1684 | 1684 | ||
| 1685 | var in_file_stream = io.FileInStream.init(in_file); | 1685 | var in_file_stream = in_file.inStream(); |
| 1686 | const in_stream = &in_file_stream.stream; | 1686 | const in_stream = &in_file_stream.stream; |
| 1687 | 1687 | ||
| 1688 | while (this_offset < debug_line_end) : (this_index += 1) { | 1688 | while (this_offset < debug_line_end) : (this_index += 1) { |
| ... | @@ -1857,7 +1857,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { | ... | @@ -1857,7 +1857,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { |
| 1857 | var this_unit_offset = st.debug_info.offset; | 1857 | var this_unit_offset = st.debug_info.offset; |
| 1858 | var cu_index: usize = 0; | 1858 | var cu_index: usize = 0; |
| 1859 | 1859 | ||
| 1860 | var in_file_stream = io.FileInStream.init(st.self_exe_file); | 1860 | var in_file_stream = st.self_exe_file.inStream(); |
| 1861 | const in_stream = &in_file_stream.stream; | 1861 | const in_stream = &in_file_stream.stream; |
| 1862 | 1862 | ||
| 1863 | while (this_unit_offset < debug_info_end) { | 1863 | while (this_unit_offset < debug_info_end) { |
| ... | @@ -1923,7 +1923,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { | ... | @@ -1923,7 +1923,7 @@ fn scanAllCompileUnits(st: *DebugInfo) !void { |
| 1923 | } | 1923 | } |
| 1924 | 1924 | ||
| 1925 | fn findCompileUnit(st: *DebugInfo, target_address: u64) !*const CompileUnit { | 1925 | fn findCompileUnit(st: *DebugInfo, target_address: u64) !*const CompileUnit { |
| 1926 | var in_file_stream = io.FileInStream.init(st.self_exe_file); | 1926 | var in_file_stream = st.self_exe_file.inStream(); |
| 1927 | const in_stream = &in_file_stream.stream; | 1927 | const in_stream = &in_file_stream.stream; |
| 1928 | for (st.compile_unit_list.toSlice()) |*compile_unit| { | 1928 | for (st.compile_unit_list.toSlice()) |*compile_unit| { |
| 1929 | if (compile_unit.pc_range) |range| { | 1929 | if (compile_unit.pc_range) |range| { |
std/elf.zig+2-2| ... | @@ -381,7 +381,7 @@ pub const Elf = struct { | ... | @@ -381,7 +381,7 @@ pub const Elf = struct { |
| 381 | elf.in_file = file; | 381 | elf.in_file = file; |
| 382 | elf.auto_close_stream = false; | 382 | elf.auto_close_stream = false; |
| 383 | 383 | ||
| 384 | var file_stream = io.FileInStream.init(elf.in_file); | 384 | var file_stream = elf.in_file.inStream(); |
| 385 | const in = &file_stream.stream; | 385 | const in = &file_stream.stream; |
| 386 | 386 | ||
| 387 | var magic: [4]u8 = undefined; | 387 | var magic: [4]u8 = undefined; |
| ... | @@ -525,7 +525,7 @@ pub const Elf = struct { | ... | @@ -525,7 +525,7 @@ pub const Elf = struct { |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader { | 527 | pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader { |
| 528 | var file_stream = io.FileInStream.init(elf.in_file); | 528 | var file_stream = elf.in_file.inStream(); |
| 529 | const in = &file_stream.stream; | 529 | const in = &file_stream.stream; |
| 530 | 530 | ||
| 531 | section_loop: for (elf.section_headers) |*elf_section| { | 531 | section_loop: for (elf.section_headers) |*elf_section| { |
std/event.zig+2| ... | @@ -6,6 +6,7 @@ pub const Locked = @import("event/locked.zig").Locked; | ... | @@ -6,6 +6,7 @@ pub const Locked = @import("event/locked.zig").Locked; |
| 6 | pub const RwLock = @import("event/rwlock.zig").RwLock; | 6 | pub const RwLock = @import("event/rwlock.zig").RwLock; |
| 7 | pub const RwLocked = @import("event/rwlocked.zig").RwLocked; | 7 | pub const RwLocked = @import("event/rwlocked.zig").RwLocked; |
| 8 | pub const Loop = @import("event/loop.zig").Loop; | 8 | pub const Loop = @import("event/loop.zig").Loop; |
| 9 | pub const io = @import("event/io.zig"); | ||
| 9 | pub const fs = @import("event/fs.zig"); | 10 | pub const fs = @import("event/fs.zig"); |
| 10 | pub const net = @import("event/net.zig"); | 11 | pub const net = @import("event/net.zig"); |
| 11 | 12 | ||
| ... | @@ -14,6 +15,7 @@ test "import event tests" { | ... | @@ -14,6 +15,7 @@ test "import event tests" { |
| 14 | _ = @import("event/fs.zig"); | 15 | _ = @import("event/fs.zig"); |
| 15 | _ = @import("event/future.zig"); | 16 | _ = @import("event/future.zig"); |
| 16 | _ = @import("event/group.zig"); | 17 | _ = @import("event/group.zig"); |
| 18 | _ = @import("event/io.zig"); | ||
| 17 | _ = @import("event/lock.zig"); | 19 | _ = @import("event/lock.zig"); |
| 18 | _ = @import("event/locked.zig"); | 20 | _ = @import("event/locked.zig"); |
| 19 | _ = @import("event/rwlock.zig"); | 21 | _ = @import("event/rwlock.zig"); |
std/event/fs.zig-2| ... | @@ -1246,9 +1246,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -1246,9 +1246,7 @@ pub fn Watch(comptime V: type) type { |
| 1246 | os.linux.EPOLLET | os.linux.EPOLLIN, | 1246 | os.linux.EPOLLET | os.linux.EPOLLIN, |
| 1247 | ) catch unreachable)) catch |err| { | 1247 | ) catch unreachable)) catch |err| { |
| 1248 | const transformed_err = switch (err) { | 1248 | const transformed_err = switch (err) { |
| 1249 | error.InvalidFileDescriptor => unreachable, | ||
| 1250 | error.FileDescriptorAlreadyPresentInSet => unreachable, | 1249 | error.FileDescriptorAlreadyPresentInSet => unreachable, |
| 1251 | error.InvalidSyscall => unreachable, | ||
| 1252 | error.OperationCausesCircularLoop => unreachable, | 1250 | error.OperationCausesCircularLoop => unreachable, |
| 1253 | error.FileDescriptorNotRegistered => unreachable, | 1251 | error.FileDescriptorNotRegistered => unreachable, |
| 1254 | error.SystemResources => error.SystemResources, | 1252 | error.SystemResources => error.SystemResources, |
std/event/io.zig created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | const std = @import("../index.zig"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const Allocator = std.mem.Allocator; | ||
| 4 | const assert = std.debug.assert; | ||
| 5 | |||
| 6 | pub fn InStream(comptime ReadError: type) type { | ||
| 7 | return struct { | ||
| 8 | const Self = @This(); | ||
| 9 | pub const Error = ReadError; | ||
| 10 | |||
| 11 | /// Return the number of bytes read. It may be less than buffer.len. | ||
| 12 | /// If the number of bytes read is 0, it means end of stream. | ||
| 13 | /// End of stream is not an error condition. | ||
| 14 | readFn: async<*Allocator> fn (self: *Self, buffer: []u8) Error!usize, | ||
| 15 | |||
| 16 | /// Return the number of bytes read. It may be less than buffer.len. | ||
| 17 | /// If the number of bytes read is 0, it means end of stream. | ||
| 18 | /// End of stream is not an error condition. | ||
| 19 | pub async fn read(self: *Self, buffer: []u8) !usize { | ||
| 20 | return await (async self.readFn(self, buffer) catch unreachable); | ||
| 21 | } | ||
| 22 | |||
| 23 | /// Same as `read` but end of stream returns `error.EndOfStream`. | ||
| 24 | pub async fn readFull(self: *Self, buf: []u8) !void { | ||
| 25 | var index: usize = 0; | ||
| 26 | while (index != buf.len) { | ||
| 27 | const amt_read = try await (async self.read(buf[index..]) catch unreachable); | ||
| 28 | if (amt_read == 0) return error.EndOfStream; | ||
| 29 | index += amt_read; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | pub async fn readStruct(self: *Self, comptime T: type, ptr: *T) !void { | ||
| 34 | // Only extern and packed structs have defined in-memory layout. | ||
| 35 | comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); | ||
| 36 | return await (async self.readFull(@sliceToBytes((*[1]T)(ptr)[0..])) catch unreachable); | ||
| 37 | } | ||
| 38 | }; | ||
| 39 | } | ||
| 40 | |||
| 41 | pub fn OutStream(comptime WriteError: type) type { | ||
| 42 | return struct { | ||
| 43 | const Self = @This(); | ||
| 44 | pub const Error = WriteError; | ||
| 45 | |||
| 46 | writeFn: async<*Allocator> fn (self: *Self, buffer: []u8) Error!void, | ||
| 47 | }; | ||
| 48 | } | ||
std/event/net.zig+200-60| ... | @@ -3,12 +3,12 @@ const builtin = @import("builtin"); | ... | @@ -3,12 +3,12 @@ const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const event = std.event; | 4 | const event = std.event; |
| 5 | const mem = std.mem; | 5 | const mem = std.mem; |
| 6 | const posix = std.os.posix; | 6 | const os = std.os; |
| 7 | const windows = std.os.windows; | 7 | const posix = os.posix; |
| 8 | const Loop = std.event.Loop; | 8 | const Loop = std.event.Loop; |
| 9 | 9 | ||
| 10 | pub const Server = struct { | 10 | pub const Server = struct { |
| 11 | handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, *const std.os.File) void, | 11 | handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, *const os.File) void, |
| 12 | 12 | ||
| 13 | loop: *Loop, | 13 | loop: *Loop, |
| 14 | sockfd: ?i32, | 14 | sockfd: ?i32, |
| ... | @@ -40,17 +40,17 @@ pub const Server = struct { | ... | @@ -40,17 +40,17 @@ pub const Server = struct { |
| 40 | pub fn listen( | 40 | pub fn listen( |
| 41 | self: *Server, | 41 | self: *Server, |
| 42 | address: *const std.net.Address, | 42 | address: *const std.net.Address, |
| 43 | handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, *const std.os.File) void, | 43 | handleRequestFn: async<*mem.Allocator> fn (*Server, *const std.net.Address, *const os.File) void, |
| 44 | ) !void { | 44 | ) !void { |
| 45 | self.handleRequestFn = handleRequestFn; | 45 | self.handleRequestFn = handleRequestFn; |
| 46 | 46 | ||
| 47 | const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp); | 47 | const sockfd = try os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp); |
| 48 | errdefer std.os.close(sockfd); | 48 | errdefer os.close(sockfd); |
| 49 | self.sockfd = sockfd; | 49 | self.sockfd = sockfd; |
| 50 | 50 | ||
| 51 | try std.os.posixBind(sockfd, &address.os_addr); | 51 | try os.posixBind(sockfd, &address.os_addr); |
| 52 | try std.os.posixListen(sockfd, posix.SOMAXCONN); | 52 | try os.posixListen(sockfd, posix.SOMAXCONN); |
| 53 | self.listen_address = std.net.Address.initPosix(try std.os.posixGetSockName(sockfd)); | 53 | self.listen_address = std.net.Address.initPosix(try os.posixGetSockName(sockfd)); |
| 54 | 54 | ||
| 55 | self.accept_coro = try async<self.loop.allocator> Server.handler(self); | 55 | self.accept_coro = try async<self.loop.allocator> Server.handler(self); |
| 56 | errdefer cancel self.accept_coro.?; | 56 | errdefer cancel self.accept_coro.?; |
| ... | @@ -63,19 +63,25 @@ pub const Server = struct { | ... | @@ -63,19 +63,25 @@ pub const Server = struct { |
| 63 | /// Stop listening | 63 | /// Stop listening |
| 64 | pub fn close(self: *Server) void { | 64 | pub fn close(self: *Server) void { |
| 65 | self.loop.linuxRemoveFd(self.sockfd.?); | 65 | self.loop.linuxRemoveFd(self.sockfd.?); |
| 66 | std.os.close(self.sockfd.?); | 66 | os.close(self.sockfd.?); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | pub fn deinit(self: *Server) void { | 69 | pub fn deinit(self: *Server) void { |
| 70 | if (self.accept_coro) |accept_coro| cancel accept_coro; | 70 | if (self.accept_coro) |accept_coro| cancel accept_coro; |
| 71 | if (self.sockfd) |sockfd| std.os.close(sockfd); | 71 | if (self.sockfd) |sockfd| os.close(sockfd); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | pub async fn handler(self: *Server) void { | 74 | pub async fn handler(self: *Server) void { |
| 75 | while (true) { | 75 | while (true) { |
| 76 | var accepted_addr: std.net.Address = undefined; | 76 | var accepted_addr: std.net.Address = undefined; |
| 77 | if (std.os.posixAccept(self.sockfd.?, &accepted_addr.os_addr, posix.SOCK_NONBLOCK | posix.SOCK_CLOEXEC)) |accepted_fd| { | 77 | // TODO just inline the following function here and don't expose it as posixAsyncAccept |
| 78 | var socket = std.os.File.openHandle(accepted_fd); | 78 | if (os.posixAsyncAccept(self.sockfd.?, &accepted_addr.os_addr, posix.SOCK_NONBLOCK | posix.SOCK_CLOEXEC)) |accepted_fd| { |
| 79 | if (accepted_fd == -1) { | ||
| 80 | // would block | ||
| 81 | suspend; // we will get resumed by epoll_wait in the event loop | ||
| 82 | continue; | ||
| 83 | } | ||
| 84 | var socket = os.File.openHandle(accepted_fd); | ||
| 79 | _ = async<self.loop.allocator> self.handleRequestFn(self, accepted_addr, socket) catch |err| switch (err) { | 85 | _ = async<self.loop.allocator> self.handleRequestFn(self, accepted_addr, socket) catch |err| switch (err) { |
| 80 | error.OutOfMemory => { | 86 | error.OutOfMemory => { |
| 81 | socket.close(); | 87 | socket.close(); |
| ... | @@ -83,22 +89,16 @@ pub const Server = struct { | ... | @@ -83,22 +89,16 @@ pub const Server = struct { |
| 83 | }, | 89 | }, |
| 84 | }; | 90 | }; |
| 85 | } else |err| switch (err) { | 91 | } else |err| switch (err) { |
| 86 | error.WouldBlock => { | ||
| 87 | suspend; // we will get resumed by epoll_wait in the event loop | ||
| 88 | continue; | ||
| 89 | }, | ||
| 90 | error.ProcessFdQuotaExceeded => { | 92 | error.ProcessFdQuotaExceeded => { |
| 91 | errdefer std.os.emfile_promise_queue.remove(&self.waiting_for_emfile_node); | 93 | errdefer os.emfile_promise_queue.remove(&self.waiting_for_emfile_node); |
| 92 | suspend { | 94 | suspend { |
| 93 | self.waiting_for_emfile_node = PromiseNode.init(@handle()); | 95 | self.waiting_for_emfile_node = PromiseNode.init(@handle()); |
| 94 | std.os.emfile_promise_queue.append(&self.waiting_for_emfile_node); | 96 | os.emfile_promise_queue.append(&self.waiting_for_emfile_node); |
| 95 | } | 97 | } |
| 96 | continue; | 98 | continue; |
| 97 | }, | 99 | }, |
| 98 | error.ConnectionAborted, error.FileDescriptorClosed => continue, | 100 | error.ConnectionAborted => continue, |
| 99 | 101 | ||
| 100 | error.PageFault => unreachable, | ||
| 101 | error.InvalidSyscall => unreachable, | ||
| 102 | error.FileDescriptorNotASocket => unreachable, | 102 | error.FileDescriptorNotASocket => unreachable, |
| 103 | error.OperationNotSupported => unreachable, | 103 | error.OperationNotSupported => unreachable, |
| 104 | 104 | ||
| ... | @@ -111,64 +111,161 @@ pub const Server = struct { | ... | @@ -111,64 +111,161 @@ pub const Server = struct { |
| 111 | }; | 111 | }; |
| 112 | 112 | ||
| 113 | pub async fn connectUnixSocket(loop: *Loop, path: []const u8) !i32 { | 113 | pub async fn connectUnixSocket(loop: *Loop, path: []const u8) !i32 { |
| 114 | const sockfd = try std.os.posixSocket( | 114 | const sockfd = try os.posixSocket( |
| 115 | posix.AF_UNIX, | 115 | posix.AF_UNIX, |
| 116 | posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, | 116 | posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, |
| 117 | 0, | 117 | 0, |
| 118 | ); | 118 | ); |
| 119 | errdefer std.os.close(sockfd); | 119 | errdefer os.close(sockfd); |
| 120 | 120 | ||
| 121 | var sock_addr = posix.sockaddr{ | 121 | var sock_addr = posix.sockaddr_un{ |
| 122 | .un = posix.sockaddr_un{ | 122 | .family = posix.AF_UNIX, |
| 123 | .family = posix.AF_UNIX, | 123 | .path = undefined, |
| 124 | .path = undefined, | ||
| 125 | }, | ||
| 126 | }; | 124 | }; |
| 127 | 125 | ||
| 128 | if (path.len > @typeOf(sock_addr.un.path).len) return error.NameTooLong; | 126 | if (path.len > @typeOf(sock_addr.path).len) return error.NameTooLong; |
| 129 | mem.copy(u8, sock_addr.un.path[0..], path); | 127 | mem.copy(u8, sock_addr.path[0..], path); |
| 130 | const size = @intCast(u32, @sizeOf(posix.sa_family_t) + path.len); | 128 | const size = @intCast(u32, @sizeOf(posix.sa_family_t) + path.len); |
| 131 | try std.os.posixConnectAsync(sockfd, &sock_addr, size); | 129 | try os.posixConnectAsync(sockfd, &sock_addr, size); |
| 132 | try await try async loop.linuxWaitFd(sockfd, posix.EPOLLIN | posix.EPOLLOUT | posix.EPOLLET); | 130 | try await try async loop.linuxWaitFd(sockfd, posix.EPOLLIN | posix.EPOLLOUT | posix.EPOLLET); |
| 133 | try std.os.posixGetSockOptConnectError(sockfd); | 131 | try os.posixGetSockOptConnectError(sockfd); |
| 134 | 132 | ||
| 135 | return sockfd; | 133 | return sockfd; |
| 136 | } | 134 | } |
| 137 | 135 | ||
| 138 | pub async fn socketRead(loop: *std.event.Loop, fd: i32, buffer: []u8) !void { | 136 | pub const ReadError = error{ |
| 137 | SystemResources, | ||
| 138 | Unexpected, | ||
| 139 | UserResourceLimitReached, | ||
| 140 | InputOutput, | ||
| 141 | |||
| 142 | FileDescriptorNotRegistered, // TODO remove this possibility | ||
| 143 | OperationCausesCircularLoop, // TODO remove this possibility | ||
| 144 | FileDescriptorAlreadyPresentInSet, // TODO remove this possibility | ||
| 145 | FileDescriptorIncompatibleWithEpoll, // TODO remove this possibility | ||
| 146 | }; | ||
| 147 | |||
| 148 | /// returns number of bytes read. 0 means EOF. | ||
| 149 | pub async fn read(loop: *std.event.Loop, fd: os.FileHandle, buffer: []u8) ReadError!usize { | ||
| 150 | const iov = posix.iovec{ | ||
| 151 | .iov_base = buffer.ptr, | ||
| 152 | .iov_len = buffer.len, | ||
| 153 | }; | ||
| 154 | const iovs: *const [1]posix.iovec = &iov; | ||
| 155 | return await (async readvPosix(loop, fd, iovs, 1) catch unreachable); | ||
| 156 | } | ||
| 157 | |||
| 158 | pub const WriteError = error{}; | ||
| 159 | |||
| 160 | pub async fn write(loop: *std.event.Loop, fd: os.FileHandle, buffer: []const u8) WriteError!void { | ||
| 161 | const iov = posix.iovec_const{ | ||
| 162 | .iov_base = buffer.ptr, | ||
| 163 | .iov_len = buffer.len, | ||
| 164 | }; | ||
| 165 | const iovs: *const [1]posix.iovec_const = &iov; | ||
| 166 | return await (async writevPosix(loop, fd, iovs, 1) catch unreachable); | ||
| 167 | } | ||
| 168 | |||
| 169 | pub async fn writevPosix(loop: *Loop, fd: i32, iov: [*]const posix.iovec_const, count: usize) !void { | ||
| 139 | while (true) { | 170 | while (true) { |
| 140 | return std.os.posixRead(fd, buffer) catch |err| switch (err) { | 171 | switch (builtin.os) { |
| 141 | error.WouldBlock => { | 172 | builtin.Os.macosx, builtin.Os.linux => { |
| 142 | try await try async loop.linuxWaitFd(fd, std.os.posix.EPOLLET | std.os.posix.EPOLLIN); | 173 | const rc = posix.writev(fd, iov, count); |
| 143 | continue; | 174 | const err = posix.getErrno(rc); |
| 175 | switch (err) { | ||
| 176 | 0 => return, | ||
| 177 | posix.EINTR => continue, | ||
| 178 | posix.ESPIPE => unreachable, | ||
| 179 | posix.EINVAL => unreachable, | ||
| 180 | posix.EFAULT => unreachable, | ||
| 181 | posix.EAGAIN => { | ||
| 182 | try await (async loop.linuxWaitFd(fd, posix.EPOLLET | posix.EPOLLOUT) catch unreachable); | ||
| 183 | continue; | ||
| 184 | }, | ||
| 185 | posix.EBADF => unreachable, // always a race condition | ||
| 186 | posix.EDESTADDRREQ => unreachable, // connect was never called | ||
| 187 | posix.EDQUOT => unreachable, | ||
| 188 | posix.EFBIG => unreachable, | ||
| 189 | posix.EIO => return error.InputOutput, | ||
| 190 | posix.ENOSPC => unreachable, | ||
| 191 | posix.EPERM => return error.AccessDenied, | ||
| 192 | posix.EPIPE => unreachable, | ||
| 193 | else => return os.unexpectedErrorPosix(err), | ||
| 194 | } | ||
| 144 | }, | 195 | }, |
| 145 | else => return err, | 196 | else => @compileError("Unsupported OS"), |
| 146 | }; | 197 | } |
| 147 | } | 198 | } |
| 148 | } | 199 | } |
| 149 | pub async fn socketWrite(loop: *std.event.Loop, fd: i32, buffer: []const u8) !void { | 200 | |
| 201 | /// returns number of bytes read. 0 means EOF. | ||
| 202 | pub async fn readvPosix(loop: *std.event.Loop, fd: i32, iov: [*]posix.iovec, count: usize) !usize { | ||
| 150 | while (true) { | 203 | while (true) { |
| 151 | return std.os.posixWrite(fd, buffer) catch |err| switch (err) { | 204 | switch (builtin.os) { |
| 152 | error.WouldBlock => { | 205 | builtin.Os.linux, builtin.Os.freebsd, builtin.Os.macosx => { |
| 153 | try await try async loop.linuxWaitFd(fd, std.os.posix.EPOLLET | std.os.posix.EPOLLOUT); | 206 | const rc = posix.readv(fd, iov, count); |
| 154 | continue; | 207 | const err = posix.getErrno(rc); |
| 208 | switch (err) { | ||
| 209 | 0 => return rc, | ||
| 210 | posix.EINTR => continue, | ||
| 211 | posix.EINVAL => unreachable, | ||
| 212 | posix.EFAULT => unreachable, | ||
| 213 | posix.EAGAIN => { | ||
| 214 | try await (async loop.linuxWaitFd(fd, posix.EPOLLET | posix.EPOLLIN) catch unreachable); | ||
| 215 | continue; | ||
| 216 | }, | ||
| 217 | posix.EBADF => unreachable, // always a race condition | ||
| 218 | posix.EIO => return error.InputOutput, | ||
| 219 | posix.EISDIR => unreachable, | ||
| 220 | posix.ENOBUFS => return error.SystemResources, | ||
| 221 | posix.ENOMEM => return error.SystemResources, | ||
| 222 | else => return os.unexpectedErrorPosix(err), | ||
| 223 | } | ||
| 155 | }, | 224 | }, |
| 156 | else => return err, | 225 | else => @compileError("Unsupported OS"), |
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | pub async fn writev(loop: *Loop, fd: os.FileHandle, data: []const []const u8) !void { | ||
| 231 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); | ||
| 232 | defer loop.allocator.free(iovecs); | ||
| 233 | |||
| 234 | for (data) |buf, i| { | ||
| 235 | iovecs[i] = os.posix.iovec_const{ | ||
| 236 | .iov_base = buf.ptr, | ||
| 237 | .iov_len = buf.len, | ||
| 157 | }; | 238 | }; |
| 158 | } | 239 | } |
| 240 | |||
| 241 | return await (async writevPosix(loop, fd, iovecs.ptr, data.len) catch unreachable); | ||
| 242 | } | ||
| 243 | |||
| 244 | pub async fn readv(loop: *Loop, fd: os.FileHandle, data: []const []u8) !usize { | ||
| 245 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); | ||
| 246 | defer loop.allocator.free(iovecs); | ||
| 247 | |||
| 248 | for (data) |buf, i| { | ||
| 249 | iovecs[i] = os.posix.iovec{ | ||
| 250 | .iov_base = buf.ptr, | ||
| 251 | .iov_len = buf.len, | ||
| 252 | }; | ||
| 253 | } | ||
| 254 | |||
| 255 | return await (async readvPosix(loop, fd, iovecs.ptr, data.len) catch unreachable); | ||
| 159 | } | 256 | } |
| 160 | 257 | ||
| 161 | pub async fn connect(loop: *Loop, _address: *const std.net.Address) !std.os.File { | 258 | pub async fn connect(loop: *Loop, _address: *const std.net.Address) !os.File { |
| 162 | var address = _address.*; // TODO https://github.com/ziglang/zig/issues/733 | 259 | var address = _address.*; // TODO https://github.com/ziglang/zig/issues/1592 |
| 163 | 260 | ||
| 164 | const sockfd = try std.os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp); | 261 | const sockfd = try os.posixSocket(posix.AF_INET, posix.SOCK_STREAM | posix.SOCK_CLOEXEC | posix.SOCK_NONBLOCK, posix.PROTO_tcp); |
| 165 | errdefer std.os.close(sockfd); | 262 | errdefer os.close(sockfd); |
| 166 | 263 | ||
| 167 | try std.os.posixConnectAsync(sockfd, &address.os_addr, @sizeOf(posix.sockaddr_in)); | 264 | try os.posixConnectAsync(sockfd, &address.os_addr, @sizeOf(posix.sockaddr_in)); |
| 168 | try await try async loop.linuxWaitFd(sockfd, posix.EPOLLIN | posix.EPOLLOUT | posix.EPOLLET); | 265 | try await try async loop.linuxWaitFd(sockfd, posix.EPOLLIN | posix.EPOLLOUT | posix.EPOLLET); |
| 169 | try std.os.posixGetSockOptConnectError(sockfd); | 266 | try os.posixGetSockOptConnectError(sockfd); |
| 170 | 267 | ||
| 171 | return std.os.File.openHandle(sockfd); | 268 | return os.File.openHandle(sockfd); |
| 172 | } | 269 | } |
| 173 | 270 | ||
| 174 | test "listen on a port, send bytes, receive bytes" { | 271 | test "listen on a port, send bytes, receive bytes" { |
| ... | @@ -181,9 +278,9 @@ test "listen on a port, send bytes, receive bytes" { | ... | @@ -181,9 +278,9 @@ test "listen on a port, send bytes, receive bytes" { |
| 181 | tcp_server: Server, | 278 | tcp_server: Server, |
| 182 | 279 | ||
| 183 | const Self = @This(); | 280 | const Self = @This(); |
| 184 | async<*mem.Allocator> fn handler(tcp_server: *Server, _addr: *const std.net.Address, _socket: *const std.os.File) void { | 281 | async<*mem.Allocator> fn handler(tcp_server: *Server, _addr: *const std.net.Address, _socket: *const os.File) void { |
| 185 | const self = @fieldParentPtr(Self, "tcp_server", tcp_server); | 282 | const self = @fieldParentPtr(Self, "tcp_server", tcp_server); |
| 186 | var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733 | 283 | var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/1592 |
| 187 | defer socket.close(); | 284 | defer socket.close(); |
| 188 | // TODO guarantee elision of this allocation | 285 | // TODO guarantee elision of this allocation |
| 189 | const next_handler = async errorableHandler(self, _addr, socket) catch unreachable; | 286 | const next_handler = async errorableHandler(self, _addr, socket) catch unreachable; |
| ... | @@ -194,12 +291,11 @@ test "listen on a port, send bytes, receive bytes" { | ... | @@ -194,12 +291,11 @@ test "listen on a port, send bytes, receive bytes" { |
| 194 | cancel @handle(); | 291 | cancel @handle(); |
| 195 | } | 292 | } |
| 196 | } | 293 | } |
| 197 | async fn errorableHandler(self: *Self, _addr: *const std.net.Address, _socket: std.os.File) !void { | 294 | async fn errorableHandler(self: *Self, _addr: *const std.net.Address, _socket: os.File) !void { |
| 198 | const addr = _addr.*; // TODO https://github.com/ziglang/zig/issues/733 | 295 | const addr = _addr.*; // TODO https://github.com/ziglang/zig/issues/1592 |
| 199 | var socket = _socket; // TODO https://github.com/ziglang/zig/issues/733 | 296 | var socket = _socket; // TODO https://github.com/ziglang/zig/issues/1592 |
| 200 | 297 | ||
| 201 | var adapter = std.io.FileOutStream.init(socket); | 298 | const stream = &socket.outStream().stream; |
| 202 | var stream = &adapter.stream; | ||
| 203 | try stream.print("hello from server\n"); | 299 | try stream.print("hello from server\n"); |
| 204 | } | 300 | } |
| 205 | }; | 301 | }; |
| ... | @@ -230,3 +326,47 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv | ... | @@ -230,3 +326,47 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv |
| 230 | assert(mem.eql(u8, msg, "hello from server\n")); | 326 | assert(mem.eql(u8, msg, "hello from server\n")); |
| 231 | server.close(); | 327 | server.close(); |
| 232 | } | 328 | } |
| 329 | |||
| 330 | pub const OutStream = struct { | ||
| 331 | fd: os.FileHandle, | ||
| 332 | stream: Stream, | ||
| 333 | loop: *Loop, | ||
| 334 | |||
| 335 | pub const Error = WriteError; | ||
| 336 | pub const Stream = event.io.OutStream(Error); | ||
| 337 | |||
| 338 | pub fn init(loop: *Loop, fd: os.FileHandle) OutStream { | ||
| 339 | return OutStream{ | ||
| 340 | .fd = fd, | ||
| 341 | .loop = loop, | ||
| 342 | .stream = Stream{ .writeFn = writeFn }, | ||
| 343 | }; | ||
| 344 | } | ||
| 345 | |||
| 346 | async<*mem.Allocator> fn writeFn(out_stream: *Stream, bytes: []const u8) Error!void { | ||
| 347 | const self = @fieldParentPtr(OutStream, "stream", out_stream); | ||
| 348 | return await (async write(self.loop, self.fd, bytes) catch unreachable); | ||
| 349 | } | ||
| 350 | }; | ||
| 351 | |||
| 352 | pub const InStream = struct { | ||
| 353 | fd: os.FileHandle, | ||
| 354 | stream: Stream, | ||
| 355 | loop: *Loop, | ||
| 356 | |||
| 357 | pub const Error = ReadError; | ||
| 358 | pub const Stream = event.io.InStream(Error); | ||
| 359 | |||
| 360 | pub fn init(loop: *Loop, fd: os.FileHandle) InStream { | ||
| 361 | return InStream{ | ||
| 362 | .fd = fd, | ||
| 363 | .loop = loop, | ||
| 364 | .stream = Stream{ .readFn = readFn }, | ||
| 365 | }; | ||
| 366 | } | ||
| 367 | |||
| 368 | async<*mem.Allocator> fn readFn(in_stream: *Stream, bytes: []u8) Error!usize { | ||
| 369 | const self = @fieldParentPtr(InStream, "stream", in_stream); | ||
| 370 | return await (async read(self.loop, self.fd, bytes) catch unreachable); | ||
| 371 | } | ||
| 372 | }; |
std/io.zig+9-49| ... | @@ -32,48 +32,6 @@ pub fn getStdIn() GetStdIoErrs!File { | ... | @@ -32,48 +32,6 @@ pub fn getStdIn() GetStdIoErrs!File { |
| 32 | return File.openHandle(handle); | 32 | return File.openHandle(handle); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | /// Implementation of InStream trait for File | ||
| 36 | pub const FileInStream = struct { | ||
| 37 | file: File, | ||
| 38 | stream: Stream, | ||
| 39 | |||
| 40 | pub const Error = @typeOf(File.read).ReturnType.ErrorSet; | ||
| 41 | pub const Stream = InStream(Error); | ||
| 42 | |||
| 43 | pub fn init(file: File) FileInStream { | ||
| 44 | return FileInStream{ | ||
| 45 | .file = file, | ||
| 46 | .stream = Stream{ .readFn = readFn }, | ||
| 47 | }; | ||
| 48 | } | ||
| 49 | |||
| 50 | fn readFn(in_stream: *Stream, buffer: []u8) Error!usize { | ||
| 51 | const self = @fieldParentPtr(FileInStream, "stream", in_stream); | ||
| 52 | return self.file.read(buffer); | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | /// Implementation of OutStream trait for File | ||
| 57 | pub const FileOutStream = struct { | ||
| 58 | file: File, | ||
| 59 | stream: Stream, | ||
| 60 | |||
| 61 | pub const Error = File.WriteError; | ||
| 62 | pub const Stream = OutStream(Error); | ||
| 63 | |||
| 64 | pub fn init(file: File) FileOutStream { | ||
| 65 | return FileOutStream{ | ||
| 66 | .file = file, | ||
| 67 | .stream = Stream{ .writeFn = writeFn }, | ||
| 68 | }; | ||
| 69 | } | ||
| 70 | |||
| 71 | fn writeFn(out_stream: *Stream, bytes: []const u8) !void { | ||
| 72 | const self = @fieldParentPtr(FileOutStream, "stream", out_stream); | ||
| 73 | return self.file.write(bytes); | ||
| 74 | } | ||
| 75 | }; | ||
| 76 | |||
| 77 | pub fn InStream(comptime ReadError: type) type { | 35 | pub fn InStream(comptime ReadError: type) type { |
| 78 | return struct { | 36 | return struct { |
| 79 | const Self = @This(); | 37 | const Self = @This(); |
| ... | @@ -280,7 +238,7 @@ pub fn readFileAllocAligned(allocator: *mem.Allocator, path: []const u8, comptim | ... | @@ -280,7 +238,7 @@ pub fn readFileAllocAligned(allocator: *mem.Allocator, path: []const u8, comptim |
| 280 | const buf = try allocator.alignedAlloc(u8, A, size); | 238 | const buf = try allocator.alignedAlloc(u8, A, size); |
| 281 | errdefer allocator.free(buf); | 239 | errdefer allocator.free(buf); |
| 282 | 240 | ||
| 283 | var adapter = FileInStream.init(file); | 241 | var adapter = file.inStream(); |
| 284 | try adapter.stream.readNoEof(buf[0..size]); | 242 | try adapter.stream.readNoEof(buf[0..size]); |
| 285 | return buf; | 243 | return buf; |
| 286 | } | 244 | } |
| ... | @@ -577,8 +535,8 @@ pub const BufferOutStream = struct { | ... | @@ -577,8 +535,8 @@ pub const BufferOutStream = struct { |
| 577 | 535 | ||
| 578 | pub const BufferedAtomicFile = struct { | 536 | pub const BufferedAtomicFile = struct { |
| 579 | atomic_file: os.AtomicFile, | 537 | atomic_file: os.AtomicFile, |
| 580 | file_stream: FileOutStream, | 538 | file_stream: os.File.OutStream, |
| 581 | buffered_stream: BufferedOutStream(FileOutStream.Error), | 539 | buffered_stream: BufferedOutStream(os.File.WriteError), |
| 582 | 540 | ||
| 583 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { | 541 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { |
| 584 | // TODO with well defined copy elision we don't need this allocation | 542 | // TODO with well defined copy elision we don't need this allocation |
| ... | @@ -592,8 +550,8 @@ pub const BufferedAtomicFile = struct { | ... | @@ -592,8 +550,8 @@ pub const BufferedAtomicFile = struct { |
| 592 | self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.File.default_mode); | 550 | self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.File.default_mode); |
| 593 | errdefer self.atomic_file.deinit(); | 551 | errdefer self.atomic_file.deinit(); |
| 594 | 552 | ||
| 595 | self.file_stream = FileOutStream.init(self.atomic_file.file); | 553 | self.file_stream = self.atomic_file.file.outStream(); |
| 596 | self.buffered_stream = BufferedOutStream(FileOutStream.Error).init(&self.file_stream.stream); | 554 | self.buffered_stream = BufferedOutStream(os.File.WriteError).init(&self.file_stream.stream); |
| 597 | return self; | 555 | return self; |
| 598 | } | 556 | } |
| 599 | 557 | ||
| ... | @@ -609,7 +567,7 @@ pub const BufferedAtomicFile = struct { | ... | @@ -609,7 +567,7 @@ pub const BufferedAtomicFile = struct { |
| 609 | try self.atomic_file.finish(); | 567 | try self.atomic_file.finish(); |
| 610 | } | 568 | } |
| 611 | 569 | ||
| 612 | pub fn stream(self: *BufferedAtomicFile) *OutStream(FileOutStream.Error) { | 570 | pub fn stream(self: *BufferedAtomicFile) *OutStream(os.File.WriteError) { |
| 613 | return &self.buffered_stream.stream; | 571 | return &self.buffered_stream.stream; |
| 614 | } | 572 | } |
| 615 | }; | 573 | }; |
| ... | @@ -622,7 +580,7 @@ test "import io tests" { | ... | @@ -622,7 +580,7 @@ test "import io tests" { |
| 622 | 580 | ||
| 623 | pub fn readLine(buf: []u8) !usize { | 581 | pub fn readLine(buf: []u8) !usize { |
| 624 | var stdin = getStdIn() catch return error.StdInUnavailable; | 582 | var stdin = getStdIn() catch return error.StdInUnavailable; |
| 625 | var adapter = FileInStream.init(stdin); | 583 | var adapter = stdin.inStream(); |
| 626 | var stream = &adapter.stream; | 584 | var stream = &adapter.stream; |
| 627 | var index: usize = 0; | 585 | var index: usize = 0; |
| 628 | while (true) { | 586 | while (true) { |
| ... | @@ -642,3 +600,5 @@ pub fn readLine(buf: []u8) !usize { | ... | @@ -642,3 +600,5 @@ pub fn readLine(buf: []u8) !usize { |
| 642 | } | 600 | } |
| 643 | } | 601 | } |
| 644 | } | 602 | } |
| 603 | |||
| 604 |
std/io_test.zig+4-4| ... | @@ -19,8 +19,8 @@ test "write a file, read it, then delete it" { | ... | @@ -19,8 +19,8 @@ test "write a file, read it, then delete it" { |
| 19 | var file = try os.File.openWrite(tmp_file_name); | 19 | var file = try os.File.openWrite(tmp_file_name); |
| 20 | defer file.close(); | 20 | defer file.close(); |
| 21 | 21 | ||
| 22 | var file_out_stream = io.FileOutStream.init(file); | 22 | var file_out_stream = file.outStream(); |
| 23 | var buf_stream = io.BufferedOutStream(io.FileOutStream.Error).init(&file_out_stream.stream); | 23 | var buf_stream = io.BufferedOutStream(os.File.WriteError).init(&file_out_stream.stream); |
| 24 | const st = &buf_stream.stream; | 24 | const st = &buf_stream.stream; |
| 25 | try st.print("begin"); | 25 | try st.print("begin"); |
| 26 | try st.write(data[0..]); | 26 | try st.write(data[0..]); |
| ... | @@ -35,8 +35,8 @@ test "write a file, read it, then delete it" { | ... | @@ -35,8 +35,8 @@ test "write a file, read it, then delete it" { |
| 35 | const expected_file_size = "begin".len + data.len + "end".len; | 35 | const expected_file_size = "begin".len + data.len + "end".len; |
| 36 | assert(file_size == expected_file_size); | 36 | assert(file_size == expected_file_size); |
| 37 | 37 | ||
| 38 | var file_in_stream = io.FileInStream.init(file); | 38 | var file_in_stream = file.inStream(); |
| 39 | var buf_stream = io.BufferedInStream(io.FileInStream.Error).init(&file_in_stream.stream); | 39 | var buf_stream = io.BufferedInStream(os.File.ReadError).init(&file_in_stream.stream); |
| 40 | const st = &buf_stream.stream; | 40 | const st = &buf_stream.stream; |
| 41 | const contents = try st.readAllAlloc(allocator, 2 * 1024); | 41 | const contents = try st.readAllAlloc(allocator, 2 * 1024); |
| 42 | defer allocator.free(contents); | 42 | defer allocator.free(contents); |
std/os/child_process.zig+2-2| ... | @@ -211,8 +211,8 @@ pub const ChildProcess = struct { | ... | @@ -211,8 +211,8 @@ pub const ChildProcess = struct { |
| 211 | defer Buffer.deinit(&stdout); | 211 | defer Buffer.deinit(&stdout); |
| 212 | defer Buffer.deinit(&stderr); | 212 | defer Buffer.deinit(&stderr); |
| 213 | 213 | ||
| 214 | var stdout_file_in_stream = io.FileInStream.init(child.stdout.?); | 214 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 215 | var stderr_file_in_stream = io.FileInStream.init(child.stderr.?); | 215 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 216 | 216 | ||
| 217 | try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size); | 217 | try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size); |
| 218 | try stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size); | 218 | try stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size); |
std/os/file.zig+44-2| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("../index.zig"); | 1 | const std = @import("../index.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const os = std.os; | 3 | const os = std.os; |
| 4 | const io = std.io; | ||
| 4 | const mem = std.mem; | 5 | const mem = std.mem; |
| 5 | const math = std.math; | 6 | const math = std.math; |
| 6 | const assert = std.debug.assert; | 7 | const assert = std.debug.assert; |
| ... | @@ -368,7 +369,6 @@ pub const File = struct { | ... | @@ -368,7 +369,6 @@ pub const File = struct { |
| 368 | FileClosed, | 369 | FileClosed, |
| 369 | InputOutput, | 370 | InputOutput, |
| 370 | IsDir, | 371 | IsDir, |
| 371 | WouldBlock, | ||
| 372 | SystemResources, | 372 | SystemResources, |
| 373 | 373 | ||
| 374 | Unexpected, | 374 | Unexpected, |
| ... | @@ -385,7 +385,7 @@ pub const File = struct { | ... | @@ -385,7 +385,7 @@ pub const File = struct { |
| 385 | posix.EINTR => continue, | 385 | posix.EINTR => continue, |
| 386 | posix.EINVAL => unreachable, | 386 | posix.EINVAL => unreachable, |
| 387 | posix.EFAULT => unreachable, | 387 | posix.EFAULT => unreachable, |
| 388 | posix.EAGAIN => return error.WouldBlock, | 388 | posix.EAGAIN => unreachable, |
| 389 | posix.EBADF => return error.FileClosed, | 389 | posix.EBADF => return error.FileClosed, |
| 390 | posix.EIO => return error.InputOutput, | 390 | posix.EIO => return error.InputOutput, |
| 391 | posix.EISDIR => return error.IsDir, | 391 | posix.EISDIR => return error.IsDir, |
| ... | @@ -431,4 +431,46 @@ pub const File = struct { | ... | @@ -431,4 +431,46 @@ pub const File = struct { |
| 431 | @compileError("Unsupported OS"); | 431 | @compileError("Unsupported OS"); |
| 432 | } | 432 | } |
| 433 | } | 433 | } |
| 434 | |||
| 435 | pub fn inStream(file: File) InStream { | ||
| 436 | return InStream{ | ||
| 437 | .file = file, | ||
| 438 | .stream = InStream.Stream{ .readFn = InStream.readFn }, | ||
| 439 | }; | ||
| 440 | } | ||
| 441 | |||
| 442 | pub fn outStream(file: File) OutStream { | ||
| 443 | return OutStream{ | ||
| 444 | .file = file, | ||
| 445 | .stream = OutStream.Stream{ .writeFn = OutStream.writeFn }, | ||
| 446 | }; | ||
| 447 | } | ||
| 448 | |||
| 449 | /// Implementation of io.InStream trait for File | ||
| 450 | pub const InStream = struct { | ||
| 451 | file: File, | ||
| 452 | stream: Stream, | ||
| 453 | |||
| 454 | pub const Error = ReadError; | ||
| 455 | pub const Stream = io.InStream(Error); | ||
| 456 | |||
| 457 | fn readFn(in_stream: *Stream, buffer: []u8) Error!usize { | ||
| 458 | const self = @fieldParentPtr(InStream, "stream", in_stream); | ||
| 459 | return self.file.read(buffer); | ||
| 460 | } | ||
| 461 | }; | ||
| 462 | |||
| 463 | /// Implementation of io.OutStream trait for File | ||
| 464 | pub const OutStream = struct { | ||
| 465 | file: File, | ||
| 466 | stream: Stream, | ||
| 467 | |||
| 468 | pub const Error = WriteError; | ||
| 469 | pub const Stream = io.OutStream(Error); | ||
| 470 | |||
| 471 | fn writeFn(out_stream: *Stream, bytes: []const u8) Error!void { | ||
| 472 | const self = @fieldParentPtr(OutStream, "stream", out_stream); | ||
| 473 | return self.file.write(bytes); | ||
| 474 | } | ||
| 475 | }; | ||
| 434 | }; | 476 | }; |
std/os/index.zig+57-75| ... | @@ -242,8 +242,8 @@ pub fn posixRead(fd: i32, buf: []u8) !void { | ... | @@ -242,8 +242,8 @@ pub fn posixRead(fd: i32, buf: []u8) !void { |
| 242 | return switch (err) { | 242 | return switch (err) { |
| 243 | posix.EINTR => continue, | 243 | posix.EINTR => continue, |
| 244 | posix.EINVAL, posix.EFAULT => unreachable, | 244 | posix.EINVAL, posix.EFAULT => unreachable, |
| 245 | posix.EAGAIN => error.WouldBlock, | 245 | posix.EAGAIN => unreachable, |
| 246 | posix.EBADF => error.FileClosed, | 246 | posix.EBADF => unreachable, // always a race condition |
| 247 | posix.EIO => error.InputOutput, | 247 | posix.EIO => error.InputOutput, |
| 248 | posix.EISDIR => error.IsDir, | 248 | posix.EISDIR => error.IsDir, |
| 249 | posix.ENOBUFS, posix.ENOMEM => error.SystemResources, | 249 | posix.ENOBUFS, posix.ENOMEM => error.SystemResources, |
| ... | @@ -284,8 +284,8 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 | ... | @@ -284,8 +284,8 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 |
| 284 | posix.EINVAL => unreachable, | 284 | posix.EINVAL => unreachable, |
| 285 | posix.EFAULT => unreachable, | 285 | posix.EFAULT => unreachable, |
| 286 | posix.ESPIPE => unreachable, // fd is not seekable | 286 | posix.ESPIPE => unreachable, // fd is not seekable |
| 287 | posix.EAGAIN => return error.WouldBlock, | 287 | posix.EAGAIN => unreachable, // use posixAsyncPReadV for non blocking |
| 288 | posix.EBADF => return error.FileClosed, | 288 | posix.EBADF => unreachable, // always a race condition |
| 289 | posix.EIO => return error.InputOutput, | 289 | posix.EIO => return error.InputOutput, |
| 290 | posix.EISDIR => return error.IsDir, | 290 | posix.EISDIR => return error.IsDir, |
| 291 | posix.ENOBUFS => return error.SystemResources, | 291 | posix.ENOBUFS => return error.SystemResources, |
| ... | @@ -302,8 +302,8 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 | ... | @@ -302,8 +302,8 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 |
| 302 | posix.EINTR => continue, | 302 | posix.EINTR => continue, |
| 303 | posix.EINVAL => unreachable, | 303 | posix.EINVAL => unreachable, |
| 304 | posix.EFAULT => unreachable, | 304 | posix.EFAULT => unreachable, |
| 305 | posix.EAGAIN => return error.WouldBlock, | 305 | posix.EAGAIN => unreachable, // use posixAsyncPReadV for non blocking |
| 306 | posix.EBADF => return error.FileClosed, | 306 | posix.EBADF => unreachable, // always a race condition |
| 307 | posix.EIO => return error.InputOutput, | 307 | posix.EIO => return error.InputOutput, |
| 308 | posix.EISDIR => return error.IsDir, | 308 | posix.EISDIR => return error.IsDir, |
| 309 | posix.ENOBUFS => return error.SystemResources, | 309 | posix.ENOBUFS => return error.SystemResources, |
| ... | @@ -316,9 +316,6 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 | ... | @@ -316,9 +316,6 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6 |
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | pub const PosixWriteError = error{ | 318 | pub const PosixWriteError = error{ |
| 319 | WouldBlock, | ||
| 320 | FileClosed, | ||
| 321 | DestinationAddressRequired, | ||
| 322 | DiskQuota, | 319 | DiskQuota, |
| 323 | FileTooBig, | 320 | FileTooBig, |
| 324 | InputOutput, | 321 | InputOutput, |
| ... | @@ -349,9 +346,9 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void { | ... | @@ -349,9 +346,9 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void { |
| 349 | posix.EINTR => continue, | 346 | posix.EINTR => continue, |
| 350 | posix.EINVAL => unreachable, | 347 | posix.EINVAL => unreachable, |
| 351 | posix.EFAULT => unreachable, | 348 | posix.EFAULT => unreachable, |
| 352 | posix.EAGAIN => return PosixWriteError.WouldBlock, | 349 | posix.EAGAIN => unreachable, // use posixAsyncWrite for non-blocking |
| 353 | posix.EBADF => return PosixWriteError.FileClosed, | 350 | posix.EBADF => unreachable, // always a race condition |
| 354 | posix.EDESTADDRREQ => return PosixWriteError.DestinationAddressRequired, | 351 | posix.EDESTADDRREQ => unreachable, // connect was never called |
| 355 | posix.EDQUOT => return PosixWriteError.DiskQuota, | 352 | posix.EDQUOT => return PosixWriteError.DiskQuota, |
| 356 | posix.EFBIG => return PosixWriteError.FileTooBig, | 353 | posix.EFBIG => return PosixWriteError.FileTooBig, |
| 357 | posix.EIO => return PosixWriteError.InputOutput, | 354 | posix.EIO => return PosixWriteError.InputOutput, |
| ... | @@ -391,9 +388,9 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off | ... | @@ -391,9 +388,9 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off |
| 391 | posix.ESPIPE => unreachable, // fd is not seekable | 388 | posix.ESPIPE => unreachable, // fd is not seekable |
| 392 | posix.EINVAL => unreachable, | 389 | posix.EINVAL => unreachable, |
| 393 | posix.EFAULT => unreachable, | 390 | posix.EFAULT => unreachable, |
| 394 | posix.EAGAIN => return PosixWriteError.WouldBlock, | 391 | posix.EAGAIN => unreachable, // use posixAsyncPWriteV for non-blocking |
| 395 | posix.EBADF => return PosixWriteError.FileClosed, | 392 | posix.EBADF => unreachable, // always a race condition |
| 396 | posix.EDESTADDRREQ => return PosixWriteError.DestinationAddressRequired, | 393 | posix.EDESTADDRREQ => unreachable, // connect was never called |
| 397 | posix.EDQUOT => return PosixWriteError.DiskQuota, | 394 | posix.EDQUOT => return PosixWriteError.DiskQuota, |
| 398 | posix.EFBIG => return PosixWriteError.FileTooBig, | 395 | posix.EFBIG => return PosixWriteError.FileTooBig, |
| 399 | posix.EIO => return PosixWriteError.InputOutput, | 396 | posix.EIO => return PosixWriteError.InputOutput, |
| ... | @@ -412,9 +409,9 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off | ... | @@ -412,9 +409,9 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off |
| 412 | posix.EINTR => continue, | 409 | posix.EINTR => continue, |
| 413 | posix.EINVAL => unreachable, | 410 | posix.EINVAL => unreachable, |
| 414 | posix.EFAULT => unreachable, | 411 | posix.EFAULT => unreachable, |
| 415 | posix.EAGAIN => return PosixWriteError.WouldBlock, | 412 | posix.EAGAIN => unreachable, // use posixAsyncPWriteV for non-blocking |
| 416 | posix.EBADF => return PosixWriteError.FileClosed, | 413 | posix.EBADF => unreachable, // always a race condition |
| 417 | posix.EDESTADDRREQ => return PosixWriteError.DestinationAddressRequired, | 414 | posix.EDESTADDRREQ => unreachable, // connect was never called |
| 418 | posix.EDQUOT => return PosixWriteError.DiskQuota, | 415 | posix.EDQUOT => return PosixWriteError.DiskQuota, |
| 419 | posix.EFBIG => return PosixWriteError.FileTooBig, | 416 | posix.EFBIG => return PosixWriteError.FileTooBig, |
| 420 | posix.EIO => return PosixWriteError.InputOutput, | 417 | posix.EIO => return PosixWriteError.InputOutput, |
| ... | @@ -2287,22 +2284,9 @@ pub const PosixBindError = error{ | ... | @@ -2287,22 +2284,9 @@ pub const PosixBindError = error{ |
| 2287 | /// use. See the discussion of /proc/sys/net/ipv4/ip_local_port_range ip(7). | 2284 | /// use. See the discussion of /proc/sys/net/ipv4/ip_local_port_range ip(7). |
| 2288 | AddressInUse, | 2285 | AddressInUse, |
| 2289 | 2286 | ||
| 2290 | /// sockfd is not a valid file descriptor. | ||
| 2291 | InvalidFileDescriptor, | ||
| 2292 | |||
| 2293 | /// The socket is already bound to an address, or addrlen is wrong, or addr is not | ||
| 2294 | /// a valid address for this socket's domain. | ||
| 2295 | InvalidSocketOrAddress, | ||
| 2296 | |||
| 2297 | /// The file descriptor sockfd does not refer to a socket. | ||
| 2298 | FileDescriptorNotASocket, | ||
| 2299 | |||
| 2300 | /// A nonexistent interface was requested or the requested address was not local. | 2287 | /// A nonexistent interface was requested or the requested address was not local. |
| 2301 | AddressNotAvailable, | 2288 | AddressNotAvailable, |
| 2302 | 2289 | ||
| 2303 | /// addr points outside the user's accessible address space. | ||
| 2304 | PageFault, | ||
| 2305 | |||
| 2306 | /// Too many symbolic links were encountered in resolving addr. | 2290 | /// Too many symbolic links were encountered in resolving addr. |
| 2307 | SymLinkLoop, | 2291 | SymLinkLoop, |
| 2308 | 2292 | ||
| ... | @@ -2333,11 +2317,11 @@ pub fn posixBind(fd: i32, addr: *const posix.sockaddr) PosixBindError!void { | ... | @@ -2333,11 +2317,11 @@ pub fn posixBind(fd: i32, addr: *const posix.sockaddr) PosixBindError!void { |
| 2333 | 0 => return, | 2317 | 0 => return, |
| 2334 | posix.EACCES => return PosixBindError.AccessDenied, | 2318 | posix.EACCES => return PosixBindError.AccessDenied, |
| 2335 | posix.EADDRINUSE => return PosixBindError.AddressInUse, | 2319 | posix.EADDRINUSE => return PosixBindError.AddressInUse, |
| 2336 | posix.EBADF => return PosixBindError.InvalidFileDescriptor, | 2320 | posix.EBADF => unreachable, // always a race condition if this error is returned |
| 2337 | posix.EINVAL => return PosixBindError.InvalidSocketOrAddress, | 2321 | posix.EINVAL => unreachable, |
| 2338 | posix.ENOTSOCK => return PosixBindError.FileDescriptorNotASocket, | 2322 | posix.ENOTSOCK => unreachable, |
| 2339 | posix.EADDRNOTAVAIL => return PosixBindError.AddressNotAvailable, | 2323 | posix.EADDRNOTAVAIL => return PosixBindError.AddressNotAvailable, |
| 2340 | posix.EFAULT => return PosixBindError.PageFault, | 2324 | posix.EFAULT => unreachable, |
| 2341 | posix.ELOOP => return PosixBindError.SymLinkLoop, | 2325 | posix.ELOOP => return PosixBindError.SymLinkLoop, |
| 2342 | posix.ENAMETOOLONG => return PosixBindError.NameTooLong, | 2326 | posix.ENAMETOOLONG => return PosixBindError.NameTooLong, |
| 2343 | posix.ENOENT => return PosixBindError.FileNotFound, | 2327 | posix.ENOENT => return PosixBindError.FileNotFound, |
| ... | @@ -2356,9 +2340,6 @@ const PosixListenError = error{ | ... | @@ -2356,9 +2340,6 @@ const PosixListenError = error{ |
| 2356 | /// use. See the discussion of /proc/sys/net/ipv4/ip_local_port_range in ip(7). | 2340 | /// use. See the discussion of /proc/sys/net/ipv4/ip_local_port_range in ip(7). |
| 2357 | AddressInUse, | 2341 | AddressInUse, |
| 2358 | 2342 | ||
| 2359 | /// The argument sockfd is not a valid file descriptor. | ||
| 2360 | InvalidFileDescriptor, | ||
| 2361 | |||
| 2362 | /// The file descriptor sockfd does not refer to a socket. | 2343 | /// The file descriptor sockfd does not refer to a socket. |
| 2363 | FileDescriptorNotASocket, | 2344 | FileDescriptorNotASocket, |
| 2364 | 2345 | ||
| ... | @@ -2375,7 +2356,7 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void { | ... | @@ -2375,7 +2356,7 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void { |
| 2375 | switch (err) { | 2356 | switch (err) { |
| 2376 | 0 => return, | 2357 | 0 => return, |
| 2377 | posix.EADDRINUSE => return PosixListenError.AddressInUse, | 2358 | posix.EADDRINUSE => return PosixListenError.AddressInUse, |
| 2378 | posix.EBADF => return PosixListenError.InvalidFileDescriptor, | 2359 | posix.EBADF => unreachable, |
| 2379 | posix.ENOTSOCK => return PosixListenError.FileDescriptorNotASocket, | 2360 | posix.ENOTSOCK => return PosixListenError.FileDescriptorNotASocket, |
| 2380 | posix.EOPNOTSUPP => return PosixListenError.OperationNotSupported, | 2361 | posix.EOPNOTSUPP => return PosixListenError.OperationNotSupported, |
| 2381 | else => return unexpectedErrorPosix(err), | 2362 | else => return unexpectedErrorPosix(err), |
| ... | @@ -2383,21 +2364,8 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void { | ... | @@ -2383,21 +2364,8 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void { |
| 2383 | } | 2364 | } |
| 2384 | 2365 | ||
| 2385 | pub const PosixAcceptError = error{ | 2366 | pub const PosixAcceptError = error{ |
| 2386 | /// The socket is marked nonblocking and no connections are present to be accepted. | ||
| 2387 | WouldBlock, | ||
| 2388 | |||
| 2389 | /// sockfd is not an open file descriptor. | ||
| 2390 | FileDescriptorClosed, | ||
| 2391 | |||
| 2392 | ConnectionAborted, | 2367 | ConnectionAborted, |
| 2393 | 2368 | ||
| 2394 | /// The addr argument is not in a writable part of the user address space. | ||
| 2395 | PageFault, | ||
| 2396 | |||
| 2397 | /// Socket is not listening for connections, or addrlen is invalid (e.g., is negative), | ||
| 2398 | /// or invalid value in flags. | ||
| 2399 | InvalidSyscall, | ||
| 2400 | |||
| 2401 | /// The per-process limit on the number of open file descriptors has been reached. | 2369 | /// The per-process limit on the number of open file descriptors has been reached. |
| 2402 | ProcessFdQuotaExceeded, | 2370 | ProcessFdQuotaExceeded, |
| 2403 | 2371 | ||
| ... | @@ -2433,14 +2401,15 @@ pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError! | ... | @@ -2433,14 +2401,15 @@ pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError! |
| 2433 | posix.EINTR => continue, | 2401 | posix.EINTR => continue, |
| 2434 | else => return unexpectedErrorPosix(err), | 2402 | else => return unexpectedErrorPosix(err), |
| 2435 | 2403 | ||
| 2436 | posix.EAGAIN => return PosixAcceptError.WouldBlock, | 2404 | posix.EAGAIN => unreachable, // use posixAsyncAccept for non-blocking |
| 2437 | posix.EBADF => return PosixAcceptError.FileDescriptorClosed, | 2405 | posix.EBADF => unreachable, // always a race condition |
| 2438 | posix.ECONNABORTED => return PosixAcceptError.ConnectionAborted, | 2406 | posix.ECONNABORTED => return PosixAcceptError.ConnectionAborted, |
| 2439 | posix.EFAULT => return PosixAcceptError.PageFault, | 2407 | posix.EFAULT => unreachable, |
| 2440 | posix.EINVAL => return PosixAcceptError.InvalidSyscall, | 2408 | posix.EINVAL => unreachable, |
| 2441 | posix.EMFILE => return PosixAcceptError.ProcessFdQuotaExceeded, | 2409 | posix.EMFILE => return PosixAcceptError.ProcessFdQuotaExceeded, |
| 2442 | posix.ENFILE => return PosixAcceptError.SystemFdQuotaExceeded, | 2410 | posix.ENFILE => return PosixAcceptError.SystemFdQuotaExceeded, |
| 2443 | posix.ENOBUFS, posix.ENOMEM => return PosixAcceptError.SystemResources, | 2411 | posix.ENOBUFS => return PosixAcceptError.SystemResources, |
| 2412 | posix.ENOMEM => return PosixAcceptError.SystemResources, | ||
| 2444 | posix.ENOTSOCK => return PosixAcceptError.FileDescriptorNotASocket, | 2413 | posix.ENOTSOCK => return PosixAcceptError.FileDescriptorNotASocket, |
| 2445 | posix.EOPNOTSUPP => return PosixAcceptError.OperationNotSupported, | 2414 | posix.EOPNOTSUPP => return PosixAcceptError.OperationNotSupported, |
| 2446 | posix.EPROTO => return PosixAcceptError.ProtocolFailure, | 2415 | posix.EPROTO => return PosixAcceptError.ProtocolFailure, |
| ... | @@ -2449,10 +2418,35 @@ pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError! | ... | @@ -2449,10 +2418,35 @@ pub fn posixAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError! |
| 2449 | } | 2418 | } |
| 2450 | } | 2419 | } |
| 2451 | 2420 | ||
| 2452 | pub const LinuxEpollCreateError = error{ | 2421 | /// Returns -1 if would block. |
| 2453 | /// Invalid value specified in flags. | 2422 | pub fn posixAsyncAccept(fd: i32, addr: *posix.sockaddr, flags: u32) PosixAcceptError!i32 { |
| 2454 | InvalidSyscall, | 2423 | while (true) { |
| 2424 | var sockaddr_size = u32(@sizeOf(posix.sockaddr)); | ||
| 2425 | const rc = posix.accept4(fd, addr, &sockaddr_size, flags); | ||
| 2426 | const err = posix.getErrno(rc); | ||
| 2427 | switch (err) { | ||
| 2428 | 0 => return @intCast(i32, rc), | ||
| 2429 | posix.EINTR => continue, | ||
| 2430 | else => return unexpectedErrorPosix(err), | ||
| 2431 | |||
| 2432 | posix.EAGAIN => return -1, | ||
| 2433 | posix.EBADF => unreachable, // always a race condition | ||
| 2434 | posix.ECONNABORTED => return PosixAcceptError.ConnectionAborted, | ||
| 2435 | posix.EFAULT => unreachable, | ||
| 2436 | posix.EINVAL => unreachable, | ||
| 2437 | posix.EMFILE => return PosixAcceptError.ProcessFdQuotaExceeded, | ||
| 2438 | posix.ENFILE => return PosixAcceptError.SystemFdQuotaExceeded, | ||
| 2439 | posix.ENOBUFS => return PosixAcceptError.SystemResources, | ||
| 2440 | posix.ENOMEM => return PosixAcceptError.SystemResources, | ||
| 2441 | posix.ENOTSOCK => return PosixAcceptError.FileDescriptorNotASocket, | ||
| 2442 | posix.EOPNOTSUPP => return PosixAcceptError.OperationNotSupported, | ||
| 2443 | posix.EPROTO => return PosixAcceptError.ProtocolFailure, | ||
| 2444 | posix.EPERM => return PosixAcceptError.BlockedByFirewall, | ||
| 2445 | } | ||
| 2446 | } | ||
| 2447 | } | ||
| 2455 | 2448 | ||
| 2449 | pub const LinuxEpollCreateError = error{ | ||
| 2456 | /// The per-user limit on the number of epoll instances imposed by | 2450 | /// The per-user limit on the number of epoll instances imposed by |
| 2457 | /// /proc/sys/fs/epoll/max_user_instances was encountered. See epoll(7) for further | 2451 | /// /proc/sys/fs/epoll/max_user_instances was encountered. See epoll(7) for further |
| 2458 | /// details. | 2452 | /// details. |
| ... | @@ -2476,7 +2470,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 { | ... | @@ -2476,7 +2470,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 { |
| 2476 | 0 => return @intCast(i32, rc), | 2470 | 0 => return @intCast(i32, rc), |
| 2477 | else => return unexpectedErrorPosix(err), | 2471 | else => return unexpectedErrorPosix(err), |
| 2478 | 2472 | ||
| 2479 | posix.EINVAL => return LinuxEpollCreateError.InvalidSyscall, | 2473 | posix.EINVAL => unreachable, |
| 2480 | posix.EMFILE => return LinuxEpollCreateError.ProcessFdQuotaExceeded, | 2474 | posix.EMFILE => return LinuxEpollCreateError.ProcessFdQuotaExceeded, |
| 2481 | posix.ENFILE => return LinuxEpollCreateError.SystemFdQuotaExceeded, | 2475 | posix.ENFILE => return LinuxEpollCreateError.SystemFdQuotaExceeded, |
| 2482 | posix.ENOMEM => return LinuxEpollCreateError.SystemResources, | 2476 | posix.ENOMEM => return LinuxEpollCreateError.SystemResources, |
| ... | @@ -2484,22 +2478,10 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 { | ... | @@ -2484,22 +2478,10 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 { |
| 2484 | } | 2478 | } |
| 2485 | 2479 | ||
| 2486 | pub const LinuxEpollCtlError = error{ | 2480 | pub const LinuxEpollCtlError = error{ |
| 2487 | /// epfd or fd is not a valid file descriptor. | ||
| 2488 | InvalidFileDescriptor, | ||
| 2489 | |||
| 2490 | /// op was EPOLL_CTL_ADD, and the supplied file descriptor fd is already registered | 2481 | /// op was EPOLL_CTL_ADD, and the supplied file descriptor fd is already registered |
| 2491 | /// with this epoll instance. | 2482 | /// with this epoll instance. |
| 2492 | FileDescriptorAlreadyPresentInSet, | 2483 | FileDescriptorAlreadyPresentInSet, |
| 2493 | 2484 | ||
| 2494 | /// epfd is not an epoll file descriptor, or fd is the same as epfd, or the requested | ||
| 2495 | /// operation op is not supported by this interface, or | ||
| 2496 | /// An invalid event type was specified along with EPOLLEXCLUSIVE in events, or | ||
| 2497 | /// op was EPOLL_CTL_MOD and events included EPOLLEXCLUSIVE, or | ||
| 2498 | /// op was EPOLL_CTL_MOD and the EPOLLEXCLUSIVE flag has previously been applied to | ||
| 2499 | /// this epfd, fd pair, or | ||
| 2500 | /// EPOLLEXCLUSIVE was specified in event and fd refers to an epoll instance. | ||
| 2501 | InvalidSyscall, | ||
| 2502 | |||
| 2503 | /// fd refers to an epoll instance and this EPOLL_CTL_ADD operation would result in a | 2485 | /// fd refers to an epoll instance and this EPOLL_CTL_ADD operation would result in a |
| 2504 | /// circular loop of epoll instances monitoring one another. | 2486 | /// circular loop of epoll instances monitoring one another. |
| 2505 | OperationCausesCircularLoop, | 2487 | OperationCausesCircularLoop, |
| ... | @@ -2531,9 +2513,9 @@ pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: *linux.epoll_event) Lin | ... | @@ -2531,9 +2513,9 @@ pub fn linuxEpollCtl(epfd: i32, op: u32, fd: i32, event: *linux.epoll_event) Lin |
| 2531 | 0 => return, | 2513 | 0 => return, |
| 2532 | else => return unexpectedErrorPosix(err), | 2514 | else => return unexpectedErrorPosix(err), |
| 2533 | 2515 | ||
| 2534 | posix.EBADF => return LinuxEpollCtlError.InvalidFileDescriptor, | 2516 | posix.EBADF => unreachable, // always a race condition if this happens |
| 2535 | posix.EEXIST => return LinuxEpollCtlError.FileDescriptorAlreadyPresentInSet, | 2517 | posix.EEXIST => return LinuxEpollCtlError.FileDescriptorAlreadyPresentInSet, |
| 2536 | posix.EINVAL => return LinuxEpollCtlError.InvalidSyscall, | 2518 | posix.EINVAL => unreachable, |
| 2537 | posix.ELOOP => return LinuxEpollCtlError.OperationCausesCircularLoop, | 2519 | posix.ELOOP => return LinuxEpollCtlError.OperationCausesCircularLoop, |
| 2538 | posix.ENOENT => return LinuxEpollCtlError.FileDescriptorNotRegistered, | 2520 | posix.ENOENT => return LinuxEpollCtlError.FileDescriptorNotRegistered, |
| 2539 | posix.ENOMEM => return LinuxEpollCtlError.SystemResources, | 2521 | posix.ENOMEM => return LinuxEpollCtlError.SystemResources, |
std/os/linux/index.zig+8| ... | @@ -793,6 +793,14 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { | ... | @@ -793,6 +793,14 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 793 | return syscall4(SYS_preadv, @intCast(usize, fd), @ptrToInt(iov), count, offset); | 793 | return syscall4(SYS_preadv, @intCast(usize, fd), @ptrToInt(iov), count, offset); |
| 794 | } | 794 | } |
| 795 | 795 | ||
| 796 | pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { | ||
| 797 | return syscall3(SYS_readv, @intCast(usize, fd), @ptrToInt(iov), count); | ||
| 798 | } | ||
| 799 | |||
| 800 | pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { | ||
| 801 | return syscall3(SYS_writev, @intCast(usize, fd), @ptrToInt(iov), count); | ||
| 802 | } | ||
| 803 | |||
| 796 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { | 804 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { |
| 797 | return syscall4(SYS_pwritev, @intCast(usize, fd), @ptrToInt(iov), count, offset); | 805 | return syscall4(SYS_pwritev, @intCast(usize, fd), @ptrToInt(iov), count, offset); |
| 798 | } | 806 | } |
std/pdb.zig+3-3| ... | @@ -482,7 +482,7 @@ const Msf = struct { | ... | @@ -482,7 +482,7 @@ const Msf = struct { |
| 482 | streams: []MsfStream, | 482 | streams: []MsfStream, |
| 483 | 483 | ||
| 484 | fn openFile(self: *Msf, allocator: *mem.Allocator, file: os.File) !void { | 484 | fn openFile(self: *Msf, allocator: *mem.Allocator, file: os.File) !void { |
| 485 | var file_stream = io.FileInStream.init(file); | 485 | var file_stream = file.inStream(); |
| 486 | const in = &file_stream.stream; | 486 | const in = &file_stream.stream; |
| 487 | 487 | ||
| 488 | var superblock: SuperBlock = undefined; | 488 | var superblock: SuperBlock = undefined; |
| ... | @@ -597,7 +597,7 @@ const MsfStream = struct { | ... | @@ -597,7 +597,7 @@ const MsfStream = struct { |
| 597 | .stream = Stream{ .readFn = readFn }, | 597 | .stream = Stream{ .readFn = readFn }, |
| 598 | }; | 598 | }; |
| 599 | 599 | ||
| 600 | var file_stream = io.FileInStream.init(file); | 600 | var file_stream = file.inStream(); |
| 601 | const in = &file_stream.stream; | 601 | const in = &file_stream.stream; |
| 602 | try file.seekTo(pos); | 602 | try file.seekTo(pos); |
| 603 | 603 | ||
| ... | @@ -627,7 +627,7 @@ const MsfStream = struct { | ... | @@ -627,7 +627,7 @@ const MsfStream = struct { |
| 627 | var offset = self.pos % self.block_size; | 627 | var offset = self.pos % self.block_size; |
| 628 | 628 | ||
| 629 | try self.in_file.seekTo(block * self.block_size + offset); | 629 | try self.in_file.seekTo(block * self.block_size + offset); |
| 630 | var file_stream = io.FileInStream.init(self.in_file); | 630 | var file_stream = self.in_file.inStream(); |
| 631 | const in = &file_stream.stream; | 631 | const in = &file_stream.stream; |
| 632 | 632 | ||
| 633 | var size: usize = 0; | 633 | var size: usize = 0; |
std/special/build_runner.zig+4-4| ... | @@ -48,16 +48,16 @@ pub fn main() !void { | ... | @@ -48,16 +48,16 @@ pub fn main() !void { |
| 48 | var prefix: ?[]const u8 = null; | 48 | var prefix: ?[]const u8 = null; |
| 49 | 49 | ||
| 50 | var stderr_file = io.getStdErr(); | 50 | var stderr_file = io.getStdErr(); |
| 51 | var stderr_file_stream: io.FileOutStream = undefined; | 51 | var stderr_file_stream: os.File.OutStream = undefined; |
| 52 | var stderr_stream = if (stderr_file) |f| x: { | 52 | var stderr_stream = if (stderr_file) |f| x: { |
| 53 | stderr_file_stream = io.FileOutStream.init(f); | 53 | stderr_file_stream = f.outStream(); |
| 54 | break :x &stderr_file_stream.stream; | 54 | break :x &stderr_file_stream.stream; |
| 55 | } else |err| err; | 55 | } else |err| err; |
| 56 | 56 | ||
| 57 | var stdout_file = io.getStdOut(); | 57 | var stdout_file = io.getStdOut(); |
| 58 | var stdout_file_stream: io.FileOutStream = undefined; | 58 | var stdout_file_stream: os.File.OutStream = undefined; |
| 59 | var stdout_stream = if (stdout_file) |f| x: { | 59 | var stdout_stream = if (stdout_file) |f| x: { |
| 60 | stdout_file_stream = io.FileOutStream.init(f); | 60 | stdout_file_stream = f.outStream(); |
| 61 | break :x &stdout_file_stream.stream; | 61 | break :x &stdout_file_stream.stream; |
| 62 | } else |err| err; | 62 | } else |err| err; |
| 63 | 63 |
std/zig/bench.zig+1-1| ... | @@ -24,7 +24,7 @@ pub fn main() !void { | ... | @@ -24,7 +24,7 @@ pub fn main() !void { |
| 24 | const mb_per_sec = bytes_per_sec / (1024 * 1024); | 24 | const mb_per_sec = bytes_per_sec / (1024 * 1024); |
| 25 | 25 | ||
| 26 | var stdout_file = try std.io.getStdOut(); | 26 | var stdout_file = try std.io.getStdOut(); |
| 27 | const stdout = &std.io.FileOutStream.init(stdout_file).stream; | 27 | const stdout = &stdout_file.outStream().stream; |
| 28 | try stdout.print("{.3} MiB/s, {} KiB used \n", mb_per_sec, memory_used / 1024); | 28 | try stdout.print("{.3} MiB/s, {} KiB used \n", mb_per_sec, memory_used / 1024); |
| 29 | } | 29 | } |
| 30 | 30 |
std/zig/parser_test.zig+1-1| ... | @@ -1873,7 +1873,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined; | ... | @@ -1873,7 +1873,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1873 | 1873 | ||
| 1874 | fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 { | 1874 | fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 { |
| 1875 | var stderr_file = try io.getStdErr(); | 1875 | var stderr_file = try io.getStdErr(); |
| 1876 | var stderr = &io.FileOutStream.init(stderr_file).stream; | 1876 | var stderr = &stderr_file.outStream().stream; |
| 1877 | 1877 | ||
| 1878 | var tree = try std.zig.parse(allocator, source); | 1878 | var tree = try std.zig.parse(allocator, source); |
| 1879 | defer tree.deinit(); | 1879 | defer tree.deinit(); |
test/compare_output.zig+15-15| ... | @@ -19,7 +19,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -19,7 +19,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 19 | \\ | 19 | \\ |
| 20 | \\pub fn main() void { | 20 | \\pub fn main() void { |
| 21 | \\ privateFunction(); | 21 | \\ privateFunction(); |
| 22 | \\ const stdout = &FileOutStream.init(getStdOut() catch unreachable).stream; | 22 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; |
| 23 | \\ stdout.print("OK 2\n") catch unreachable; | 23 | \\ stdout.print("OK 2\n") catch unreachable; |
| 24 | \\} | 24 | \\} |
| 25 | \\ | 25 | \\ |
| ... | @@ -34,7 +34,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -34,7 +34,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 34 | \\// purposefully conflicting function with main.zig | 34 | \\// purposefully conflicting function with main.zig |
| 35 | \\// but it's private so it should be OK | 35 | \\// but it's private so it should be OK |
| 36 | \\fn privateFunction() void { | 36 | \\fn privateFunction() void { |
| 37 | \\ const stdout = &FileOutStream.init(getStdOut() catch unreachable).stream; | 37 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; |
| 38 | \\ stdout.print("OK 1\n") catch unreachable; | 38 | \\ stdout.print("OK 1\n") catch unreachable; |
| 39 | \\} | 39 | \\} |
| 40 | \\ | 40 | \\ |
| ... | @@ -60,7 +60,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -60,7 +60,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 60 | tc.addSourceFile("foo.zig", | 60 | tc.addSourceFile("foo.zig", |
| 61 | \\use @import("std").io; | 61 | \\use @import("std").io; |
| 62 | \\pub fn foo_function() void { | 62 | \\pub fn foo_function() void { |
| 63 | \\ const stdout = &FileOutStream.init(getStdOut() catch unreachable).stream; | 63 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; |
| 64 | \\ stdout.print("OK\n") catch unreachable; | 64 | \\ stdout.print("OK\n") catch unreachable; |
| 65 | \\} | 65 | \\} |
| 66 | ); | 66 | ); |
| ... | @@ -71,7 +71,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -71,7 +71,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 71 | \\ | 71 | \\ |
| 72 | \\pub fn bar_function() void { | 72 | \\pub fn bar_function() void { |
| 73 | \\ if (foo_function()) { | 73 | \\ if (foo_function()) { |
| 74 | \\ const stdout = &FileOutStream.init(getStdOut() catch unreachable).stream; | 74 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; |
| 75 | \\ stdout.print("OK\n") catch unreachable; | 75 | \\ stdout.print("OK\n") catch unreachable; |
| 76 | \\ } | 76 | \\ } |
| 77 | \\} | 77 | \\} |
| ... | @@ -103,7 +103,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -103,7 +103,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 103 | \\pub const a_text = "OK\n"; | 103 | \\pub const a_text = "OK\n"; |
| 104 | \\ | 104 | \\ |
| 105 | \\pub fn ok() void { | 105 | \\pub fn ok() void { |
| 106 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 106 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 107 | \\ stdout.print(b_text) catch unreachable; | 107 | \\ stdout.print(b_text) catch unreachable; |
| 108 | \\} | 108 | \\} |
| 109 | ); | 109 | ); |
| ... | @@ -121,7 +121,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -121,7 +121,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 121 | \\const io = @import("std").io; | 121 | \\const io = @import("std").io; |
| 122 | \\ | 122 | \\ |
| 123 | \\pub fn main() void { | 123 | \\pub fn main() void { |
| 124 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 124 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 125 | \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; | 125 | \\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable; |
| 126 | \\} | 126 | \\} |
| 127 | , "Hello, world!\n0012 012 a\n"); | 127 | , "Hello, world!\n0012 012 a\n"); |
| ... | @@ -274,7 +274,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -274,7 +274,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 274 | \\ var x_local : i32 = print_ok(x); | 274 | \\ var x_local : i32 = print_ok(x); |
| 275 | \\} | 275 | \\} |
| 276 | \\fn print_ok(val: @typeOf(x)) @typeOf(foo) { | 276 | \\fn print_ok(val: @typeOf(x)) @typeOf(foo) { |
| 277 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 277 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 278 | \\ stdout.print("OK\n") catch unreachable; | 278 | \\ stdout.print("OK\n") catch unreachable; |
| 279 | \\ return 0; | 279 | \\ return 0; |
| 280 | \\} | 280 | \\} |
| ... | @@ -356,7 +356,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -356,7 +356,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 356 | \\pub fn main() void { | 356 | \\pub fn main() void { |
| 357 | \\ const bar = Bar {.field2 = 13,}; | 357 | \\ const bar = Bar {.field2 = 13,}; |
| 358 | \\ const foo = Foo {.field1 = bar,}; | 358 | \\ const foo = Foo {.field1 = bar,}; |
| 359 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 359 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 360 | \\ if (!foo.method()) { | 360 | \\ if (!foo.method()) { |
| 361 | \\ stdout.print("BAD\n") catch unreachable; | 361 | \\ stdout.print("BAD\n") catch unreachable; |
| 362 | \\ } | 362 | \\ } |
| ... | @@ -370,7 +370,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -370,7 +370,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 370 | cases.add("defer with only fallthrough", | 370 | cases.add("defer with only fallthrough", |
| 371 | \\const io = @import("std").io; | 371 | \\const io = @import("std").io; |
| 372 | \\pub fn main() void { | 372 | \\pub fn main() void { |
| 373 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 373 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 374 | \\ stdout.print("before\n") catch unreachable; | 374 | \\ stdout.print("before\n") catch unreachable; |
| 375 | \\ defer stdout.print("defer1\n") catch unreachable; | 375 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 376 | \\ defer stdout.print("defer2\n") catch unreachable; | 376 | \\ defer stdout.print("defer2\n") catch unreachable; |
| ... | @@ -383,7 +383,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -383,7 +383,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 383 | \\const io = @import("std").io; | 383 | \\const io = @import("std").io; |
| 384 | \\const os = @import("std").os; | 384 | \\const os = @import("std").os; |
| 385 | \\pub fn main() void { | 385 | \\pub fn main() void { |
| 386 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 386 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 387 | \\ stdout.print("before\n") catch unreachable; | 387 | \\ stdout.print("before\n") catch unreachable; |
| 388 | \\ defer stdout.print("defer1\n") catch unreachable; | 388 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 389 | \\ defer stdout.print("defer2\n") catch unreachable; | 389 | \\ defer stdout.print("defer2\n") catch unreachable; |
| ... | @@ -400,7 +400,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -400,7 +400,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 400 | \\ do_test() catch return; | 400 | \\ do_test() catch return; |
| 401 | \\} | 401 | \\} |
| 402 | \\fn do_test() !void { | 402 | \\fn do_test() !void { |
| 403 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 403 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 404 | \\ stdout.print("before\n") catch unreachable; | 404 | \\ stdout.print("before\n") catch unreachable; |
| 405 | \\ defer stdout.print("defer1\n") catch unreachable; | 405 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 406 | \\ errdefer stdout.print("deferErr\n") catch unreachable; | 406 | \\ errdefer stdout.print("deferErr\n") catch unreachable; |
| ... | @@ -419,7 +419,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -419,7 +419,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 419 | \\ do_test() catch return; | 419 | \\ do_test() catch return; |
| 420 | \\} | 420 | \\} |
| 421 | \\fn do_test() !void { | 421 | \\fn do_test() !void { |
| 422 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 422 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 423 | \\ stdout.print("before\n") catch unreachable; | 423 | \\ stdout.print("before\n") catch unreachable; |
| 424 | \\ defer stdout.print("defer1\n") catch unreachable; | 424 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 425 | \\ errdefer stdout.print("deferErr\n") catch unreachable; | 425 | \\ errdefer stdout.print("deferErr\n") catch unreachable; |
| ... | @@ -436,7 +436,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -436,7 +436,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 436 | \\const io = @import("std").io; | 436 | \\const io = @import("std").io; |
| 437 | \\ | 437 | \\ |
| 438 | \\pub fn main() void { | 438 | \\pub fn main() void { |
| 439 | \\ const stdout = &io.FileOutStream.init(io.getStdOut() catch unreachable).stream; | 439 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; |
| 440 | \\ stdout.print(foo_txt) catch unreachable; | 440 | \\ stdout.print(foo_txt) catch unreachable; |
| 441 | \\} | 441 | \\} |
| 442 | , "1234\nabcd\n"); | 442 | , "1234\nabcd\n"); |
| ... | @@ -456,7 +456,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -456,7 +456,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 456 | \\pub fn main() !void { | 456 | \\pub fn main() !void { |
| 457 | \\ var args_it = os.args(); | 457 | \\ var args_it = os.args(); |
| 458 | \\ var stdout_file = try io.getStdOut(); | 458 | \\ var stdout_file = try io.getStdOut(); |
| 459 | \\ var stdout_adapter = io.FileOutStream.init(stdout_file); | 459 | \\ var stdout_adapter = stdout_file.outStream(); |
| 460 | \\ const stdout = &stdout_adapter.stream; | 460 | \\ const stdout = &stdout_adapter.stream; |
| 461 | \\ var index: usize = 0; | 461 | \\ var index: usize = 0; |
| 462 | \\ _ = args_it.skip(); | 462 | \\ _ = args_it.skip(); |
| ... | @@ -497,7 +497,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -497,7 +497,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 497 | \\pub fn main() !void { | 497 | \\pub fn main() !void { |
| 498 | \\ var args_it = os.args(); | 498 | \\ var args_it = os.args(); |
| 499 | \\ var stdout_file = try io.getStdOut(); | 499 | \\ var stdout_file = try io.getStdOut(); |
| 500 | \\ var stdout_adapter = io.FileOutStream.init(stdout_file); | 500 | \\ var stdout_adapter = stdout_file.outStream(); |
| 501 | \\ const stdout = &stdout_adapter.stream; | 501 | \\ const stdout = &stdout_adapter.stream; |
| 502 | \\ var index: usize = 0; | 502 | \\ var index: usize = 0; |
| 503 | \\ _ = args_it.skip(); | 503 | \\ _ = args_it.skip(); |
test/standalone/brace_expansion/main.zig+1-1| ... | @@ -191,7 +191,7 @@ pub fn main() !void { | ... | @@ -191,7 +191,7 @@ pub fn main() !void { |
| 191 | var stdin_buf = try Buffer.initSize(global_allocator, 0); | 191 | var stdin_buf = try Buffer.initSize(global_allocator, 0); |
| 192 | defer stdin_buf.deinit(); | 192 | defer stdin_buf.deinit(); |
| 193 | 193 | ||
| 194 | var stdin_adapter = io.FileInStream.init(stdin_file); | 194 | var stdin_adapter = stdin_file.inStream(); |
| 195 | try stdin_adapter.stream.readAllBuffer(&stdin_buf, @maxValue(usize)); | 195 | try stdin_adapter.stream.readAllBuffer(&stdin_buf, @maxValue(usize)); |
| 196 | 196 | ||
| 197 | var result_buf = try Buffer.initSize(global_allocator, 0); | 197 | var result_buf = try Buffer.initSize(global_allocator, 0); |
test/tests.zig+6-6| ... | @@ -278,8 +278,8 @@ pub const CompareOutputContext = struct { | ... | @@ -278,8 +278,8 @@ pub const CompareOutputContext = struct { |
| 278 | var stdout = Buffer.initNull(b.allocator); | 278 | var stdout = Buffer.initNull(b.allocator); |
| 279 | var stderr = Buffer.initNull(b.allocator); | 279 | var stderr = Buffer.initNull(b.allocator); |
| 280 | 280 | ||
| 281 | var stdout_file_in_stream = io.FileInStream.init(child.stdout.?); | 281 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 282 | var stderr_file_in_stream = io.FileInStream.init(child.stderr.?); | 282 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 283 | 283 | ||
| 284 | stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable; | 284 | stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable; |
| 285 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; | 285 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; |
| ... | @@ -593,8 +593,8 @@ pub const CompileErrorContext = struct { | ... | @@ -593,8 +593,8 @@ pub const CompileErrorContext = struct { |
| 593 | var stdout_buf = Buffer.initNull(b.allocator); | 593 | var stdout_buf = Buffer.initNull(b.allocator); |
| 594 | var stderr_buf = Buffer.initNull(b.allocator); | 594 | var stderr_buf = Buffer.initNull(b.allocator); |
| 595 | 595 | ||
| 596 | var stdout_file_in_stream = io.FileInStream.init(child.stdout.?); | 596 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 597 | var stderr_file_in_stream = io.FileInStream.init(child.stderr.?); | 597 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 598 | 598 | ||
| 599 | stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; | 599 | stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; |
| 600 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | 600 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; |
| ... | @@ -857,8 +857,8 @@ pub const TranslateCContext = struct { | ... | @@ -857,8 +857,8 @@ pub const TranslateCContext = struct { |
| 857 | var stdout_buf = Buffer.initNull(b.allocator); | 857 | var stdout_buf = Buffer.initNull(b.allocator); |
| 858 | var stderr_buf = Buffer.initNull(b.allocator); | 858 | var stderr_buf = Buffer.initNull(b.allocator); |
| 859 | 859 | ||
| 860 | var stdout_file_in_stream = io.FileInStream.init(child.stdout.?); | 860 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 861 | var stderr_file_in_stream = io.FileInStream.init(child.stderr.?); | 861 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 862 | 862 | ||
| 863 | stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; | 863 | stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; |
| 864 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | 864 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; |