about summary refs log tree commit diff
path: root/src/libstd/net
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-7686/+0
2020-07-02libstd/net/tcp.rs: #![deny(unsafe_op_in_unsafe_fn)]Yashhwanth Ram-2/+5
Enclose unsafe operations in unsafe blocks
2020-07-01Rollup merge of #72369 - Lucretiel:socketaddr-parse, r=dtolnayManish Goregaokar-193/+289
Bring net/parser.rs up to modern up to date with modern rust patterns The current implementation of IP address parsing is very unidiomatic; it's full of `if` / `return` / `is_some` / `is_none` instead of `?`, `loop` with manual index tracking; etc. Went through and did and cleanup to try to bring it in line with modern sensibilities. The obvious concern with making changes like this is "make sure you understand why it's written that way before changing it". Looking through the commit history for this file, there are several much smaller commits that make similar changes (For instance, https://github.com/rust-lang/rust/commit/3024c1434a667425d30e4b0785857381323712aa, https://github.com/rust-lang/rust/commit/4f3ab4986ec96d9c93f34dc53d0a4a1279288451, https://github.com/rust-lang/rust/commit/79f876495b2853d1b78ba953ceb3114b8019100f), and there don't seem to be any commits in the history that indicate that this lack of idiomaticity is related to specific performance needs (ie, there aren't any commits that replace a `for` loop with a `loop` and a manual index count). In fact, the basic shape of the file is essentially unchanged from its initial commit back in 2015. Made the following changes throughout the IP address parser: - Replaced all uses of `is_some()` / `is_none()` with `?`. - "Upgraded" loops wherever possible; ie, replace `while` with `for`, etc. - Removed all cases of manual index tracking / incrementing. - Renamed several single-character variables with more expressive names. - Replaced several manual control flow segments with equivalent adapters (such as `Option::filter`). - Removed `read_seq_3`; replaced with simple sequences of `?`. - Parser now reslices its state when consuming, rather than carrying a separate state and index variable. - `read_digit` now uses `char::to_digit`. - Added comments throughout, especially in the complex IPv6 parsing logic. - Added comprehensive local unit tests for the parser to validate these changes.
2020-06-30Bring net/parser.rs up to modern up to date with modern rust patternsNathan West-193/+289
Made the following changes throughout the IP address parser: - Replaced all uses of `is_some()` / `is_none()` with `?`. - "Upgraded" loops wherever possible; ie, replace `while` with `for`, etc. - Removed all cases of manual index tracking / incrementing. - Renamed several single-character variables with more expressive names. - Replaced several manual control flow segments with equivalent adapters (such as `Option::filter`). - Removed `read_seq_3`; replaced with simple sequences of `?`. - Parser now reslices its state when consuming, rather than carrying a separate state and index variable. - `read_digit` now uses `char::to_digit`. - Removed unnecessary casts back and forth between u8 and u32 - Added comments throughout, especially in the complex IPv6 parsing logic. - Added comprehensive local unit tests for the parser to validate these changes.
2020-06-23Auto merge of #73007 - yoshuawuyts:socketaddr-from-string-u16, r=sfacklerbors-0/+8
impl ToSocketAddrs for (String, u16) This adds a convenience impl of `ToSocketAddrs for (String, u16)`. When authoring HTTP services it's common to take command line options for `host` and `port` and parse them into `String` and `u16` respectively. Consider the following program: ```rust #[derive(Debug, StructOpt)] struct Config { host: String, port: u16, } async fn main() -> io::Result<()> { let config = Config::from_args(); let stream = TcpStream::connect((&*config.host, config.port))?; // &* is not ideal // ... } ``` Networking is a pretty common starting point for people new to Rust, and seeing `&*` in basic examples can be confusing. Even as someone that has experience with networking in Rust I tend to forget that `String` can't be passed directly there. Instead with this patch we can omit the `&*` conversion and pass `host` directly: ```rust #[derive(Debug, StructOpt)] struct Config { host: String, port: u16, } async fn main() -> io::Result<()> { let config = Config::from_args(); let stream = TcpStream::connect((config.host, config.port))?; // no more conversions! // ... } ``` I think should be an easy and small ergonomics improvement for networking. Thanks!
2020-06-13Add test for comparing SocketAddr with inferred right-hand sideDavid Tolnay-0/+5
2020-06-12Revert heterogeneous SocketAddr PartialEq implsDavid Tolnay-40/+0
These lead to inference regressions (mostly in tests) in code that looks like: let socket = std::net::SocketAddrV4::new(std::net::Ipv4Addr::new(127, 0, 0, 1), 8080); assert_eq!(socket, "127.0.0.1:8080".parse().unwrap()); That compiles as of stable 1.44.0 but fails in beta with: error[E0284]: type annotations needed --> src/main.rs:3:41 | 3 | assert_eq!(socket, "127.0.0.1:8080".parse().unwrap()); | ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse` | = note: cannot satisfy `<_ as std::str::FromStr>::Err == _` help: consider specifying the type argument in the method call | 3 | assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap()); |
2020-06-05impl ToSocketAddrs for (String, u16)Yoshua Wuyts-0/+8
2020-05-29Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJungbors-80/+78
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
2020-05-29Rollup merge of #72407 - Lucretiel:ipv6-display, r=Mark-SimulacrumRalf Jung-80/+78
Various minor improvements to Ipv6Addr::Display Cleaned up `Ipv6Addr::Display`, especially with an eye towards simplifying and reducing duplicated logic. Also added a fast-path optimization, similar to #72399 and #72398. - Defer to `Ipv4Addr::fmt` when printing an Ipv4 address - Fast path: write directly to `f` without an intermediary buffer when there are no alignment options - Simplify finding the inner zeroes-span
2020-05-29Clarify comment message & MAX_LENGTH constNathan West-3/+7
2020-05-29Added fast-path, testsNathan West-20/+54
2020-05-29`SocketAddr(V4|V6)?`::Display now correctly pads its contentNathan West-3/+27
IpAddr and friends pad when displaying; SocketAddr now does this as well
2020-05-29Rollup merge of #72239 - hch12907:master, r=dtolnayDylan DPC-1/+106
Implement PartialOrd and Ord for SocketAddr* The implementation is mostly the same as the one found in `IpAddr` (other than adding comparison for ports, of course). Continues #53788 and #53863 Fixes #53710
2020-05-24Fix testsHoe Hao Cheng-2/+2
2020-05-24Remove heterogeneous ordering for SocketAddrHoe Hao Cheng-55/+15
2020-05-20Various minor improvements to Ipv6Addr::DisplayNathan West-80/+78
- Defer to Ipv4Addr::fmt when printing an Ipv4 address - Fast path: write directly to f without an intermediary buffer when there are no alignment options - Simplify finding the inner zeroes-span
2020-05-20Add fast-path optimization for Ipv4Addr::fmtNathan West-9/+16
2020-05-16Implement PartialOrd and Ord for SocketAddr*Hoe Hao Cheng-1/+146
2020-04-26Update nameSteven Fackler-8/+8
2020-04-26Add Read/Write::can_read/write_vectoredSteven Fackler-0/+20
When working with an arbitrary reader or writer, code that uses vectored operations may end up being slower than code that copies into a single buffer when the underlying reader or writer doesn't actually support vectored operations. These new methods allow you to ask the reader or witer up front if vectored operations are efficiently supported. Currently, you have to use some heuristics to guess by e.g. checking if the read or write only accessed the first buffer. Hyper is one concrete example of a library that has to do this dynamically: https://github.com/hyperium/hyper/blob/0eaf304644a396895a4ce1f0146e596640bb666a/src/proto/h1/io.rs#L582-L594
2020-03-20For issue 53957: revise unit tests to focus on underlying bug of 23076.Felix S. Klock II-4/+19
Namely, this version focuses on the end-to-end behavior that the attempt to create the UDP binding will fail, regardless of the semantics of how particular DNS servers handle junk inputs. (I spent some time trying to create a second more-focused test that would sidestep the DNS resolution, but this is not possible without more invasive changes to the internal infrastructure of `ToSocketAddrs` and what not. It is not worth it.)
2020-03-06fix various typosMatthias Krüger-1/+1
2020-03-02Don't convert Results to Options just for matching.Matthias Krüger-1/+1
2020-02-29simplify boolean expressionsMatthias Krüger-1/+1
2020-01-29Document remaining undocumented `From` implementations for IPsLeSeulArtichaut-0/+72
2020-01-09Rollup merge of #67966 - popzxc:core-std-matches, r=CentrilMazdak Farrokhzad-16/+4
Use matches macro in libcore and libstd This PR replaces matches like ```rust match var { value => true, _ => false, } ``` with use of `matches!` macro. r? @Centril
2020-01-08Use matches macro in libcore and libstdIgor Aleksanov-16/+4
2020-01-06Removed module usage.Strømberg-1/+0
2020-01-06Missing module std in example.Strømberg-1/+1
2019-12-26Implement padding for IpAddr without heap allocDario Gonzalez-13/+80
2019-12-24Deprecate Error::description for realDavid Tolnay-0/+2
`description` has been documented as soft-deprecated since 1.27.0 (17 months ago). There is no longer any reason to call it or implement it. This commit: - adds #[rustc_deprecated(since = "1.41.0")] to Error::description; - moves description (and cause, which is also deprecated) below the source and backtrace methods in the Error trait; - reduces documentation of description and cause to take up much less vertical real estate in rustdocs, while preserving the example that shows how to render errors without needing to call description; - removes the description function of all *currently unstable* Error impls in the standard library; - marks #[allow(deprecated)] the description function of all *stable* Error impls in the standard library; - replaces miscellaneous uses of description in example code and the compiler.
2019-12-22Format the worldMark Rousskov-215/+278
2019-12-19Rollup merge of #67321 - lzutao:htons, r=dtolnayMazdak Farrokhzad-22/+11
make htons const fn This may partially help #67315.
2019-12-18Propagate cfg bootstrapMark Rousskov-4/+4
2019-12-15make htons const fnLzu Tao-22/+11
2019-12-14Delete flaky test net::tcp::tests::fast_rebindDavid Tolnay-15/+0
2019-12-13Require stable/unstable annotations for the constness of all stable ↵Oliver Scherer-0/+4
functions with a `const` modifier
2019-12-06Remove boxed closures in address parser.Markus Reiter-19/+4
2019-11-29Format libstd with rustfmtDavid Tolnay-212/+294
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-11-13Fix broken links in Ipv4Addr::is_benchmarking docsBenjamin Sago-2/+2
2019-11-10Rollup merge of #66058 - mjptree:patch-2, r=kennytmYuki Okushi-1/+1
Correct deprecated `is_global` IPv6 documentation This method does currently not return false for the `site_local` unicast address space. The documentation of the `is_unicast_global` method on lines 1352 - 1382 suggests that this is intentional as the site-local prefix must no longer be supported in new implementations, thus the documentation can safely be updated to reflect that information. If not so, either the `is_unicast_global` method should be updated to exclude the unicast site-local address space, or the `is_global` method itself.
2019-11-09Update src/libstd/net/ip.rs mjptree-1/+1
I assumed some sort of Oxford-comma case here, bit have to admit English is not my first language. Co-Authored-By: kennytm <kennytm@gmail.com>
2019-11-03 Correct deprecated `is_global` IPv6 documentationmjptree-1/+1
This method does currently not return false for the `site_local` unicast address space. The documentation of the `is_unicast_global` method on lines 1352 - 1382 suggests that this is intentional as the site-local prefix must no longer be supported in new implementations, thus the documentation can safely be updated to reflect that information. If not so, either the `is_unicast_global` method should be updated to exclude the unicast site-local address space, or the `is_global` method itself.
2019-11-02Correct error in documentation for Ipv4Addr methodmjptree-1/+1
Correct statement in doctests on line 539 of `is_global` method of the `Ipv4Addr` object, which falsely attributed the tests to the broadcast address.
2019-10-20Remove leading :: from paths in doc examplesMikko Rantanen-1/+1
2019-10-05Rollup merge of #64728 - messense:udp-peer-addr, r=dtolnayTyler Mandry-3/+1
Stabilize UdpSocket::peer_addr Fixes #59127
2019-10-01Remove unneeded `fn main` blocks from docsLzu Tao-146/+108
2019-09-26Update src/libstd/net/udp.rsmessense-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-09-24Stabilize UdpSocket::peer_addrmessense-3/+1