Commit Graph
257 Commits
Author SHA1 Message Date
Giuseppe Cesarano 44e5319107 Remove extern from Io.Mutex (#37081)
An `Io.Mutex` is bound to the Io implementation used to lock and unlock it: having it cross Io implementations could already be an abuse of the API. C code is even further removed, since it has no `Io` at all and could never meaningfully interact with an `Io.Mutex`, so making it `extern` doesn't buy us anything. The only thing we actually gain is less boilerplate when the user needs to protect a struct that is also used from C, where the C side doesn't need the synchronization. I would argue that's not a strong enough reason to keep it `extern`, since the same behavior can be achieved with composition.

Being `extern` also conflicts with adding safety features to the implementation: their size would change with the compilation configuration, which defeats the purpose of `extern`.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37081
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-10-10 19:11:35 +02:00
Brandon Black 71f6780c98 Move netAccept to an Operation 2026-10-10 00:47:09 +02:00
Isaac Freund 2217d43cc9 Revert "std.Io.net: improve reception of control data"
It is not clear to me that this is the right path to take, using a
shared buffer for control data makes managing the alignment trickier,
and would require the Io interface itself to deal with alignment.

For an example of what I consider clean design, see net_read/net_write.
There is no need for the Io interface/operations to be aware of control
buffer alignment and it is sufficient for the net.Stream.Reader
abstraction to use an aligned buffer.

Also this has no test coverage and is (to my knowledege)
not currently blocking any real world Zig project.

This reverts commit 7c0347fce0b6f510b43ca503ad9c1cd2f8ac9a6b.
2026-10-01 11:21:28 +02:00
hemisputnik c4d9d65a7b std.Io.net: send control data with .net_write
Add a new parameter to .net_write - control.
2026-10-01 10:55:12 +02:00
hemisputnik 875cb2ff2f std.Io.net: read control data with .net_read
Also adds a way to read control data using Stream.Reader. Stream.Reader
will buffer control data until it can't no more, in which case it will
be truncated.

The readv syscall in netReadPosix has been replaced with recvmsg.
2026-10-01 10:55:12 +02:00
hemisputnik 2035549408 std.Io.net: improve reception of control data
A couple of changes to improve reception of control data when using the
datagram API.

Instead of having a separate control buffer per received message,
there's one big buffer that all messages share (like the data buffer).

This means that now IncomingMessage has no user-initialised fields, and
can be initialised with undefined (which means that .init is now
deprecated).

Also, instead of taking a pointer to mutable IncomingMessage,
netReceiveOne* functions simply return a IncomingMessage.
2026-10-01 10:55:12 +02:00
Ryan Liptak bbb48690de Io.failing: Fix dirRead implementation not setting state
This caused `Dir.Reader.next` to loop infinitely since it only returns `null` when state is `.finished`.

Closes #37011
2026-09-29 19:10:34 -07:00
Jacob Young 4dd645fddd Runner: add --libc-runtimes support 2026-09-26 19:08:50 -04:00
Jacob Young ee0bd6c69e Io: avoid leaking inherited descriptors 2026-09-26 19:08:50 -04:00
Jacob Young 488c15320b runner: spawn compiler process 2026-09-26 19:08:50 -04:00
Richalsu f506a49142 std.Io: add error.ConnectionTimedOut for net read/write/send/receive 2026-08-15 10:46:35 +02:00
Lukas Lalinsky 9d92d2ce93 Migrate netWrite to std.Io.Operation
Preparation for adding timeouts:
https://codeberg.org/ziglang/zig/issues/32166
2026-08-11 11:57:57 +02:00
Lukáš LalinskýandLukas Lalinsky 254c23b038 Fix std.Io.Condition.wait cancelation race / error swallowing (#35564)
When `std.Io.Condition` is signaled and almost immediately after
that canceled, it will swallow the `error.Canceled` error and
leave the task in an uncancelable state.

Co-authored-by: Lukas Lalinsky <lukas@lalinsky.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35564
Reviewed-by: mlugg <mlugg@mlugg.co.uk>
2026-08-11 10:43:13 +02:00
Brandon Black a6c2839505 Move std.Io netSend to an Operation
Also adds sendTimeout() and sendManyTimeout() functions to
Io.net.Socket, and updates the UDP tests to exercise all of the
combined interfaces.

Deprecates `sendMany` in favor of `sendManyTimeout` with a
`Timeout` of `.none`.  The existing `sendMany` interface is not
capable of reporting partial success, and eventually removing it
will align with the current interfaces on the receive side.

Seems to work for Posix + Threaded?  Beyond very basic "avoid
compile errors maybe", I have not tried to address non-Posix or
non-Threaded parts.
2026-08-10 20:33:08 +02:00
xeondev b2c230df50 std.Io: change netClose to accept []const net.Socket 2026-08-09 15:42:33 +02:00
Anthon van der Neut 3239f672d2 Add compare() to Io.Timestamp
this makes it possible to compare e.g. file stat results without
knowing implementation details for Timestamp
2026-08-08 14:43:12 +02:00
Perry Fraser c9c97ee845 Fix tryLockStderr compilation error
Fixes #36430. Thanks to kavika13 for the suggested fix!
2026-08-08 13:56:37 +02:00
Alex Rønne Petersen 2597da0254 Merge pull request 'std.Io: minor Timeout-related things' (#35299) from blblack/zig:io-minor-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35299
2026-08-08 01:32:04 +02:00
Brandon Black 47825d7de3 Io.operateTimeout: if timeout == .none, operate
It's far simpler for the same effective outcome (no Batch
instantiation, no quick-success attempt + infinite poll first)
2026-08-07 17:50:25 -05:00
Brandon Black 1182f06c14 Io: Fix Threaded.sleep(.none), doc Timeout.none
Timeout.none implicitly seems to mean indefinitely nearly
everywhere I can see.  However, Io.Threaded.sleep() has a
short-circuit at the top which treats Timeout.none as effectively
zero (no sleep at all), even though the per-target functions it
calls afterwards would otherwise would honor .none correctly.

This patch removes this (presumably erronenous) short-circuit and
documents Timeout.none's meaning explicitly.
2026-08-07 17:50:12 -05:00
林晨 (Leo Cheng) 407061498c std.Io: fix missing word in Clock.cpu_process/cpu_thread doc
Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
2026-08-02 12:12:14 +02:00
Justus Klausecker 69a26976ed zig fmt
Converts usages of `@intFromEnum` and `@enumFromInt` to instead use the
new `@backingInt` and `@fromBackingInt` builtins.
2026-07-17 23:30:26 +02:00
Krzysztof Wolicki 9e80795623 all: update to use new std.lang.Type definitions 2026-05-27 10:03:51 +01:00
Andrew Kelley fd63f57cd8 build system: update more usize to u64 for maxrss
makes the build system compile on 32 bit systems

bonus, also fix incorrectly passing advanced debug options to the maker
process which doesn't care about them
2026-05-26 09:50:48 -07:00
Andrew Kelley 56265d6f99 std.Io: clarify Group semantics with respect to async tasks 2026-05-05 13:39:24 -07:00
Linus Groh 0add2dfc41 std.Io.File: Remove deprecated option types 2026-05-05 04:12:52 +02:00
David Rubin a0a36bf92e io: make toClock compile 2026-04-19 16:58:12 -07:00
Andrew Kelley c0763b5e25 std.Io.Condition: separate wait impls for clarity
also:
* add docs
* add test coverage for waitUncancelable
* explicit error set declaration WaitTimeoutError
2026-04-16 14:52:48 -07:00
Lukas Lalinsky d821446cf9 Implement Condition.waitTimeout
I'd have preferred if `vtable.futexWait` returned `error.Timeout`, since
all the OS-level APIs provide it. However, if I keep the vtable untouched,
I had to determine the timeout case by post-checking the deadline.
It's fine functionally, but one extra syscall that be avoided at
cost of changing the vtable and all the futex implementations.
2026-04-16 13:37:23 -07:00
xeondev 2b48f559f4 std.Io: move netRead to become an Operation 2026-04-16 22:13:29 +02:00
Andrew Kelley 5ccfeb9268 std.Io.net: add error.PortUnreachable to NetReceive
closes #31787
2026-04-08 22:58:22 +02:00
Samuel Fiedler 5ec8e45f3d Io: add failing io (Io.failing) 2026-04-06 14:25:44 +02:00
Andrew Kelley 9292ded5a3 std.Io.Batch: fix add function
closes #31730
closes #31757
2026-04-05 02:17:53 -07:00
Andrew Kelley 6f467e436d std.Io: move File.CreateFlags to Dir.CreateFileOptions
for naming consistency.

same thing with File.OpenFlags -> Dir.OpenFileFlags
2026-03-27 01:23:04 -07:00
Jacob Young 9ac1386c10 std.Io.Threaded: windows networking without ws2_32 2026-03-18 20:13:59 -04:00
squidy239 d6632b1dd2 std.Io: added missing toMicroseconds and fromMicroseconds functions (#30099)
added toMicroseconds and fromMicroseconds functions to std.Io.Duration and toMicroseconds to std.Io.Timestamp

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30099
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: squidy239 <sachabarsayuracko@gmail.com>
Co-committed-by: squidy239 <sachabarsayuracko@gmail.com>
2026-03-12 01:34:40 +01:00
GasInfinity 048e38624e fix: use cmpxchgStrong in Io.Mutex
* `cmpxchgWeak` can fail spuriously on LL/SC architectures
and `tryLock` would invalidly return false in those cases.
2026-03-10 10:05:09 +01:00
Andrew Kelley be0f188990 std.Io: move netReceive to become an Operation
Notably, the timeout becomes provided by the general-purpose Batch API
rather than being special-purposed.
2026-03-08 19:20:06 -07:00
Ryan Liptak 6be202f466 Io: Add processSetCurrentPath
The logic used to allow providing a path for setting the CWD of a child process in https://codeberg.org/ziglang/zig/pulls/31090 applies here as well:

- Windows must provide a path when setting the CWD, so the path of an `Io.Dir` must be resolved before actually calling RtlSetCurrentDirectory_U
- A directory handle may have multiple paths associated with it, so providing the CWD as a string retains a legitimate use case in cases where the precise path matters
2026-03-09 03:19:11 +01:00
Andrew Kelley 0a412853aa std.Io: fix Select cancel deadlock with no tasks 2026-03-03 02:26:23 +01:00
Andrew Kelley 02142a54d2 std.Io: remove cancelation propagation assertions
While the general guidance remains useful, it is not the case that
error.Canceled will always pass across the Group task function boundary.

Remove the too-aggressive assertions and add unit test coverage.

Closes #30096
Closes #31340
Closes #31358
2026-02-28 05:07:54 +01:00
hemisputnik 99229ceb55 std.Io.{Writer|Duration}: move duration formatting to a format method
Remove the `{D}` format specifier. It is moved into `std.Io.Duration` as
a format method.

Migration plan:

```diff
-writer.print("{D}", .{ns});
+writer.print("{f}", .{std.Io.Duration{ .nanoseconds = ns }});
```

All instances where `{D}` was used have been changed to use
`std.Io.Duration` and `{f}`.

Fixes #31281
2026-02-28 02:46:04 +01:00
Andrew Kelley 8c70fd0a57 std.Io.Select: introduce cancelDiscard
and make the return value of `cancel` return queue items.

I don't think it's possible to make `cancel` not deadlock with an empty
queue buffer without introducing a new Group primitive.

This is the best I could come up with based on existing primitives.
Let's see if applications find these APIs palatable.
2026-02-28 01:46:43 +01:00
estevesnp 0b6b65b387 fix: Allow async and concurrent from Io.Select to accept non-void error unions 2026-02-26 20:49:05 +01:00
Andrew Kelley 311bba4af0 std.Io.Select: add awaitMany function and unit test
and fix documentation. these functions are in fact threadsafe.
2026-02-20 17:28:33 -08:00
Andrew Kelley f9053f38e5 std.Io.Select: add documentation 2026-02-20 17:08:13 -08:00
Andrew Kelley 54eb03cbf6 std.Io.Select: remove "outstanding" field
it is not fundamentally part of this abstraction
2026-02-20 16:42:37 -08:00
Andrew Kelley 5ac6ff43d4 Merge pull request 'Io.Select: cancelation and concurrent' (#30836) from blblack/zig:select-stuff into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30836
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-21 01:29:06 +01:00
Andrew Kelley d9fc7fa04d std.Io: remove select function
This function works with a slice of futures and returns the index of a
completed one. This doesn't work very well in practice because it's
either too high level or too low level.

At the lower level we have Io.Batch for doing this kind of thing at the
Operation API layer.

At the higher level we have Io.Select which is a convenience wrapper
around an Io.Group and an Io.Queue.
2026-02-14 18:31:48 -08:00
Jacob Young 2fa1a78491 Io.Dispatch: introduce grand central dispatch io impl 2026-02-13 12:29:40 -05:00