about summary refs log tree commit diff
path: root/library/std/src/sys_common/net.rs
AgeCommit message (Collapse)AuthorLines
2023-03-06Implement read_buf for a few more typesTomasz Miąsko-1/+5
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-02-28Add QNX Neutrino support to libstdFlorian Bartels-3/+4
Co-authored-by: gh-tr <troach@qnx.com>
2023-01-28Replace libc::{type} with crate::ffi::{type}Ayush Singh-4/+4
Replace libc::{type} imports with crate::ffi::{type} outside of `std::sys` and `std::os`. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-10-03Reduce CString allocations in std as much as possibleAlex Saveau-9/+11
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-08-13created tcpstream quickack traitBerend-Jan Lange-1/+7
for linux and android
2022-07-31Auto merge of #78802 - faern:simplify-socketaddr, r=joshtriplettbors-13/+48
Implement network primitives with ideal Rust layout, not C system layout This PR is the result of this internals forum thread: https://internals.rust-lang.org/t/why-are-socketaddrv4-socketaddrv6-based-on-low-level-sockaddr-in-6/13321. Instead of basing `std:::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}` on system (C) structs, they are encoded in a more optimal and idiomatic Rust way. This changes the public API of std by introducing structural equality impls for all four types here, which means that `match ipv4addr { SOME_CONSTANT => ... }` will now compile, whereas previously this was an error. No other intentional changes are introduced to public API. It's possible to observe the current layout of these types (e.g., by pointer casting); most but not all libraries which were found by Crater to do this have had updates issued and affected versions yanked. See report below. ### Benefits of this change - It will become possible to move these fundamental network types from `std` into `core` ([RFC](https://github.com/rust-lang/rfcs/pull/2832)). - Some methods that can't be made `const fn`s today can be made `const fn`s with this change. - `SocketAddrV4` only occupies 6 bytes instead of 16 bytes. - These simple primitives become easier to read and uses less `unsafe`. - Makes these types support structural equality, which means you can now (for instance) match an `Ipv4Addr` against a constant ### ~Remaining~ Previous problems This change obviously changes the memory layout of the types. And it turns out some libraries invalidly assumes the memory layout and does very dangerous pointer casts to convert them. These libraries will have undefined behaviour and perform invalid memory access until patched. - [x] - `mio` - Issue: https://github.com/tokio-rs/mio/issues/1386. - [x] `0.7` branch https://github.com/tokio-rs/mio/pull/1388 - [x] `0.7.6` published https://github.com/tokio-rs/mio/pull/1398 - [x] Yank all `0.7` versions older than `0.7.6` - [x] Report `<0.7.6` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0081.html - [x] - `socket2` - Issue: https://github.com/rust-lang/socket2-rs/issues/119. - [x] `0.3.x` branch https://github.com/rust-lang/socket2-rs/pull/120 - [x] `0.3.16` published - [x] `master` branch https://github.com/rust-lang/socket2-rs/pull/122 - [x] Yank all `0.3` versions older than `0.3.16` - [x] Report `<0.3.16` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0079.html - [x] - `net2` - Issue: https://github.com/deprecrated/net2-rs/issues/105 - [x] https://github.com/deprecrated/net2-rs/pull/106 - [x] `0.2.36` published - [x] Yank all `0.2` versions older than `0.2.36` - [x] Report `<0.2.36` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0078.html - [x] - `miow` - Issue: https://github.com/yoshuawuyts/miow/issues/38 - [x] `0.3.x` - https://github.com/yoshuawuyts/miow/pull/39 - [x] `0.3.6` published - [x] `0.2.x` - https://github.com/yoshuawuyts/miow/pull/40 - [x] `0.2.2` published - [x] Yanked all `0.2` versions older than `0.2.2` - [x] Yanked all `0.3` versions older than `0.3.6` - [x] Report `<0.2.2` and `<0.3.6` to RustSec Advisory Database https://rustsec.org/advisories/RUSTSEC-2020-0080.html - [x] - `quinn master` (aka what became 0.7) - https://github.com/quinn-rs/quinn/issues/968 https://github.com/quinn-rs/quinn/pull/987 - [x] - `quinn 0.6` - https://github.com/quinn-rs/quinn/pull/1045 - [x] - `quinn 0.5` - https://github.com/quinn-rs/quinn/pull/1046 - [x] - Release `0.7.0`, `0.6.2` and `0.5.4` - [x] - `nb-connect` - https://github.com/smol-rs/nb-connect/issues/1 - [x] - Release `1.0.3` - [x] - Yank all versions older than `1.0.3` - [x] - `shadowsocks-rust` - https://github.com/shadowsocks/shadowsocks-rust/issues/462 - [ ] - `rio` - https://github.com/spacejam/rio/issues/44 - [ ] - `seaslug` - https://github.com/spacejam/seaslug/issues/1 #### Fixed crate versions All crates I have found that assumed the memory layout have been fixed and published. The crates and versions that will continue working even as/if this PR is merged is (please upgrade these to help unblock this PR): * `net2 0.2.36` * `socket2 0.3.16` * `miow 0.2.2` * `miow 0.3.6` * `mio 0.7.6` * `mio 0.6.23` - Never had the invalid assumption itself, but has now been bumped to only allow fixed dependencies (`net2` + `miow`) * `nb-connect 1.0.3` * `quinn 0.5.4` * `quinn 0.6.2` ### Release notes draft This release changes the memory layout of `Ipv4Addr`, `Ipv6Addr`, `SocketAddrV4` and `SocketAddrV6`. The standard library no longer implements these as the corresponding `libc` structs (`sockaddr_in`, `sockaddr_in6` etc.). This internal representation was never exposed, but some crates relied on it anyway by unsafely transmuting. This change will cause those crates to make invalid memory accesses. Notably `net2 <0.2.36`, `socket2 <0.3.16`, `mio <0.7.6`, `miow <0.3.6` and a few other crates are affected. All known affected crates have been patched and have had fixed versions published over a year ago. If any affected crate is still in your dependency tree, you need to upgrade them before using this version of Rust.
2022-07-20Library changes for Apple WatchOSVladimir Michael Eatwell-1/+1
2022-07-17Move SocketAddrCRepr to sys_commonLinus Färnstrand-0/+35
2022-06-23Implement IpV{4,6}Addr structs with native Rust encodingLinus Färnstrand-3/+3
2022-06-23Represent SocketAddrV4 and SocketAddrV6 as Rust native encodingLinus Färnstrand-10/+10
2022-06-13Lower listen backlog to fix accept crashesAzureMarker-6/+13
See https://github.com/Meziu/rust-horizon/pull/1
2022-06-13Horizon OS STD supportMeziu-0/+5
Co-authored-by: Ian Chamberlain <ian.h.chamberlain@gmail.com> Co-authored-by: Mark Drobnak <mark.drobnak@gmail.com>
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-1/+0
2022-02-20Remove assertion on output length for `getsockopt`.Chris Copeland-1/+0
POSIX allows `getsockopt` to set `*option_len` to a smaller value if necessary. Windows will set `*option_len` to 1 for boolean options even when the caller passes a `BOOL` (`int`) with `*option_len` as 4.
2022-02-20Fix `setsockopt` and `getsockopt` parameter names.Chris Copeland-9/+25
Previously `level` was named `opt` and `option_name` was named `val`, then extra names of `payload` or `slot` were used for the option value. This change aligns the wrapper parameters with their names in POSIX. Winsock uses similar but more abbreviated names: `level`, `optname`, `optval`, `optlen`.
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-3/+3
2021-08-30add `TcpStream::set_linger` and `TcpStream::linger`ibraheemdev-0/+8
2021-08-19I/O safety.Dan Gohman-24/+18
Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: - <https://github.com/rust-lang/rust/issues/87074> RFC: - <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md>
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-2/+2
2020-12-07Fix net.rs - rsplitn() returns a reverse iteratorEric Arellano-2/+1
2020-12-07Dogfood 'str_split_once()` in the std libEric Arellano-3/+1
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-23/+3
Also doing fmt inplace as requested.
2020-08-19Minor changes to Ipv4AddrLzu Tao-4/+4
* Impl IntoInner rather than AsInner for Ipv4Addr * Add some comments * Add test to show endiannes of Ipv4Addr display
2020-07-27mv std libs to library/mark-0/+697