| author | |
| committer | |
| log | 7f5bb118d4d90e2b883ee66e17592ac8d7808ac8 |
| tree | a9ea1f3ad962cdfb7597b6e1a1d89982f7199c35 |
| parent | 6f46570958af8ae27308eb4a9470e05f33aaa522 |
6 files changed, 29 insertions(+), 23 deletions(-)
lib/std/Build/Step/WriteFile.zig+1-7| ... | ... | @@ -208,7 +208,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 208 | 208 | |
| 209 | 209 | const open_dir_cache = try arena.alloc(Io.Dir, write_file.directories.items.len); |
| 210 | 210 | var open_dirs_count: usize = 0; |
| 211 | defer closeDirs(open_dir_cache[0..open_dirs_count]); | |
| 211 | defer Io.Dir.closeMany(io, open_dir_cache[0..open_dirs_count]); | |
| 212 | 212 | |
| 213 | 213 | for (write_file.directories.items, open_dir_cache) |dir, *open_dir_cache_elem| { |
| 214 | 214 | man.hash.addBytes(dir.sub_path); |
| ... | ... | @@ -341,9 +341,3 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 341 | 341 | |
| 342 | 342 | try step.writeManifest(&man); |
| 343 | 343 | } |
| 344 | ||
| 345 | fn closeDirs(io: Io, dirs: []Io.Dir) void { | |
| 346 | var group: Io.Group = .init; | |
| 347 | defer group.wait(); | |
| 348 | for (dirs) |d| group.async(Io.Dir.close, .{ d, io }); | |
| 349 | } |
lib/std/Io.zig+3-3| ... | ... | @@ -671,7 +671,7 @@ pub const VTable = struct { |
| 671 | 671 | dirCreateFile: *const fn (?*anyopaque, Dir, []const u8, File.CreateFlags) File.OpenError!File, |
| 672 | 672 | dirOpenFile: *const fn (?*anyopaque, Dir, []const u8, File.OpenFlags) File.OpenError!File, |
| 673 | 673 | dirOpenDir: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.OpenError!Dir, |
| 674 | dirClose: *const fn (?*anyopaque, Dir) void, | |
| 674 | dirClose: *const fn (?*anyopaque, []const Dir) void, | |
| 675 | 675 | dirRead: *const fn (?*anyopaque, *Dir.Reader, []Dir.Entry) Dir.Reader.Error!usize, |
| 676 | 676 | dirRealPath: *const fn (?*anyopaque, Dir, path_name: []const u8, out_buffer: []u8) Dir.RealPathError!usize, |
| 677 | 677 | dirDeleteFile: *const fn (?*anyopaque, Dir, []const u8) Dir.DeleteFileError!void, |
| ... | ... | @@ -686,7 +686,7 @@ pub const VTable = struct { |
| 686 | 686 | |
| 687 | 687 | fileStat: *const fn (?*anyopaque, File) File.StatError!File.Stat, |
| 688 | 688 | fileLength: *const fn (?*anyopaque, File) File.LengthError!u64, |
| 689 | fileClose: *const fn (?*anyopaque, File) void, | |
| 689 | fileClose: *const fn (?*anyopaque, []const File) void, | |
| 690 | 690 | fileWriteStreaming: *const fn (?*anyopaque, File, header: []const u8, data: []const []const u8, splat: usize) File.Writer.Error!usize, |
| 691 | 691 | fileWritePositional: *const fn (?*anyopaque, File, header: []const u8, data: []const []const u8, splat: usize, offset: u64) File.WritePositionalError!usize, |
| 692 | 692 | fileWriteFileStreaming: *const fn (?*anyopaque, File, header: []const u8, *Io.File.Reader, Io.Limit) File.Writer.WriteFileError!usize, |
| ... | ... | @@ -729,7 +729,7 @@ pub const VTable = struct { |
| 729 | 729 | netRead: *const fn (?*anyopaque, src: net.Socket.Handle, data: [][]u8) net.Stream.Reader.Error!usize, |
| 730 | 730 | netWrite: *const fn (?*anyopaque, dest: net.Socket.Handle, header: []const u8, data: []const []const u8, splat: usize) net.Stream.Writer.Error!usize, |
| 731 | 731 | netWriteFile: *const fn (?*anyopaque, net.Socket.Handle, header: []const u8, *Io.File.Reader, Io.Limit) net.Stream.Writer.WriteFileError!usize, |
| 732 | netClose: *const fn (?*anyopaque, handle: net.Socket.Handle) void, | |
| 732 | netClose: *const fn (?*anyopaque, handle: []const net.Socket.Handle) void, | |
| 733 | 733 | netInterfaceNameResolve: *const fn (?*anyopaque, *const net.Interface.Name) net.Interface.Name.ResolveError!net.Interface, |
| 734 | 734 | netInterfaceName: *const fn (?*anyopaque, net.Interface) net.Interface.NameError!net.Interface.Name, |
| 735 | 735 | netLookup: *const fn (?*anyopaque, net.HostName, *Queue(net.HostName.LookupResult), net.HostName.LookupOptions) net.HostName.LookupError!void, |
lib/std/Io/Dir.zig+5-1| ... | ... | @@ -446,7 +446,11 @@ pub fn openDirAbsolute(io: Io, absolute_path: []const u8, options: OpenOptions) |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | pub fn close(dir: Dir, io: Io) void { |
| 449 | return io.vtable.dirClose(io.userdata, dir); | |
| 449 | return io.vtable.dirClose(io.userdata, (&dir)[0..1]); | |
| 450 | } | |
| 451 | ||
| 452 | pub fn closeMany(io: Io, dirs: []const Dir) void { | |
| 453 | return io.vtable.dirClose(io.userdata, dirs); | |
| 450 | 454 | } |
| 451 | 455 | |
| 452 | 456 | /// Opens a file for reading or writing, without attempting to create a new file. |
lib/std/Io/File.zig+5-1| ... | ... | @@ -252,7 +252,11 @@ pub const OpenError = error{ |
| 252 | 252 | } || Io.Dir.PathNameError || Io.Cancelable || Io.UnexpectedError; |
| 253 | 253 | |
| 254 | 254 | pub fn close(file: File, io: Io) void { |
| 255 | return io.vtable.fileClose(io.userdata, file); | |
| 255 | return io.vtable.fileClose(io.userdata, (&file)[0..1]); | |
| 256 | } | |
| 257 | ||
| 258 | pub fn closeMany(io: Io, files: []const File) void { | |
| 259 | return io.vtable.fileClose(io.userdata, files); | |
| 256 | 260 | } |
| 257 | 261 | |
| 258 | 262 | pub const SyncError = error{ |
lib/std/Io/Threaded.zig+9-9| ... | ... | @@ -3243,10 +3243,10 @@ const MakeOpenDirAccessMaskWOptions = struct { |
| 3243 | 3243 | create_disposition: u32, |
| 3244 | 3244 | }; |
| 3245 | 3245 | |
| 3246 | fn dirClose(userdata: ?*anyopaque, dir: Dir) void { | |
| 3246 | fn dirClose(userdata: ?*anyopaque, dirs: []const Dir) void { | |
| 3247 | 3247 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 3248 | 3248 | _ = t; |
| 3249 | posix.close(dir.handle); | |
| 3249 | for (dirs) |dir| posix.close(dir.handle); | |
| 3250 | 3250 | } |
| 3251 | 3251 | |
| 3252 | 3252 | const dirRealPath = switch (native_os) { |
| ... | ... | @@ -5515,10 +5515,10 @@ fn dirOpenDirWasi( |
| 5515 | 5515 | } |
| 5516 | 5516 | } |
| 5517 | 5517 | |
| 5518 | fn fileClose(userdata: ?*anyopaque, file: File) void { | |
| 5518 | fn fileClose(userdata: ?*anyopaque, files: []const File) void { | |
| 5519 | 5519 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 5520 | 5520 | _ = t; |
| 5521 | posix.close(file.handle); | |
| 5521 | for (files) |file| posix.close(file.handle); | |
| 5522 | 5522 | } |
| 5523 | 5523 | |
| 5524 | 5524 | const fileReadStreaming = switch (native_os) { |
| ... | ... | @@ -9084,18 +9084,18 @@ fn addBuf(v: []posix.iovec_const, i: *iovlen_t, bytes: []const u8) void { |
| 9084 | 9084 | i.* += 1; |
| 9085 | 9085 | } |
| 9086 | 9086 | |
| 9087 | fn netClose(userdata: ?*anyopaque, handle: net.Socket.Handle) void { | |
| 9087 | fn netClose(userdata: ?*anyopaque, handles: []const net.Socket.Handle) void { | |
| 9088 | 9088 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 9089 | 9089 | _ = t; |
| 9090 | 9090 | switch (native_os) { |
| 9091 | .windows => closeSocketWindows(handle), | |
| 9092 | else => posix.close(handle), | |
| 9091 | .windows => for (handles) |handle| closeSocketWindows(handle), | |
| 9092 | else => for (handles) |handle| posix.close(handle), | |
| 9093 | 9093 | } |
| 9094 | 9094 | } |
| 9095 | 9095 | |
| 9096 | fn netCloseUnavailable(userdata: ?*anyopaque, handle: net.Socket.Handle) void { | |
| 9096 | fn netCloseUnavailable(userdata: ?*anyopaque, handles: []const net.Socket.Handle) void { | |
| 9097 | 9097 | _ = userdata; |
| 9098 | _ = handle; | |
| 9098 | _ = handles; | |
| 9099 | 9099 | unreachable; // How you gonna close something that was impossible to open? |
| 9100 | 9100 | } |
| 9101 | 9101 |
lib/std/Io/net.zig+6-2| ... | ... | @@ -1043,7 +1043,11 @@ pub const Socket = struct { |
| 1043 | 1043 | |
| 1044 | 1044 | /// Leaves `address` in a valid state. |
| 1045 | 1045 | pub fn close(s: *const Socket, io: Io) void { |
| 1046 | io.vtable.netClose(io.userdata, s.handle); | |
| 1046 | io.vtable.netClose(io.userdata, (&s.handle)[0..1]); | |
| 1047 | } | |
| 1048 | ||
| 1049 | pub fn closeMany(io: Io, sockets: []const Socket) void { | |
| 1050 | io.vtable.netClose(io.userdata, sockets); | |
| 1047 | 1051 | } |
| 1048 | 1052 | |
| 1049 | 1053 | pub const SendError = error{ |
| ... | ... | @@ -1184,7 +1188,7 @@ pub const Stream = struct { |
| 1184 | 1188 | const max_iovecs_len = 8; |
| 1185 | 1189 | |
| 1186 | 1190 | pub fn close(s: *const Stream, io: Io) void { |
| 1187 | io.vtable.netClose(io.userdata, s.socket.handle); | |
| 1191 | io.vtable.netClose(io.userdata, (&s.socket.handle)[0..1]); | |
| 1188 | 1192 | } |
| 1189 | 1193 | |
| 1190 | 1194 | pub const Reader = struct { |