about summary refs log tree commit diff
path: root/library/std/src/net
AgeCommit message (Collapse)AuthorLines
2024-11-26std: update internal uses of `io::const_error!`joboet-4/+2
2024-09-30Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichtonTrevor Gross-6/+55
Hook up std::net to wasi-libc on wasm32-wasip2 target One of the improvements of the `wasm32-wasip2` target over `wasm32-wasip1` is better support for networking. Right now, p2 is just re-using the `std::net` implementation from p1. This PR adds a new net module for p2 that makes use of net from `sys_common` and calls wasi-libc functions directly. There are currently a few limitations: - Duplicating a socket is not supported by WASIp2 (directly returns an error) - Peeking is not yet implemented in wasi-libc (we could let wasi-libc handle this, but I opted to directly return an error instead) - Vectored reads/writes are not supported by WASIp2 (the necessary functions are available in wasi-libc, but they call WASIp1 functions which do not support sockets, so I opted to directly return an error instead) - Getting/setting `TCP_NODELAY` is faked in wasi-libc (uses the fake implementation instead of returning an error) - Getting/setting `SO_LINGER` is not supported by WASIp2 (directly returns an error) - Setting `SO_REUSEADDR` is faked in wasi-libc (since this is done from `sys_common`, the fake implementation is used instead of returning an error) - Getting/setting `IPV6_V6ONLY` is not supported by WASIp2 and will always be set for IPv6 sockets (since this is done from `sys_common`, wasi-libc will return an error) - UDP broadcast/multicast is not supported by WASIp2 (since this is configured from `sys_common`, wasi-libc will return appropriate errors) - The `MSG_NOSIGNAL` send flag is a no-op because there are no signals in WASIp2 (since explicitly setting this flag would require a change to `sys_common` and the result would be exactly the same, I opted to not set it) Do those decisions make sense? While working on this PR, I noticed that there is a `std::os::wasi::net::TcpListenerExt` trait that adds a `sock_accept()` method to `std::net::TcpListener`. Now that WASIp2 supports standard accept, would it make sense to remove this? cc `@alexcrichton`
2024-09-29Rollup merge of #130743 - YohDeadfall:net-nonblocking-doc, r=Mark-SimulacrumGuillaume Gomez-2/+2
Clarifications for set_nonblocking methods Closes #129903. The issue mentions that `send`, `recv` and other operations are interpreted by some users as methods of `TcpSocket` which led to confusion since it hasn't them. To fix it I added "system" into the documentation as being more precise for two reasons: * it's makes it clear that these names are system operations; * it doesn't point to the location of these methods like `libc` because not every system is POSIX compatible.
2024-09-29Fix std tests for wasm32-wasip2 targetNicola Krumschmidt-6/+55
2024-09-27Reference UNSPECIFIED instead of INADDR_ANY in join_multicast_v4Asger Hautop Drewsen-2/+2
2024-09-23Clarifications for set_nonblocking methodsYoh Deadfall-2/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-26/+15
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-24Replace `MaybeUninit::uninit_array()` with array repeat expression.Kevin Reid-1/+1
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681> > if it’s stabilized soon enough maybe it’s not worth having a > standard library method that will be replaceable with > `let buffer = [MaybeUninit::<T>::uninit(); $N];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
2024-06-21fix issue numberTristan Guichaoua-5/+5
2024-03-20SeqCst->Relaxed in std::net::test.Mara Bos-2/+2
Relaxed is enough to have fetch_add(1) return each value only once (until it wraps around).
2024-03-06fix `close_read_wakes_up` testLukas Markeffsky-15/+18
2023-12-10remove redundant importssurechen-2/+1
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-10-03Auto merge of #105394 - Patiga:improve-udpsocket-docs, r=workingjubileebors-1/+20
Improve UdpSocket documentation I tried working with `UdpSocket` and ran into `EINVAL` errors with no clear indication of what causes the error. Also, it was uncharacteristically hard to figure this module out, compared to other Rust `std` modules. 1. `send` and `send_to` return a `usize` This one is just clarity. Usually, returned `usize`s indicate that the buffer might have only been sent partially. This is not the case with UDP. Since that `usize` must always be `buffer.len()`, I have documented that. 2. `bind` limits `connect` and `send_to` When you bind to a limited address space like localhost, you can only `connect` to addresses in that same address space. Error kind: `AddrNotAvailable`. 3. `connect`ing to localhost locks you to localhost On Linux, if you first `connect` to localhost, subsequent `connect`s to non-localhost addresses fail. Error kind: `InvalidInput`. For debugging the third one, it was really hard to find someone else who already had that problem. I only managed to find this thread: https://www.mail-archive.com/netdev@vger.kernel.org/msg159519.html
2023-08-22Improve UdpSocket documentationPatiga-1/+20
I tried working with `UdpSocket` and ran into `EINVAL` errors with no clear indication of what causes the error. Also, it was uncharacteristically hard to figure this module out, compared to other Rust `std` modules. 1. `send` and `send_to` return a `usize` This one is just clarity. Usually, returned `usize`s indicate that the buffer might have only been sent partially. This is not the case with UDP. Since that `usize` must always be `buffer.len()`, I have documented that. 2. `bind` limits `connect` and `send_to` When you bind to a limited address space like localhost, you can only `connect` to addresses in that same address space. Error kind: `AddrNotAvailable`. 3. `connect`ing to localhost locks you to localhost On Linux, if you first `connect` to localhost, subsequent `connect`s to non-localhost addresses fail. Error kind: `InvalidInput`. Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2023-08-22std: net: skip tests on xousSean Cross-2/+2
Network functionality is not yet ready for merging. Signed-off-by: Sean Cross <sean@xobs.io>
2023-07-28inline trivial (noop) flush callsThom Chiovoloni-0/+2
2023-06-20Rollup merge of #112464 - eval-exec:exec/fix-connect_timeout-overflow, ↵Guillaume Gomez-0/+11
r=ChrisDenton Fix windows `Socket::connect_timeout` overflow This PR want to close #112405 - [x] add unit test
2023-06-20Remove useless unit testsEval EXEC-21/+0
2023-06-20Ignore `connect_timeout` unit test on SGX platformEval EXEC-0/+1
Co-authored-by: Chris Denton <christophersdenton@gmail.com>
2023-06-18Add unit test to connect to an unreachable addressEval EXEC-0/+11
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-18Add unit test for `TcpStream::connect_timeout`Eval EXEC-0/+20
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-14Fix `SocketAddrV6: Display` testsltdk-1/+1
2023-05-13add examples of port 0 binding behaviorkirk-0/+18
2023-05-01Inline AsInner implementationsKonrad Borowski-0/+3
2023-04-08fix(tcp): remove redundant `format!` macro callSergei Belokon-1/+1
2023-04-06chore(tcp): change the hardcoded port number to `port` varSergei Belokon-1/+1
The `listen_on` function in the example has a `port` option but doesn't use it
2023-03-06Implement read_buf for a few more typesTomasz Miąsko-2/+36
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-03-02Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubileebors-2/+8
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr` ⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-02-28Add QNX Neutrino support to libstdFlorian Bartels-2/+8
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-26Move IpAddr and SocketAddr to coreLinus Färnstrand-4468/+26
2023-01-31Replace unwrap with ? in TcpListener docDaniel Chmielewski-1/+1
2023-01-25Stabilize the const_socketaddr featureLinus Färnstrand-13/+13
2023-01-21Remove unnecessary `&format!`Nikolai Vazquez-8/+8
These were likely from before the `PartialEq<str>` impl for `&String`.
2022-12-30Rollup merge of #104182 - gabhijit:ipv6-in6addr-any-doc-fix, r=m-ou-seMatthias Krüger-0/+9
`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation. Added documentation for IPv6 Addresses `IN6ADDR_ANY_INIT` also known as `in6addr_any` and `IN6ADDR_LOOPBACK_INIT` also known as `in6addr_loopback` similar to `INADDR_ANY` for IPv4 Addresses.
2022-11-13Remove unused diagnostic itemsMaybe Waffle-2/+0
2022-11-09`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation.Abhijit Gadgil-0/+9
Added documentation for IPv6 Addresses `IN6ADDR_ANY_INIT` also known as `in6addr_any` and `IN6ADDR_LOOPBACK_INIT` also known as `in6addr_loopback` similar to `INADDR_ANY` for IPv4 Addresses.
2022-10-31Update mod.rstyggja-1/+1
2022-09-12Simplify `clippy` fix.Markus Reiter-2/+0
2022-09-12Add `rustc_diagnostic_item` for IP addresses.Markus Reiter-0/+5
2022-09-12Flatten `net` module again.Markus Reiter-9/+7
2022-09-12Move `net::parser` into `net::addr` module.Markus Reiter-3/+3
2022-09-12Add tests for `SockAddr` `Display`.Markus Reiter-0/+69
2022-09-12Use `DisplayBuffer` for socket addresses.Markus Reiter-46/+34
2022-08-29Rollup merge of #94890 - marmeladema:ip-addr-try-from-bytes, r=joshtriplettMatthias Krüger-13/+125
Support parsing IP addresses from a byte string Fixes #94821 The goal is to be able to parse addresses from a byte string without requiring to do any utf8 validation. Since internally the parser already works on byte strings, this should be possible and I personally already needed this in the past too. ~~I used the proposed approach from the issue by implementing `TryFrom<&'a [u8]>` for all 6 address types (3 ip address types and 3 socket address types). I believe implementing stable traits for stable types is insta-stable so this will probably need an FCP?~~ Switched to an unstable inherent method approach called `parse_ascii` as requested. cc ``````@jyn514``````
2022-08-28Auto merge of #96324 - berendjan:set_tcp_quickack, r=dtolnaybors-1/+1
Add setter and getter for TCP_QUICKACK on TcpStream for Linux Reference issue #96256 Setting TCP_QUICKACK on TcpStream for Linux
2022-08-26Support parsing IP addresses from a byte stringmarmeladema-13/+125
2022-08-22Rollup merge of #99957 - chotchki:ip-globally-reachable_rebase, ↵Dylan DPC-85/+217
r=Mark-Simulacrum Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase Rebasing of pull request #86634 off of master to try and get the feature "ip" stabilized. I also found a test failure in the rebase that is_global was considering the benchmark space to be globally reachable. This is related to my other rebasing pull request #99947
2022-08-16Simplify `IpDisplayBuffer` API.Markus Reiter-6/+10
2022-08-16Use `MaybeUninit<u8>` for `IpDisplayBuffer`.Markus Reiter-6/+12