about summary refs log tree commit diff
path: root/library/std/src/sys/net/connection/socket
AgeCommit message (Collapse)AuthorLines
2025-09-29Rollup merge of #146937 - joboet:gethostname, r=Mark-SimulacrumMatthias Krüger-77/+3
std: implement `hostname` Resolves https://github.com/rust-lang/libs-team/issues/330 Tracking issue: https://github.com/rust-lang/rust/issues/135142 This is based on rust-lang/rust#135141, but I've reimplemented the UNIX version, which now: * uses `sysconf(_SC_HOST_NAME_MAX)` as an initial buffer length * returns `OutOfMemory` if the `Vec` allocation fails * retries the operation if it detects that the name returned by `gethostname` was truncated Additionally, as part of the rebase, I had to move some WinSock abstractions (initialisation and error access) to `sys::pal` so that they can be accessed from `sys::net::hostname`. CC ``@orowith2os`` (and thank you for your work!)
2025-09-28Rollup merge of #140482 - devnexen:tcp_deferaccept_toduration, r=joboetMatthias Krüger-4/+5
std::net: update tcp deferaccept delay type to Duration. See comment [here](https://github.com/rust-lang/rust/issues/119639#issuecomment-2839330337).
2025-09-26std::net: update tcp deferaccept delay type to Duration.David Carlier-4/+5
2025-09-23std: move WinSock abstractions to `sys::pal`joboet-77/+3
2025-09-19std: simplify host lookupjoboet-44/+16
2025-09-11Implement `Socket::take_error` for HermitMartin Kröning-1/+2
2025-09-10Rollup merge of #145327 - joboet:net-addr-sgx-hack, r=tgross35Matthias Krüger-0/+854
std: make address resolution weirdness local to SGX Currently, the implementations of `TcpStream::connect` and its cousins take an `io::Result<&SocketAddr>` as argument, which is very weird, as most of them then `?`-try the result immediately to access the actual address. This weirdness is however necessitated by a peculiarity of the SGX networking implementation: SGX doesn't support DNS resolution but rather accepts hostnames in the same place as socket addresses. So, to make e.g. ```rust TcpStream::connect("example.com:80")` ``` work, the DNS lookup returns a special error (`NonIpSockAddr`) instead, which contains the hostname being looked up. When `.to_socket_addrs()` fails, the `each_addr` function used to select an address will pass the error to the inner `TcpStream::connect` implementation, which in SGX's case will inspect the error and try recover the hostname from it. If that succeeds, it continues with the found hostname. This is pretty obviously a terrible hack and leads to buggy code (for instance, when users use the result of `.to_socket_addrs()` in their own `ToSocketAddrs` implementation to select from a list of possible URLs, the only URL used will be that of the last item tried). Still, without changes to the SGX usercall ABI, it cannot be avoided. Therefore, this PR aims to minimise the impact of that weirdness and remove it from all non-SGX platforms. The inner `TcpStream::connect`, et al. functions now receive the `ToSocketAddrs` type directly and call `each_addr` (which is moved to `sys::net::connection`) themselves. On SGX, the implementation uses a special `each_addr` which contains the whole pass-hostname-through-error hack. As well as making the code cleaner, this also opens up the possibility of reusing newly created sockets even if a connection request fails – but I've left that for another PR. CC `@raoulstrackx`
2025-09-08std: make address resolution weirdness local to SGXjoboet-0/+854
2025-09-06Rollup merge of #139524 - Berrysoft:cygwin-socket-ext, r=tgross35Trevor Gross-6/+6
Add socket extensions for cygwin r? `@joboet` * Abstract name uds addr * quickack * passcred
2025-09-06Add socket extensions for cygwinBerrysoft-6/+6
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-15/+19
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-07-14Don't call WSACleanup on process exitChris Denton-15/+21
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-28Rollup merge of #123476 - devnexen:std_net_solaris_exclbind, r=Mark-SimulacrumMatthias Krüger-0/+15
std::net: adding `unix_socket_exclbind` feature for solaris/illumos. allows to have a tigher control over the binding exclusivness of the socket. ACP: https://github.com/rust-lang/libs-team/issues/366
2025-06-16Set MSG_NOSIGNAL for UnixSteamMichał Łowicki-0/+8
https://github.com/rust-lang/rust/issues/139956 fix
2025-06-10std::net: adding `unix_socket_exclbind` feature for solaris/illumos.David Carlier-0/+15
allows to have a tigher control over the binding exclusivness of the socket.
2025-04-05std: Fix build for NuttX targetsThalia Archibald-0/+1
Fix std build for all NuttX targets. It is the single largest set of failures on <https://does-it-build.noratrieb.dev/>. Although, ESP-IDF also requires these same gates, there are other issues for those targets. This can verified be running `x check library/std --target=` for all NuttX targets.
2025-03-10Fix `std::sys::unix::set_linger` for CygwinOokiineko-0/+11
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
2025-03-10Initial STD support for Cygwin王宇逸-0/+3
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-9/+9
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-02-13Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in unixxizheyin-2/+5
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-12std: replace the `FromInner` implementation for addresses with private ↵joboet-30/+31
conversion functions Having these implementation available crate-wide means that platforms not using sockets for their networking code have to stub out the libc definitions required to support them. This PR moves the conversions to private helper functions that are only available where actually needed. I also fixed the signature of the function converting from a C socket address to a Rust one: taking a reference to a `sockaddr_storage` resulted in unsound usage inside `LookupHost::next`, which could create a reference to a structure smaller than `sockaddr_storage`. Thus I've replaced the argument type with a pointer and made the function `unsafe`.
2025-02-02std: move network code into `sys`joboet-0/+2421
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.