authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-24 10:03:40-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-02-24 10:03:40-08:00
log6fddc9cd3d8002a44cf65e05d32c449bde6ca60c
tree92c2e96c3a8462fb0659a878e789b907a34d9ffa
parent88b3c144265b0e22250f21809bbf9329ecfcfd6f
parent9812bc7b10d093f2041471b166e67748665c89c7
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19064 from ziglang/fix-netname-deleted

std: map NETNAME_DELETED to error.ConnectionResetByPeer

4 files changed, 19 insertions(+), 8 deletions(-)

lib/std/http/test.zig+11
...@@ -142,6 +142,17 @@ test "HTTP server handles a chunked transfer coding request" {...@@ -142,6 +142,17 @@ test "HTTP server handles a chunked transfer coding request" {
142 const stream = try std.net.tcpConnectToHost(gpa, "127.0.0.1", test_server.port());142 const stream = try std.net.tcpConnectToHost(gpa, "127.0.0.1", test_server.port());
143 defer stream.close();143 defer stream.close();
144 try stream.writeAll(request_bytes);144 try stream.writeAll(request_bytes);
145
146 const response = try stream.reader().readAllAlloc(gpa, 100);
147 defer gpa.free(response);
148
149 const expected_response =
150 "HTTP/1.1 200 OK\r\n" ++
151 "content-length: 21\r\n" ++
152 "content-type: text/plain\r\n" ++
153 "\r\n" ++
154 "message from server!\n";
155 try expectEqualStrings(expected_response, response);
145}156}
146157
147test "echo content server" {158test "echo content server" {
lib/std/os.zig-3
...@@ -836,9 +836,6 @@ pub const ReadError = error{...@@ -836,9 +836,6 @@ pub const ReadError = error{
836 NotOpenForReading,836 NotOpenForReading,
837 SocketNotConnected,837 SocketNotConnected,
838838
839 // Windows only
840 NetNameDeleted,
841
842 /// This error occurs when no global event loop is configured,839 /// This error occurs when no global event loop is configured,
843 /// and reading from the file descriptor would block.840 /// and reading from the file descriptor would block.
844 WouldBlock,841 WouldBlock,
lib/std/os/windows.zig+8-4
...@@ -453,7 +453,8 @@ pub fn FindClose(hFindFile: HANDLE) void {...@@ -453,7 +453,8 @@ pub fn FindClose(hFindFile: HANDLE) void {
453453
454pub const ReadFileError = error{454pub const ReadFileError = error{
455 BrokenPipe,455 BrokenPipe,
456 NetNameDeleted,456 /// The specified network name is no longer available.
457 ConnectionResetByPeer,
457 OperationAborted,458 OperationAborted,
458 Unexpected,459 Unexpected,
459};460};
...@@ -485,7 +486,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64) ReadFileError!usiz...@@ -485,7 +486,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64) ReadFileError!usiz
485 .OPERATION_ABORTED => continue,486 .OPERATION_ABORTED => continue,
486 .BROKEN_PIPE => return 0,487 .BROKEN_PIPE => return 0,
487 .HANDLE_EOF => return 0,488 .HANDLE_EOF => return 0,
488 .NETNAME_DELETED => return error.NetNameDeleted,489 .NETNAME_DELETED => return error.ConnectionResetByPeer,
489 else => |err| return unexpectedError(err),490 else => |err| return unexpectedError(err),
490 }491 }
491 }492 }
...@@ -501,6 +502,8 @@ pub const WriteFileError = error{...@@ -501,6 +502,8 @@ pub const WriteFileError = error{
501 /// The process cannot access the file because another process has locked502 /// The process cannot access the file because another process has locked
502 /// a portion of the file.503 /// a portion of the file.
503 LockViolation,504 LockViolation,
505 /// The specified network name is no longer available.
506 ConnectionResetByPeer,
504 Unexpected,507 Unexpected,
505};508};
506509
...@@ -517,8 +520,8 @@ pub fn WriteFile(...@@ -517,8 +520,8 @@ pub fn WriteFile(
517 .InternalHigh = 0,520 .InternalHigh = 0,
518 .DUMMYUNIONNAME = .{521 .DUMMYUNIONNAME = .{
519 .DUMMYSTRUCTNAME = .{522 .DUMMYSTRUCTNAME = .{
520 .Offset = @as(u32, @truncate(off)),523 .Offset = @truncate(off),
521 .OffsetHigh = @as(u32, @truncate(off >> 32)),524 .OffsetHigh = @truncate(off >> 32),
522 },525 },
523 },526 },
524 .hEvent = null,527 .hEvent = null,
...@@ -536,6 +539,7 @@ pub fn WriteFile(...@@ -536,6 +539,7 @@ pub fn WriteFile(
536 .BROKEN_PIPE => return error.BrokenPipe,539 .BROKEN_PIPE => return error.BrokenPipe,
537 .INVALID_HANDLE => return error.NotOpenForWriting,540 .INVALID_HANDLE => return error.NotOpenForWriting,
538 .LOCK_VIOLATION => return error.LockViolation,541 .LOCK_VIOLATION => return error.LockViolation,
542 .NETNAME_DELETED => return error.ConnectionResetByPeer,
539 else => |err| return unexpectedError(err),543 else => |err| return unexpectedError(err),
540 }544 }
541 }545 }
lib/std/zig/system.zig-1
...@@ -1103,7 +1103,6 @@ fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {...@@ -1103,7 +1103,6 @@ fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
1103 error.ConnectionResetByPeer => return error.UnableToReadElfFile,1103 error.ConnectionResetByPeer => return error.UnableToReadElfFile,
1104 error.ConnectionTimedOut => return error.UnableToReadElfFile,1104 error.ConnectionTimedOut => return error.UnableToReadElfFile,
1105 error.SocketNotConnected => return error.UnableToReadElfFile,1105 error.SocketNotConnected => return error.UnableToReadElfFile,
1106 error.NetNameDeleted => return error.UnableToReadElfFile,
1107 error.Unexpected => return error.Unexpected,1106 error.Unexpected => return error.Unexpected,
1108 error.InputOutput => return error.FileSystem,1107 error.InputOutput => return error.FileSystem,
1109 error.AccessDenied => return error.Unexpected,1108 error.AccessDenied => return error.Unexpected,