aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net
AgeCommit message (Collapse)Author
2022-07-13AstGen: fix loop control flow applying to wrong loopAndrew Kelley
In the case of 'continue' or 'break' inside the 'else' block of a 'while' or 'for' loop. Closes #12109
2022-06-30LLVM: fix lowering of untagged union typesAndrew Kelley
The LLVM backend was calculating the amount of padding solely based on the payload size. However, in the case where there is no union tag, this fails to take into account alignment. Closes #11857
2022-06-07std: adjust for stage2 semanticsVeikka Tuominen
2022-01-14Check for isDarwin() instead of linked libcJohn Schmidt
2022-01-12Use libc if_nametoindex if available when parsing IPsJohn Schmidt
Fixes https://github.com/ziglang/zig/issues/10521 and makes a couple of additional tests pass when linking libc.
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-09-16net.Address: Fix writing 0-bytes when formatting Unix addressesKirjastonhoitaja
The entire 'path' array would get written to the formatting function, when it should instead be treated as a regular zero-terminated string. Note that this doesn't handle abstract paths on Linux, those paths *start* with a \0 byte and are hence treated as empty strings instead. But fixing that would require more adjustments than just formatting, in particular to getOsSockLen().
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-09Ip4Address parser: reject 0-prefixed components (#9538)Frank Denis
Some parsers interpret these as octal, some don't, and the confusion can lead to vulnerabilities. Return error.NonCanonical when parsing IPv4 addresses with 0 prefixes.
2021-06-30changes to accomodate std.Thread updatekprotty
2021-05-08std: update usage of std.testingVeikka Tuominen
2021-02-28std: Swap arguments in Thread.spawnLemonBoy
Beside the new order being consistent with the ThreadPool API and making more sense, this shuffling allows to write the context argument type in terms of the startFn arguments, reducing the use of anytype (eg. less explicit casts when using comptime_int parameters, yay). Sorry for the breakage. Closes #8082
2021-01-11Apparently unix sockets are supported on WindowsLemonBoy
Starting from Windows 10 build 17063.
2021-01-11Let the kernel pick a random portLemonBoy
Avoid errors if the socket enters the TIME_WAIT state and we need to re-execute this test before the OS releases it. This problem was not really a problem before since the accept()-ed socket was never closed on the server-side.
2021-01-11std: Add a small test for i/o on unix socketsLemonBoy
2021-01-11std: Decouple network streams from fs.FileLemonBoy
The overlap between files and sockets is minimal and lumping them together means supporting only a small subset of the functionalities provided by the OS. Moreover the socket and file handles are not always interchangeable: on Windows one should use Winsock's close() call rather than the one used for common files.
2021-01-07Reduce use of deprecated IO typesJay Petacat
Related: #4917
2020-12-31Year++Frank Denis
2020-10-28More fixups for Windows targetsLemonBoy
* Use closeSocket on sockets instead of plain old close, the latter doesn't work on them. * Use winsocket2 everywhere, mingw has no BSD sockets.
2020-10-27std: Add basic smoke test for net functionalityLemonBoy
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-06-07Test case for tcpConnectToHost fixIan Simonson
2020-06-02cleanupsAndrew Kelley
* improve docs * add TODO comments for things that don't have open issues * remove redundant namespacing of struct fields * guard against ioctl returning EINTR * remove the general std.os.ioctl function in favor of the specific ioctl_SIOCGIFINDEX function. This allows us to have a more precise error set, and more type-safe API.
2020-06-02net.test: only call resolveIp6 when os is linuxLuna
2020-06-02Add tests for overflowLuna
2020-06-02Plug resolveIp6 into IPv6 testsLuna
2020-05-31enable dns test on windowsJonathan Marler
2020-05-18Add/fix missing WASI functionality to pass libstd testsJakub Konka
This rather large commit adds/fixes missing WASI functionality in `libstd` needed to pass the `libstd` tests. As such, now by default tests targeting `wasm32-wasi` target are enabled in `test/tests.zig` module. However, they can be disabled by passing the `-Dskip-wasi=true` flag when invoking the `zig build test` command. When the flag is set to `false`, i.e., when WASI tests are included, `wasmtime` with `--dir=.` is used as the default testing command. Since the majority of `libstd` tests were relying on `fs.cwd()` call to get current working directory handle wrapped in `Dir` struct, in order to make the tests WASI-friendly, `fs.cwd()` call was replaced with `testing.getTestDir()` function which resolved to either `fs.cwd()` for non-WASI targets, or tries to fetch the preopen list from the WASI runtime and extract a preopen for '.' path. The summary of changes introduced by this commit: * implement `Dir.makeDir` and `Dir.openDir` targeting WASI * implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI * fix `os.close` and map errors in `unlinkat` * move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi` to `std.os` module * implement `lseek_{SET, CUR, END}` targeting WASI * implement `futimens` targeting WASI * implement `ftruncate` targeting WASI * implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI * make sure ANSI escape codes are _not_ used in stderr or stdout in WASI, as WASI always sanitizes stderr, and sanitizes stdout if fd is a TTY * fix specifying WASI rights when opening/creating files/dirs * tweak `AtomicFile` to be WASI-compatible * implement `os.renameatWasi` for WASI-compliant `os.renameat` function * implement sleep() targeting WASI * fix `process.getEnvMap` targeting WASI
2020-05-03Pass filtered_sock_type to system.socket. Cover PermissionDenied errorCato
2020-03-10fix stack trace code not opening files in forced blocking modeAndrew Kelley
2020-02-28introduce operating system version ranges as part of the targetAndrew Kelley
* re-introduce `std.build.Target` which is distinct from `std.Target`. `std.build.Target` wraps `std.Target` so that it can be annotated as "the native target" or an explicitly specified target. * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a struct which has the tag as well as version range information. * `std.elf` gains some more ELF header constants. * `std.Target.parse` gains the ability to parse operating system version ranges as well as glibc version. * Added `std.Target.isGnuLibC()`. * self-hosted dynamic linker detection and glibc version detection. This also adds the improved logic using `/usr/bin/env` rather than invoking the system C compiler to find the dynamic linker when zig is statically linked. Related: #2084 Note: this `/usr/bin/env` code is work-in-progress. * `-target-glibc` CLI option is removed in favor of the new `-target` syntax. Example: `-target x86_64-linux-gnu.2.27` closes #1907
2020-02-14std: use testing.allocator in testsdaurnimator
2020-02-08std: fix bitrotted evented codeAndrew Kelley
2019-12-08std.fmt.format: tuple parameter instead of var argsAndrew Kelley
2019-11-19Make StreamServer return address of accecpted clientfrmdstryr
2019-11-09rename TcpServer -> StreamServerLuna
- add AF_UNIX support to getOsSockLen
2019-11-08replace Address.parse Address.parseIpLuna
2019-11-08rename IpAddress to Address, add Address.unixLuna
2019-11-05add special formatting for ipv4-mapped ipv6 addressesVexu
2019-11-04support ipv4-mapped ipv6 addressesVexu
2019-11-04improve ipv6 parsing and formattingVexu
2019-10-30fix os.sockaddr being a union instead of a structAndrew Kelley
2019-10-30make std.net more portableAndrew Kelley
* Delete `std.net.TmpWinAddr`. I don't think that was ever meant to be a real thing. * Delete `std.net.OsAddress`. This abstraction was not helpful. * Rename `std.net.Address` to `std.net.IpAddress`. It is now an extern union of IPv4 and IPv6 addresses. * Move `std.net.parseIp4` and `std.net.parseIp6` to the `std.net.IpAddress` namespace. They now return `IpAddress` instead of `u32` and `std.net.Ip6Addr`, which is deleted. * Add `std.net.IpAddress.parse` which accepts a port and parses either an IPv4 or IPv6 address. * Add `std.net.IpAddress.parseExpectingFamily` which additionally accepts a `family` parameter. * `std.net.IpAddress.initIp4` and `std.net.IpAddress.initIp6` are improved to directly take the address fields instead of a weird in-between type. * `std.net.IpAddress.port` is renamed to `std.net.IpAddress.getPort`. * Added `std.net.IpAddress.setPort`. * `os.sockaddr` struct on all targets is improved to match the corresponding system struct. Previously I had made it a union of sockaddr_in, sockaddr_in6, and sockaddr_un. The new abstraction for this is now `std.net.IpAddress`. * `os.sockaddr` and related bits are added for Windows. * `os.sockaddr` and related bits now have the `zero` fields default to zero initialization, and `len` fields default to the correct size. This is enough to abstract the differences across targets, and so no more switch on the target OS is needed in `std.net.IpAddress`. * Add the missing `os.sockaddr_un` on FreeBSD and NetBSD. * `std.net.IpAddress.initPosix` now takes a pointer to `os.sockaddr`.
2019-10-30fix regressionsAndrew Kelley
2019-10-30Merge branch 'testAddresses' of https://github.com/marler8997/zig into std.netAndrew Kelley
2019-10-30std.net: enable test for resolving DNSAndrew Kelley
2019-10-30fix std.net tests and std.net.TcpServer docsAndrew Kelley
2019-10-30rename std.net.Server to TcpServer and simplify itAndrew Kelley
2019-10-29std lib networking improvements, especially non-blocking I/OAndrew Kelley
* delete the std/event/net directory * `std.event.Loop.waitUntilFdReadable` and related functions no longer have possibility of failure. On Linux, they fall back to poll() and then fall back to sleep(). * add some missing `noasync` decorations in `std.event.Loop` * redo the `std.net.Server` API. it's quite nice now, but shutdown does not work cleanly. There is a race condition with close() that I am actively working on. * move `std.io.OutStream` to its own file to match `std.io.InStream`. I started working on making `write` integrated with evented I/O, but it got tricky so I backed off and filed #3557. However I did integrate `std.os.writev` and `std.os.pwritev` with evented I/O. * add `std.Target.stack_align` * move networking tests to `lib/std/net/test.zig` * add `std.net.tcpConnectToHost` and `std.net.tcpConnectToAddress`. * rename `error.UnknownName` to `error.UnknownHostName` within the context of DNS resolution. * add `std.os.readv`, which is integrated with evented I/O. * `std.os.preadv`, is now integrated with evented I/O. * `std.os.accept4` now asserts that ENOTSOCK and EOPNOTSUPP never occur (misuse of API), instead of returning errors. * `std.os.connect` is now integrated with evented I/O. `std.os.connect_async` is gone. Just use `std.os.connect`. * fix false positive dependency loop regarding async function frames * add more compile notes to help when dependency loops occur in determining whether a function is async. * ir: change an assert to ir_assert to make it easier to find workarounds for when such an assert is triggered. In this case it was trying to parse an IPv4 address at comptime.