From 9812bc7b10d093f2041471b166e67748665c89c7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 24 Feb 2024 04:16:53 -0700 Subject: [PATCH] std: map NETNAME_DELETED to error.ConnectionResetByPeer This was observed in writing to a network stream that was closed on the read end. --- lib/std/os.zig | 3 --- lib/std/os/windows.zig | 12 ++++++++---- lib/std/zig/system.zig | 1 - 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 87402e49a3..6d016822c4 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -836,9 +836,6 @@ pub const ReadError = error{ NotOpenForReading, SocketNotConnected, - // Windows only - NetNameDeleted, - /// This error occurs when no global event loop is configured, /// and reading from the file descriptor would block. WouldBlock, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index ccbcba6883..1b4b13647b 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -453,7 +453,8 @@ pub fn FindClose(hFindFile: HANDLE) void { pub const ReadFileError = error{ BrokenPipe, - NetNameDeleted, + /// The specified network name is no longer available. + ConnectionResetByPeer, OperationAborted, Unexpected, }; @@ -485,7 +486,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64) ReadFileError!usiz .OPERATION_ABORTED => continue, .BROKEN_PIPE => return 0, .HANDLE_EOF => return 0, - .NETNAME_DELETED => return error.NetNameDeleted, + .NETNAME_DELETED => return error.ConnectionResetByPeer, else => |err| return unexpectedError(err), } } @@ -501,6 +502,8 @@ pub const WriteFileError = error{ /// The process cannot access the file because another process has locked /// a portion of the file. LockViolation, + /// The specified network name is no longer available. + ConnectionResetByPeer, Unexpected, }; @@ -517,8 +520,8 @@ pub fn WriteFile( .InternalHigh = 0, .DUMMYUNIONNAME = .{ .DUMMYSTRUCTNAME = .{ - .Offset = @as(u32, @truncate(off)), - .OffsetHigh = @as(u32, @truncate(off >> 32)), + .Offset = @truncate(off), + .OffsetHigh = @truncate(off >> 32), }, }, .hEvent = null, @@ -536,6 +539,7 @@ pub fn WriteFile( .BROKEN_PIPE => return error.BrokenPipe, .INVALID_HANDLE => return error.NotOpenForWriting, .LOCK_VIOLATION => return error.LockViolation, + .NETNAME_DELETED => return error.ConnectionResetByPeer, else => |err| return unexpectedError(err), } } diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 7e0aaaafa0..b29cf939d0 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -1103,7 +1103,6 @@ fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize { error.ConnectionResetByPeer => return error.UnableToReadElfFile, error.ConnectionTimedOut => return error.UnableToReadElfFile, error.SocketNotConnected => return error.UnableToReadElfFile, - error.NetNameDeleted => return error.UnableToReadElfFile, error.Unexpected => return error.Unexpected, error.InputOutput => return error.FileSystem, error.AccessDenied => return error.Unexpected,