about summary refs log tree commit diff
path: root/library/std/src/net/tcp.rs
AgeCommit message (Collapse)AuthorLines
2025-09-08std: make address resolution weirdness local to SGXjoboet-2/+2
2025-06-16Set MSG_NOSIGNAL for UnixSteamMichał Łowicki-0/+6
https://github.com/rust-lang/rust/issues/139956 fix
2025-03-10Disable unsupported testsNicole LeGare-1/+2
Unclear why this needs to be done manually and is not done by the existing Trusty patches.
2025-02-02std: move network code into `sys`joboet-1/+2
As per #117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support #135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules. I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
2024-09-30Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichtonTrevor Gross-1/+8
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-1/+1
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-1/+8
2024-09-23Clarifications for set_nonblocking methodsYoh Deadfall-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-21fix issue numberTristan Guichaoua-4/+4
2023-08-22std: net: skip tests on xousSean Cross-1/+1
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-05-13add examples of port 0 binding behaviorkirk-0/+9
2023-05-01Inline AsInner implementationsKonrad Borowski-0/+2
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-1/+9
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-01-31Replace unwrap with ? in TcpListener docDaniel Chmielewski-1/+1
2022-07-02Bump std::net::Incoming FusedIterator impl to Rust 1.64David Tolnay-1/+1
2022-05-23Implement `FusedIterator` for `std::net::[Into]Incoming`Chayim Refael Friedman-0/+7
They never return `None`, so they trivially fulfill the contract.
2022-04-14Remove use of `#[rustc_deprecated]`Jacob Pratt-8/+2
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-5/+5
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-01Fix incorrect panic message in exampleTheVoid-1/+1
2021-11-02read_bufDrMeepster-13/+1
2021-10-30Add #[must_use] to remaining std functions (A-N)John Kugelman-0/+1
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+1
2021-09-17Rollup merge of #88339 - piegamesde:master, r=joshtriplettYuki Okushi-0/+51
Add TcpListener::into_incoming and IntoIncoming The `incoming` method is really useful, however for some use cases the borrow this introduces is needlessly restricting. Thus, an owned variant is added. r? ``@joshtriplett``
2021-08-30add `TcpStream::set_linger` and `TcpStream::linger`ibraheemdev-0/+47
2021-08-26Add TcpListener::into_incoming and IntoIncomingpiegames-0/+51
The `incoming` method is really useful, however for some use cases the borrow this introduces is needlessly restricting. Thus, an owned variant is added.
2021-08-20Auto merge of #87329 - sunfishcode:sunfishcode/io-safety, r=joshtriplettbors-0/+12
I/O safety. 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> Highlights: - The doc comments at the top of library/std/src/os/unix/io/mod.rs and library/std/src/os/windows/io/mod.rs - The new types and traits in library/std/src/os/unix/io/fd.rs and library/std/src/os/windows/io/handle.rs - The removal of the `RawHandle` struct the Windows impl, which had the same name as the `RawHandle` type alias, and its functionality is now folded into `Handle`. Managing five levels of wrapping (File wraps sys::fs::File wraps sys::fs::FileDesc wraps OwnedFd wraps RawFd, etc.) made for a fair amount of churn and verbose as/into/from sequences in some places. I've managed to simplify some of them, but I'm open to ideas here. r? `@joshtriplett`
2021-08-19Add comments about impls for File, TcpStream, ChildStdin, etc.Dan Gohman-0/+12
2021-08-08## ContextRichard Schneeman-7/+14
While going through the "The Rust Programming Language" book (Klabnik & Nichols), the TCP server example directs us to use TcpListener::incoming. I was curious how I could pass this value to a function (before reading ahead in the book), so I looked up the docs to determine the signature. When I opened the docs, I found https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.incoming, which didn't mention TcpStream anywhere in the example. Eventually, I clicked on https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.accept in the docs (after clicking a few other locations first), and was able to surmise that the value contained TcpStream. ## Opportunity While this type is mentioned several times in this doc, I feel that someone should be able to fully use the results of the TcpListner::incoming iterator based solely on the docs of just this method. ## Implementation I took the code from the top-level TcpListener https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.incoming and blended it with the existing docs for TcpListener::incoming https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.incoming. It does make the example a little longer, and it also introduces a little duplication. It also gives the reader the type signatures they need to move on to the next step. ## Additional considerations I noticed that in this doc, `handle_connection` and `handle_client` are both used to accept a TcpStream in the docs on this page. I want to standardize on one function name convention, so readers don't accidentally think two different concepts are being referenced. I didn't want to cram do too much in one PR, I can update this PR to make that change, or I could send another PR (if you would like). First attempted contribution to Rust (and I'm also still very new, hence reading through the rust book for the first time)! Would you please let me know what you think?
2020-11-22Drop support for cloudabi targetsLzu Tao-1/+1
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-866/+4
Also doing fmt inplace as requested.
2020-08-15Move to intra doc links in std::netAlexis Bourget-62/+22
2020-07-27mv std libs to library/mark-0/+1844