aboutsummaryrefslogtreecommitdiff
path: root/lib/std/event
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-03 02:03:22 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-03-03 02:25:26 -0500
commitc81345c8aec56a108f6f98001666a1552d65ce85 (patch)
tree6a18842256a157896d175d4e254811b9bf478090 /lib/std/event
parentbd287dd1942f0a72e6bd9dc8475bd4e7d34fa5f8 (diff)
downloadzig-c81345c8aec56a108f6f98001666a1552d65ce85.tar.gz
zig-c81345c8aec56a108f6f98001666a1552d65ce85.zip
breaking: std.os read/write functions + sendfile
* rework os.sendfile and add macosx support, and a fallback implementation for any OS. * fix sendto compile error * std.os write functions support partial writes. closes #3443. * std.os pread / pwrite functions can now return `error.Unseekable`. * std.fs.File read/write functions now have readAll/writeAll variants which loop to complete operations even when partial reads/writes happen. * Audit std.os read/write functions with respect to Linux returning EINVAL for lengths greater than 0x7fff0000. * std.os read/write shim functions do not unnecessarily loop. Since partial reads/writes are part of the API, the caller will be forced to loop anyway, and so that would just be code bloat. * Improve doc comments * Add a non-trivial test for std.os.sendfile * Fix std.os.pread on 32 bit Linux * Add missing SYS_sendfile bit on aarch64
Diffstat (limited to 'lib/std/event')
-rw-r--r--lib/std/event/loop.zig22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig
index 80ba5a79b5..e62f15d59a 100644
--- a/lib/std/event/loop.zig
+++ b/lib/std/event/loop.zig
@@ -236,7 +236,8 @@ pub const Loop = struct {
var extra_thread_index: usize = 0;
errdefer {
// writing 8 bytes to an eventfd cannot fail
- noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
+ const amt = noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
+ assert(amt == wakeup_bytes.len);
while (extra_thread_index != 0) {
extra_thread_index -= 1;
self.extra_threads[extra_thread_index].wait();
@@ -682,7 +683,8 @@ pub const Loop = struct {
.linux => {
self.posixFsRequest(&self.os_data.fs_end_request);
// writing 8 bytes to an eventfd cannot fail
- noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
+ const amt = noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
+ assert(amt == wakeup_bytes.len);
return;
},
.macosx, .freebsd, .netbsd, .dragonfly => {
@@ -831,7 +833,7 @@ pub const Loop = struct {
/// Performs an async `os.write` using a separate thread.
/// `fd` must block and not return EAGAIN.
- pub fn write(self: *Loop, fd: os.fd_t, bytes: []const u8) os.WriteError!void {
+ pub fn write(self: *Loop, fd: os.fd_t, bytes: []const u8) os.WriteError!usize {
var req_node = Request.Node{
.data = .{
.msg = .{
@@ -852,7 +854,7 @@ pub const Loop = struct {
/// Performs an async `os.writev` using a separate thread.
/// `fd` must block and not return EAGAIN.
- pub fn writev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const) os.WriteError!void {
+ pub fn writev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const) os.WriteError!usize {
var req_node = Request.Node{
.data = .{
.msg = .{
@@ -873,7 +875,7 @@ pub const Loop = struct {
/// Performs an async `os.pwritev` using a separate thread.
/// `fd` must block and not return EAGAIN.
- pub fn pwritev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const, offset: u64) os.WriteError!void {
+ pub fn pwritev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const, offset: u64) os.WriteError!usize {
var req_node = Request.Node{
.data = .{
.msg = .{
@@ -1137,7 +1139,7 @@ pub const Loop = struct {
pub const Write = struct {
fd: os.fd_t,
bytes: []const u8,
- result: Error!void,
+ result: Error!usize,
pub const Error = os.WriteError;
};
@@ -1145,7 +1147,7 @@ pub const Loop = struct {
pub const WriteV = struct {
fd: os.fd_t,
iov: []const os.iovec_const,
- result: Error!void,
+ result: Error!usize,
pub const Error = os.WriteError;
};
@@ -1154,9 +1156,9 @@ pub const Loop = struct {
fd: os.fd_t,
iov: []const os.iovec_const,
offset: usize,
- result: Error!void,
+ result: Error!usize,
- pub const Error = os.WriteError;
+ pub const Error = os.PWriteError;
};
pub const PReadV = struct {
@@ -1165,7 +1167,7 @@ pub const Loop = struct {
offset: usize,
result: Error!usize,
- pub const Error = os.ReadError;
+ pub const Error = os.PReadError;
};
pub const Open = struct {