io_interface: propagate cancellation errors
This commit is contained in:
+25
-25
@@ -508,7 +508,7 @@ fn dirCreateDir(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, permissio
|
|||||||
Node.CreateDirError.ComponentNotDirectory => Dir.CreateDirError.NotDir,
|
Node.CreateDirError.ComponentNotDirectory => Dir.CreateDirError.NotDir,
|
||||||
Node.CreateDirError.ComponentNotFound => Dir.CreateDirError.FileNotFound,
|
Node.CreateDirError.ComponentNotFound => Dir.CreateDirError.FileNotFound,
|
||||||
Node.CreateDirError.OutOfMemory => Dir.CreateDirError.SystemResources,
|
Node.CreateDirError.OutOfMemory => Dir.CreateDirError.SystemResources,
|
||||||
Node.CreateDirError.Canceled => @panic("TODO"),
|
Node.CreateDirError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -548,7 +548,7 @@ fn dirOpenDir(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, options: Di
|
|||||||
Node.OpenDirError.ResolutionLimit => Dir.OpenError.NameTooLong,
|
Node.OpenDirError.ResolutionLimit => Dir.OpenError.NameTooLong,
|
||||||
Node.OpenDirError.ComponentNotDirectory => Dir.OpenError.NotDir,
|
Node.OpenDirError.ComponentNotDirectory => Dir.OpenError.NotDir,
|
||||||
Node.OpenDirError.ComponentNotFound => Dir.OpenError.FileNotFound,
|
Node.OpenDirError.ComponentNotFound => Dir.OpenError.FileNotFound,
|
||||||
Node.OpenDirError.Canceled => @panic("TODO"),
|
Node.OpenDirError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ fn dirCreateFile(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, flags: D
|
|||||||
Node.CreateFileError.ComponentNotDirectory => File.OpenError.NotDir,
|
Node.CreateFileError.ComponentNotDirectory => File.OpenError.NotDir,
|
||||||
Node.CreateFileError.ComponentNotFound => File.OpenError.FileNotFound,
|
Node.CreateFileError.ComponentNotFound => File.OpenError.FileNotFound,
|
||||||
Node.CreateFileError.OutOfMemory => File.OpenError.SystemResources,
|
Node.CreateFileError.OutOfMemory => File.OpenError.SystemResources,
|
||||||
Node.CreateFileError.Canceled => @panic("TODO"),
|
Node.CreateFileError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -610,7 +610,7 @@ fn dirCreateFile(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, flags: D
|
|||||||
Node.OpenFileError.ResolutionLimit => File.OpenError.NameTooLong,
|
Node.OpenFileError.ResolutionLimit => File.OpenError.NameTooLong,
|
||||||
Node.OpenFileError.ComponentNotDirectory => File.OpenError.NotDir,
|
Node.OpenFileError.ComponentNotDirectory => File.OpenError.NotDir,
|
||||||
Node.OpenFileError.ComponentNotFound => File.OpenError.FileNotFound,
|
Node.OpenFileError.ComponentNotFound => File.OpenError.FileNotFound,
|
||||||
Node.OpenFileError.Canceled => @panic("TODO"),
|
Node.OpenFileError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -646,7 +646,7 @@ fn dirOpenFile(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, flags: Dir
|
|||||||
Node.OpenFileError.ResolutionLimit => File.OpenError.NameTooLong,
|
Node.OpenFileError.ResolutionLimit => File.OpenError.NameTooLong,
|
||||||
Node.OpenFileError.ComponentNotDirectory => File.OpenError.NotDir,
|
Node.OpenFileError.ComponentNotDirectory => File.OpenError.NotDir,
|
||||||
Node.OpenFileError.ComponentNotFound => File.OpenError.FileNotFound,
|
Node.OpenFileError.ComponentNotFound => File.OpenError.FileNotFound,
|
||||||
Node.OpenFileError.Canceled => @panic("TODO"),
|
Node.OpenFileError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -674,7 +674,7 @@ fn dirRead(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Read
|
|||||||
if (dr.state == .reset) {
|
if (dr.state == .reset) {
|
||||||
node.resetDir(dr.dir.handle) catch |e| switch (e) {
|
node.resetDir(dr.dir.handle) catch |e| switch (e) {
|
||||||
error.InvalidHandle => return Dir.Reader.Error.AccessDenied,
|
error.InvalidHandle => return Dir.Reader.Error.AccessDenied,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
dr.state = .reading;
|
dr.state = .reading;
|
||||||
}
|
}
|
||||||
@@ -683,7 +683,7 @@ fn dirRead(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Read
|
|||||||
while (count < buffer.len) {
|
while (count < buffer.len) {
|
||||||
const entry = node.readDir(dr.dir.handle) catch |e| switch (e) {
|
const entry = node.readDir(dr.dir.handle) catch |e| switch (e) {
|
||||||
error.InvalidHandle => return Dir.Reader.Error.AccessDenied,
|
error.InvalidHandle => return Dir.Reader.Error.AccessDenied,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
error.NoMoreItems => {
|
error.NoMoreItems => {
|
||||||
dr.state = .finished;
|
dr.state = .finished;
|
||||||
return count;
|
return count;
|
||||||
@@ -734,7 +734,7 @@ fn dirDeleteFile(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.Dele
|
|||||||
Node.DeleteFileError.ComponentNotFound => Dir.DeleteFileError.FileNotFound,
|
Node.DeleteFileError.ComponentNotFound => Dir.DeleteFileError.FileNotFound,
|
||||||
Node.DeleteFileError.NotFound => Dir.DeleteFileError.FileNotFound,
|
Node.DeleteFileError.NotFound => Dir.DeleteFileError.FileNotFound,
|
||||||
Node.DeleteFileError.IsDirectory => Dir.DeleteFileError.IsDir,
|
Node.DeleteFileError.IsDirectory => Dir.DeleteFileError.IsDir,
|
||||||
Node.DeleteFileError.Canceled => @panic("TODO"),
|
Node.DeleteFileError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -755,7 +755,7 @@ fn dirDeleteDir(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.Delet
|
|||||||
Node.DeleteDirError.NotFound => Dir.DeleteDirError.FileNotFound,
|
Node.DeleteDirError.NotFound => Dir.DeleteDirError.FileNotFound,
|
||||||
Node.DeleteDirError.NotDirectory => Dir.DeleteDirError.NotDir,
|
Node.DeleteDirError.NotDirectory => Dir.DeleteDirError.NotDir,
|
||||||
Node.DeleteDirError.DirNotEmpty => Dir.DeleteDirError.DirNotEmpty,
|
Node.DeleteDirError.DirNotEmpty => Dir.DeleteDirError.DirNotEmpty,
|
||||||
Node.DeleteDirError.Canceled => @panic("TODO"),
|
Node.DeleteDirError.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -857,7 +857,7 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 {
|
|||||||
const node: *Node = @ptrCast(@alignCast(userdata.?));
|
const node: *Node = @ptrCast(@alignCast(userdata.?));
|
||||||
return node.fileSize(file.handle) catch |e| switch (e) {
|
return node.fileSize(file.handle) catch |e| switch (e) {
|
||||||
error.InvalidHandle => File.LengthError.Streaming,
|
error.InvalidHandle => File.LengthError.Streaming,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -884,7 +884,7 @@ fn fileWritePositional(
|
|||||||
const written = node.writeFile(file.handle, cursor, header, &.{}) catch |err| switch (err) {
|
const written = node.writeFile(file.handle, cursor, header, &.{}) catch |err| switch (err) {
|
||||||
error.InvalidHandle => return File.WritePositionalError.NotOpenForWriting,
|
error.InvalidHandle => return File.WritePositionalError.NotOpenForWriting,
|
||||||
error.OutOfMemory => return File.WritePositionalError.SystemResources,
|
error.OutOfMemory => return File.WritePositionalError.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
cursor = std.math.add(usize, cursor, written) catch return File.WritePositionalError.FileTooBig;
|
cursor = std.math.add(usize, cursor, written) catch return File.WritePositionalError.FileTooBig;
|
||||||
copied += written;
|
copied += written;
|
||||||
@@ -897,7 +897,7 @@ fn fileWritePositional(
|
|||||||
const written = node.writeFile(file.handle, cursor, bytes, &.{}) catch |err| switch (err) {
|
const written = node.writeFile(file.handle, cursor, bytes, &.{}) catch |err| switch (err) {
|
||||||
error.InvalidHandle => return File.WritePositionalError.NotOpenForWriting,
|
error.InvalidHandle => return File.WritePositionalError.NotOpenForWriting,
|
||||||
error.OutOfMemory => return File.WritePositionalError.SystemResources,
|
error.OutOfMemory => return File.WritePositionalError.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
cursor = std.math.add(usize, cursor, written) catch return File.WritePositionalError.FileTooBig;
|
cursor = std.math.add(usize, cursor, written) catch return File.WritePositionalError.FileTooBig;
|
||||||
copied += written;
|
copied += written;
|
||||||
@@ -910,7 +910,7 @@ fn fileWritePositional(
|
|||||||
const written = node.writeFile(file.handle, cursor, pattern, &.{}) catch |err| switch (err) {
|
const written = node.writeFile(file.handle, cursor, pattern, &.{}) catch |err| switch (err) {
|
||||||
error.InvalidHandle => return File.WritePositionalError.NotOpenForWriting,
|
error.InvalidHandle => return File.WritePositionalError.NotOpenForWriting,
|
||||||
error.OutOfMemory => return File.WritePositionalError.SystemResources,
|
error.OutOfMemory => return File.WritePositionalError.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
cursor = std.math.add(usize, cursor, written) catch return File.WritePositionalError.FileTooBig;
|
cursor = std.math.add(usize, cursor, written) catch return File.WritePositionalError.FileTooBig;
|
||||||
copied += written;
|
copied += written;
|
||||||
@@ -947,7 +947,7 @@ fn fileReadPositional(userdata: ?*anyopaque, file: File, data: []const []u8, off
|
|||||||
const bytes_read = node.readFile(file.handle, @intCast(offset + copied), buffer) catch |e| {
|
const bytes_read = node.readFile(file.handle, @intCast(offset + copied), buffer) catch |e| {
|
||||||
return switch (e) {
|
return switch (e) {
|
||||||
error.InvalidHandle => File.ReadPositionalError.NotOpenForReading,
|
error.InvalidHandle => File.ReadPositionalError.NotOpenForReading,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
copied += bytes_read;
|
copied += bytes_read;
|
||||||
@@ -962,7 +962,7 @@ fn fileSeekBy(userdata: ?*anyopaque, file: File, offset: i64) File.SeekError!voi
|
|||||||
node.seekFileBy(file.handle, offset) catch |err| switch (err) {
|
node.seekFileBy(file.handle, offset) catch |err| switch (err) {
|
||||||
error.InvalidHandle => return File.SeekError.AccessDenied,
|
error.InvalidHandle => return File.SeekError.AccessDenied,
|
||||||
error.NegativeOffset, error.Overflow => return File.SeekError.Unseekable,
|
error.NegativeOffset, error.Overflow => return File.SeekError.Unseekable,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -972,7 +972,7 @@ fn fileSeekTo(userdata: ?*anyopaque, file: File, offset: u64) File.SeekError!voi
|
|||||||
node.seekFileTo(file.handle, offset_usize) catch |err| switch (err) {
|
node.seekFileTo(file.handle, offset_usize) catch |err| switch (err) {
|
||||||
error.InvalidHandle => return File.SeekError.AccessDenied,
|
error.InvalidHandle => return File.SeekError.AccessDenied,
|
||||||
error.NegativeOffset, error.Overflow => return File.SeekError.Unseekable,
|
error.NegativeOffset, error.Overflow => return File.SeekError.Unseekable,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1276,7 +1276,7 @@ fn netListenIp(userdata: ?*anyopaque, address: *const net.IpAddress, options: ne
|
|||||||
error.AddressNotAvailable => return error.AddressUnavailable,
|
error.AddressNotAvailable => return error.AddressUnavailable,
|
||||||
error.AddressAlreadyUsed => return error.AddressInUse,
|
error.AddressAlreadyUsed => return error.AddressInUse,
|
||||||
error.OutOfMemory => return error.SystemResources,
|
error.OutOfMemory => return error.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
@@ -1294,7 +1294,7 @@ fn netAccept(userdata: ?*anyopaque, listen_handle: net.Socket.Handle, options: n
|
|||||||
error.InvalidHandle => return error.SocketNotListening,
|
error.InvalidHandle => return error.SocketNotListening,
|
||||||
error.AcceptQueueEmpty => return error.WouldBlock,
|
error.AcceptQueueEmpty => return error.WouldBlock,
|
||||||
error.OutOfMemory => return error.SystemResources,
|
error.OutOfMemory => return error.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
@@ -1326,7 +1326,7 @@ fn netConnectIp(userdata: ?*anyopaque, address: *const net.IpAddress, options: n
|
|||||||
error.UnavailableHost => return error.HostUnreachable,
|
error.UnavailableHost => return error.HostUnreachable,
|
||||||
error.PeerNotListeningOnAddress => return error.ConnectionRefused,
|
error.PeerNotListeningOnAddress => return error.ConnectionRefused,
|
||||||
error.OutOfMemory => return error.SystemResources,
|
error.OutOfMemory => return error.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
@@ -1364,7 +1364,7 @@ fn netSend(userdata: ?*anyopaque, handle: net.Socket.Handle, messages: []net.Out
|
|||||||
error.InvalidHandle => return .{ error.SocketUnconnected, index },
|
error.InvalidHandle => return .{ error.SocketUnconnected, index },
|
||||||
error.NotConnected => return .{ error.SocketUnconnected, index },
|
error.NotConnected => return .{ error.SocketUnconnected, index },
|
||||||
error.OutOfMemory => return .{ error.SystemResources, index },
|
error.OutOfMemory => return .{ error.SystemResources, index },
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return .{ error.Canceled, index },
|
||||||
};
|
};
|
||||||
message.data_len = written;
|
message.data_len = written;
|
||||||
}
|
}
|
||||||
@@ -1384,7 +1384,7 @@ fn netRead(userdata: ?*anyopaque, fd: net.Socket.Handle, data: [][]u8) net.Strea
|
|||||||
const block = (copied == 0);
|
const block = (copied == 0);
|
||||||
const n = node.readSocket(fd, buffer, block) catch |e| switch (e) {
|
const n = node.readSocket(fd, buffer, block) catch |e| switch (e) {
|
||||||
error.InvalidHandle => return error.SocketUnconnected,
|
error.InvalidHandle => return error.SocketUnconnected,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
break;
|
break;
|
||||||
@@ -1407,7 +1407,7 @@ fn netWrite(userdata: ?*anyopaque, handle: net.Socket.Handle, header: []const u8
|
|||||||
error.InvalidHandle => return error.SocketUnconnected,
|
error.InvalidHandle => return error.SocketUnconnected,
|
||||||
error.NotConnected => return error.SocketUnconnected,
|
error.NotConnected => return error.SocketUnconnected,
|
||||||
error.OutOfMemory => return error.SystemResources,
|
error.OutOfMemory => return error.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.len != 0) {
|
if (data.len != 0) {
|
||||||
@@ -1418,7 +1418,7 @@ fn netWrite(userdata: ?*anyopaque, handle: net.Socket.Handle, header: []const u8
|
|||||||
error.InvalidHandle => return error.SocketUnconnected,
|
error.InvalidHandle => return error.SocketUnconnected,
|
||||||
error.NotConnected => return error.SocketUnconnected,
|
error.NotConnected => return error.SocketUnconnected,
|
||||||
error.OutOfMemory => return error.SystemResources,
|
error.OutOfMemory => return error.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1430,7 +1430,7 @@ fn netWrite(userdata: ?*anyopaque, handle: net.Socket.Handle, header: []const u8
|
|||||||
error.InvalidHandle => return error.SocketUnconnected,
|
error.InvalidHandle => return error.SocketUnconnected,
|
||||||
error.NotConnected => return error.SocketUnconnected,
|
error.NotConnected => return error.SocketUnconnected,
|
||||||
error.OutOfMemory => return error.SystemResources,
|
error.OutOfMemory => return error.SystemResources,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1461,7 +1461,7 @@ fn netShutdown(userdata: ?*anyopaque, handle: net.Socket.Handle, how: net.Shutdo
|
|||||||
|
|
||||||
node.closeSocket(handle) catch |err| switch (err) {
|
node.closeSocket(handle) catch |err| switch (err) {
|
||||||
error.InvalidHandle => return error.SocketUnconnected,
|
error.InvalidHandle => return error.SocketUnconnected,
|
||||||
error.Canceled => @panic("TODO"),
|
error.Canceled => return error.Canceled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user