aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net.zig
AgeCommit message (Collapse)Author
2025-10-29WIP land the std.Io interfaceAndrew Kelley
fix std lib compilation errors caused by introducing std.Io
2025-10-29std.Io.net: implement receiving connectionless messagesAndrew Kelley
2025-10-29Io.net: implement more networkingAndrew Kelley
the next task is now implementing Io.Group
2025-10-29Io.net: partial implementation of dns lookupAndrew Kelley
2025-10-29std.Io.net: partially implement HostName.lookupAndrew Kelley
2025-10-08std.Io.Reader: fix delimiter bugsmlugg
Fix `takeDelimiter` and `takeDelimiterExclusive` tossing too many bytes (#25132) Also add/improve test coverage for all delimiter and sentinel methods, update usages of `takeDelimiterExclusive` to not rely on the fixed bug, tweak a handful of doc comments, and slightly simplify some logic. I have not fixed #24950 in this commit because I am a little less certain about the appropriate solution there. Resolves: #25132 Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-09-15std.net.Ip6Address: format numerical scope iddatabase64128
2025-08-19Fix bugs in Windows readVec implementationsCarl Åstholm
2025-08-16Compilation: remove last instance of deprecatedReaderAndrew Kelley
This also makes initStreaming preemptively disable file size checking.
2025-08-10std.net.Stream.Reader: init size_errAndrew Kelley
This code knows in advance that stat() should never be called. closes #24754
2025-08-09net: Always set WSA_FLAG_OVERLAPPED when creating Windows sockets. Rework ↵kcbanner
send and receive logic to use overlapped I/O. build-web: Remove the now-redundant supports_recv logic
2025-08-07std.net: fix windows buildAndrew Kelley
2025-08-01Merge pull request #24614 from ziglang/flateAndrew Kelley
std.compress.flate: rework decompression and delete compression
2025-08-01build system: replace fuzzing UI with build UI, add time reportmlugg
This commit replaces the "fuzzer" UI, previously accessed with the `--fuzz` and `--port` flags, with a more interesting web UI which allows more interactions with the Zig build system. Most notably, it allows accessing the data emitted by a new "time report" system, which allows users to see which parts of Zig programs take the longest to compile. The option to expose the web UI is `--webui`. By default, it will listen on `[::1]` on a random port, but any IPv6 or IPv4 address can be specified with e.g. `--webui=[::1]:8000` or `--webui=127.0.0.1:8000`. The options `--fuzz` and `--time-report` both imply `--webui` if not given. Currently, `--webui` is incompatible with `--watch`; specifying both will cause `zig build` to exit with a fatal error. When the web UI is enabled, the build runner spawns the web server as soon as the configure phase completes. The frontend code consists of one HTML file, one JavaScript file, two CSS files, and a few Zig source files which are built into a WASM blob on-demand -- this is all very similar to the old fuzzer UI. Also inherited from the fuzzer UI is that the build system communicates with web clients over a WebSocket connection. When the build finishes, if `--webui` was passed (i.e. if the web server is running), the build runner does not terminate; it continues running to serve web requests, allowing interactive control of the build system. In the web interface is an overall "status" indicating whether a build is currently running, and also a list of all steps in this build. There are visual indicators (colors and spinners) for in-progress, succeeded, and failed steps. There is a "Rebuild" button which will cause the build system to reset the state of every step (note that this does not affect caching) and evaluate the step graph again. If `--time-report` is passed to `zig build`, a new section of the interface becomes visible, which associates every build step with a "time report". For most steps, this is just a simple "time taken" value. However, for `Compile` steps, the compiler communicates with the build system to provide it with much more interesting information: time taken for various pipeline phases, with a per-declaration and per-file breakdown, sorted by slowest declarations/files first. This feature is still in its early stages: the data can be a little tricky to understand, and there is no way to, for instance, sort by different properties, or filter to certain files. However, it has already given us some interesting statistics, and can be useful for spotting, for instance, particularly complex and slow compile-time logic. Additionally, if a compilation uses LLVM, its time report includes the "LLVM pass timing" information, which was previously accessible with the (now removed) `-ftime-report` compiler flag. To make time reports more useful, ZIR and compilation caches are ignored by the Zig compiler when they are enabled -- in other words, `Compile` steps *always* run, even if their result should be cached. This means that the flag can be used to analyze a project's compile time without having to repeatedly clear cache directory, for instance. However, when using `-fincremental`, updates other than the first will only show you the statistics for what changed on that particular update. Notably, this gives us a fairly nice way to see exactly which declarations were re-analyzed by an incremental update. If `--fuzz` is passed to `zig build`, another section of the web interface becomes visible, this time exposing the fuzzer. This is quite similar to the fuzzer UI this commit replaces, with only a few cosmetic tweaks. The interface is closer than before to supporting multiple fuzz steps at a time (in line with the overall strategy for this build UI, the goal will be for all of the fuzz steps to be accessible in the same interface), but still doesn't actually support it. The fuzzer UI looks quite different under the hood: as a result, various bugs are fixed, although other bugs remain. For instance, viewing the source code of any file other than the root of the main module is completely broken (as on master) due to some bogus file-to-module assignment logic in the fuzzer UI. Implementation notes: * The `lib/build-web/` directory holds the client side of the web UI. * The general server logic is in `std.Build.WebServer`. * Fuzzing-specific logic is in `std.Build.Fuzz`. * `std.Build.abi` is the new home of `std.Build.Fuzz.abi`, since it now relates to the build system web UI in general. * The build runner now has an **actual** general-purpose allocator, because thanks to `--watch` and `--webui`, the process can be arbitrarily long-lived. The gpa is `std.heap.DebugAllocator`, but the arena remains backed by `std.heap.page_allocator` for efficiency. I fixed several crashes caused by conflation of `gpa` and `arena` in the build runner and `std.Build`, but there may still be some I have missed. * The I/O logic in `std.Build.WebServer` is pretty gnarly; there are a *lot* of threads involved. I anticipate this situation improving significantly once the `std.Io` interface (with concurrency support) is introduced.
2025-07-31std: match readVec fn prototype exactlyAndrew Kelley
this is not necessary according to zig language, but works around a flaw in the C backend
2025-07-31fetch: update API usageAndrew Kelley
2025-07-30std.Io.Reader: introduce readVec back into the VTableAndrew Kelley
simplifies and fixes things addresses a subset of #24608
2025-07-14std.net: wasi does not have unix socketsAndrew Kelley
2025-07-14align those `@fieldParentPtr` castsAndrew Kelley
2025-07-14make msghdr.iovlen unsignedAndrew Kelley
I don't care what C headers say. This value is never supposed to be negative.
2025-07-14std.net: update to new I/O APIAndrew Kelley
2025-07-11Remove numerous things deprecated during the 0.14 release cycleLinus Groh
Basically everything that has a direct replacement or no uses left. Notable omissions: - std.ArrayHashMap: Too much fallout, needs a separate cleanup. - std.debug.runtime_safety: Too much fallout. - std.heap.GeneralPurposeAllocator: Lots of references to it remain, not a simple find and replace as "debug allocator" is not equivalent to "general purpose allocator". - std.io.Reader: Is being reworked at the moment. - std.unicode.utf8Decode(): No replacement, needs a new API first. - Manifest backwards compat options: Removal would break test data used by TestFetchBuilder. - panic handler needs to be a namespace: Many tests still rely on it being a function, needs a separate cleanup.
2025-07-07std.fmt: fully remove format string from format methodsAndrew Kelley
Introduces `std.fmt.alt` which is a helper for calling alternate format methods besides one named "format".
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-07-07std.io: deprecated Reader/Writer; introduce new APIAndrew Kelley
2025-04-04std.net: Implement if_nametoindex for windows (#22555)Zenomat
2025-02-22std.net: Fix IPv6 address format compression for long zero runs (#22441)Anders Bondehagen
2025-02-16remove unneeded native_os checkManuel Spagnolo
The check is not needed, since we are already checking for the os at line 847 and returning at 916 when the check succeeds. Therefore, at 926, we know the os is not windows.
2025-01-26std.net.listen: no REUSEPORT with unix socketPierre Tachoire
On Linux, set REUSEPORT option on an unix socket returns a EOPNOTSUPP error. See https://github.com/torvalds/linux/commit/5b0af621c3f6ef9261cf6067812f2fd9943acb4b
2024-07-19std.c reorganizationAndrew Kelley
It is now composed of these main sections: * Declarations that are shared among all operating systems. * Declarations that have the same name, but different type signatures depending on the operating system. Often multiple operating systems share the same type signatures however. * Declarations that are specific to a single operating system. - These are imported one per line so you can see where they come from, protected by a comptime block to prevent accessing the wrong one. Closes #19352 by changing the convention to making types `void` and functions `{}`, so that it becomes possible to update `@hasDecl` sites to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up removing some duplicate logic and update some bitrotted feature detection checks. A handful of types have been modified to gain namespacing and type safety. This is a breaking change. Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-04std: avoid references that trigger compile errorsmlugg
Note that the `_ = Address` statements in tests previously were a nop, and now actually check that the type is valid. However, on WASI, the type is *not* valid.
2024-07-02Rename isASCII to isAsciiMichael Bradshaw
2024-04-28std.posix.iovec: use .base and .len instead of .iov_base and .iov_lenNameless
2024-04-17compiler: un-implement #19634mlugg
This commit reverts the handling of partially-undefined values in bitcasting to transform these bits into an arbitrary numeric value, like happens on `master` today. As @andrewrk rightly points out, #19634 has unfortunate consequences for the standard library, and likely requires more thought. To avoid a major breaking change, it has been decided to revert this design decision for now, and make a more informed decision further down the line.
2024-04-17compiler: rework comptime pointer representation and accessmlugg
We've got a big one here! This commit reworks how we represent pointers in the InternPool, and rewrites the logic for loading and storing from them at comptime. Firstly, the pointer representation. Previously, pointers were represented in a highly structured manner: pointers to fields, array elements, etc, were explicitly represented. This works well for simple cases, but is quite difficult to handle in the cases of unusual reinterpretations, pointer casts, offsets, etc. Therefore, pointers are now represented in a more "flat" manner. For types without well-defined layouts -- such as comptime-only types, automatic-layout aggregates, and so on -- we still use this "hierarchical" structure. However, for types with well-defined layouts, we use a byte offset associated with the pointer. This allows the comptime pointer access logic to deal with reinterpreted pointers far more gracefully, because the "base address" of a pointer -- for instance a `field` -- is a single value which pointer accesses cannot exceed since the parent has undefined layout. This strategy is also more useful to most backends -- see the updated logic in `codegen.zig` and `codegen/llvm.zig`. For backends which do prefer a chain of field and elements accesses for lowering pointer values, such as SPIR-V, there is a helpful function in `Value` which creates a strategy to derive a pointer value using ideally only field and element accesses. This is actually more correct than the previous logic, since it correctly handles pointer casts which, after the dust has settled, end up referring exactly to an aggregate field or array element. In terms of the pointer access code, it has been rewritten from the ground up. The old logic had become rather a mess of special cases being added whenever bugs were hit, and was still riddled with bugs. The new logic was written to handle the "difficult" cases correctly, the most notable of which is restructuring of a comptime-only array (for instance, converting a `[3][2]comptime_int` to a `[2][3]comptime_int`. Currently, the logic for loading and storing work somewhat differently, but a future change will likely improve the loading logic to bring it more in line with the store strategy. As far as I can tell, the rewrite has fixed all bugs exposed by #19414. As a part of this, the comptime bitcast logic has also been rewritten. Previously, bitcasts simply worked by serializing the entire value into an in-memory buffer, then deserializing it. This strategy has two key weaknesses: pointers, and undefined values. Representations of these values at comptime cannot be easily serialized/deserialized whilst preserving data, which means many bitcasts would become runtime-known if pointers were involved, or would turn `undefined` values into `0xAA`. The new logic works by "flattening" the datastructure to be cast into a sequence of bit-packed atomic values, and then "unflattening" it; using serialization when necessary, but with special handling for `undefined` values and for pointers which align in virtual memory. The resulting code is definitely slower -- more on this later -- but it is correct. The pointer access and bitcast logic required some helper functions and types which are not generally useful elsewhere, so I opted to split them into separate files `Sema/comptime_ptr_access.zig` and `Sema/bitcast.zig`, with simple re-exports in `Sema.zig` for their small public APIs. Whilst working on this branch, I caught various unrelated bugs with transitive Sema errors, and with the handling of `undefined` values. These bugs have been fixed, and corresponding behavior test added. In terms of performance, I do anticipate that this commit will regress performance somewhat, because the new pointer access and bitcast logic is necessarily more complex. I have not yet taken performance measurements, but will do shortly, and post the results in this PR. If the performance regression is severe, I will do work to to optimize the new logic before merge. Resolves: #19452 Resolves: #19460
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-03-10improve documentation in stdAndrew Kelley
A lot of these "shorthand" doc comments were redundant, low quality filler content. Better to let the actual modules speak for themselves with top level doc comments rather than trying to document their aliases.
2024-02-23std.net: fix std lib test regression. fixupAndrew Kelley
2024-02-23std.net.listen: fix Windows API useAndrew Kelley
In a previous commit I removed a load-bearing use of `@hasDecl` to detect whether the SO.REUSEPORT option should be set. `@hasDecl` should not be used for OS feature detection because it can hide bugs. The new logic checks for the operating system specifically and then does the thing that is supposed to be done on that operating system directly.
2024-02-23std.net, std.http: simplifyAndrew Kelley
2024-02-23std.http.Client: remove invalid use of refAllDeclsAndrew Kelley
2024-02-01remove std.io.ModeVeikka Tuominen
2024-01-21Handle all errors on std.net.Ipv4address.resolveIPChristiano Haesbaert
The following test fails since NonCanonical is not handled test "foo" { std.net.Ip4Address.resolveIp("1.1.1.1", 0) catch unreachable; } /usr/lib/zig/std/net.zig:240:60: error: switch must handle all possibilities if (parse(name, port)) |ip4| return ip4 else |err| switch (err) { ^~~~~~ /usr/lib/zig/std/net.zig:240:60: note: unhandled error value: 'error.NonCanonical' referenced by: test.foo: src/dhcp.zig:383:23
2023-12-16std.net: add explicit error sets for IP parsingArtem Kolichenkov
Inferred errors in switch statements prevented IP address parsing at comptime. Adding explicit error sets fixes it. Closes #18276
2023-11-27std.net: replace `@ptrCast` with slice syntaxCarter Snook
2023-11-21std.net: enable forcing non-blocking mode for acceptJan Philipp Hafer
Justification: It is common for non-CPU bound short routines to do non-blocking accept to eliminate unnecessary delays before subscribing to data, for example in hardware integration tests.
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-10-31std.builtin.Endian: make the tags lower caseAndrew Kelley
Let's take this breaking change opportunity to fix the style of this enum.
2023-10-31mem: fix ub in writeIntJacob Young
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
2023-09-06std.net: Fix IPv6 address parsing for single digitLuis Cáceres
This fixes the case where IPv6 address parsing incorrectly succeeded on input such as `1`, which now returns error.Incomplete.