about summary refs log tree commit diff
path: root/src/libstd/sys/unix/net.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-382/+0
2020-07-21Remove Linux workarounds for missing CLOEXEC supportJosh Stone-61/+42
Now that #74163 updated the minimum Linux kernel to 2.6.32, we can assume the availability of APIs that open file descriptors that are already set to close on exec, including the flags `O_CLOEXEC`, `SOCK_CLOEXEC`, and `F_DUPFD_CLOEXEC`.
2020-06-10Migrate to numeric associated constsLzu Tao-3/+3
2020-04-26Update nameSteven Fackler-4/+4
2020-04-26Add Read/Write::can_read/write_vectoredSteven Fackler-0/+10
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-04-15Use fcntl() to set nonblock for solarish socketsPatrick Mooney-0/+8
The ioctl(FIONBIO) method of setting a file descriptor to be non-blocking does not notify the underlying resource in the same way that fcntl(F_SETFL, O_NONBLOCK) does on illumos and Solaris.
2020-03-01use subdsec_micros() instead of subsec_nanos() / 1000Matthias Krüger-1/+1
2020-01-02Use drop instead of the toilet closure `|_| ()`Lzu Tao-1/+1
2019-12-20Remove `SOCK_CLOEXEC` dummy variable on platforms that don't use it.Markus Reiter-16/+9
2019-12-18Remove `SO_NOSIGPIPE` dummy variable on platforms that don't use it.Markus Reiter-11/+6
2019-11-29Format libstd/sys with rustfmtDavid Tolnay-59/+53
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd/sys *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/sys -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd/sys outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of the files. 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-04-27Stabilized vectored IOSteven Fackler-3/+3
This renames `std::io::IoVec` to `std::io::IoSlice` and `std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes `std::io::IoSlice`, `std::io::IoSliceMut`, `std::io::Read::read_vectored`, and `std::io::Write::write_vectored`. Closes #58452
2019-02-28Fix rebase failTaiki Endo-1/+1
2019-02-28libstd => 2018Taiki Endo-12/+15
2019-02-13Add vectored read and write supportSteven Fackler-1/+9
This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies.
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-20Fix pipe2 and accept4 on static linked executables on linux (like musl).Adrian Budau-11/+14
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-1/+1
2018-08-27fix a typo: taget_env -> target_envJack O'Connor-27/+0
This typo was introduced in https://github.com/rust-lang/rust/pull/47334. A couple tests bitrotted as a result, so we fix those too, and move them to a more sensible place.
2018-08-19Fix typos found by codespell.Matthias Krüger-1/+1
2018-03-02Move glibc version lookup handling to sys::os and add a simpler glibc_version()Bryan Drewery-28/+5
2018-01-16Only link res_init() on GNU/*nixRyan Cumming-7/+13
To workaround a bug in glibc <= 2.26 lookup_host() calls res_init() based on the glibc version detected at runtime. While this avoids calling res_init() on platforms where it's not required we will still end up linking against the symbol. This causes an issue on macOS where res_init() is implemented in a separate library (libresolv.9.dylib) from the main libc. While this is harmless for standalone programs it becomes a problem if Rust code is statically linked against another program. If the linked program doesn't already specify -lresolv it will cause the link to fail. This is captured in issue #46797 Fix this by hooking in to the glibc workaround in `cvt_gai` and only activating it for the "gnu" environment on Unix This should include all glibc platforms while excluding musl, windows-gnu, macOS, FreeBSD, etc. This has the side benefit of removing the #[cfg] in sys_common; only unix.rs has code related to the workaround now.
2017-10-14Fix TcpStream::connect_timeout on linuxSteven Fackler-4/+9
Linux appears to set POLLOUT when a conection's refused, which is pretty weird. Invert the check to look for an error explicitly. Also add an explict test for this case. Closes #45265.
2017-10-05replace libc::res_init with res_init_if_glibc_before_2_26Jack O'Connor-0/+79
The previous workaround for gibc's res_init bug is not thread-safe on other implementations of libc, and it can cause crashes. Use a runtime check to make sure we only call res_init when we need to, which is also when it's safe. See https://github.com/rust-lang/rust/issues/43592.
2017-07-06Implement TcpStream::connect_timeoutSteven Fackler-1/+66
This breaks the "single syscall rule", but it's really annoying to hand write and is pretty foundational.
2017-06-20Add `Read::initializer`.Steven Fackler-4/+0
This is an API that allows types to indicate that they can be passed buffers of uninitialized memory which can improve performance.
2017-02-04libstd/net: Add `peek` APIs to UdpSocket and TcpStreamTyler Julian-3/+42
These methods enable socket reads without side-effects. That is, repeated calls to peek() return identical data. This is accomplished by providing the POSIX flag MSG_PEEK to the underlying socket read operations. This also moves the current implementation of recv_from out of the platform-independent sys_common and into respective sys/windows and sys/unix implementations. This allows for more platform-dependent implementations.
2016-09-28set SO_NOSIGPIPE on apple platformsMathieu Poumeyrol-1/+13
2016-09-26When getaddrinfo returns EAI_SYSTEM retrieve actual error from errno.Tomasz Miąsko-2/+7
Fixes issue #36546. This change also updates libc to earliest version that includes EAI_SYSTEM constant.
2016-09-07Fix argument to FIONBIO ioctlUlrich Weigand-1/+1
The FIONBIO ioctl takes as argument a pointer to an integer, which should be either 0 or 1 to indicate whether nonblocking mode is to be switched off or on. The type of the pointed-to variable is "int". However, the set_nonblocking routine in libstd/sys/unix/net.rs passes a pointer to a libc::c_ulong variable. This doesn't matter on all 32-bit platforms and on all litte-endian platforms, but it will break on big-endian 64-bit platforms. Found while porting Rust to s390x (a big-endian 64-bit platform). Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-2/+0
2016-07-20std: Fix usage of SOCK_CLOEXECAlex Crichton-2/+2
This code path was intended to only get executed on Linux, but unfortunately the `cfg!` was malformed so it actually never got executed.
2016-06-24Bubble up the errors in `set_nonblocking` and `set_cloexec`Tobias Bucher-4/+4
2016-03-22try! -> ?Jorge Aparicio-8/+8
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
2016-03-20Add unix socket support to the standard librarySteven Fackler-1/+42
2016-03-08std: Funnel read_to_end through to one locationAlex Crichton-0/+4
This pushes the implementation detail of proxying `read_to_end` through to `read_to_end_uninitialized` all the way down to the `FileDesc` and `Handle` implementations on Unix/Windows. This way intermediate layers will also be able to take advantage of this optimized implementation. This commit also adds the optimized implementation for `ChildStdout` and `ChildStderr`.
2016-02-28Fix windowsSteven Fackler-39/+5
Also back out keepalive support for TCP since the API is perhaps not actually what we want. You can't read the interval on Windows, and we should probably separate the functionality of turning keepalive on and overriding the interval.
2016-02-28Add TCP functionality from net2Steven Fackler-0/+48
2016-02-24Warn when reexporting a private extern crateJeffrey Seyfried-1/+1
2016-02-05std: Add support for accept4 on LinuxAlex Crichton-3/+23
This is necessary to atomically accept a socket and set the CLOEXEC flag at the same time. Support only appeared in Linux 2.6.28 so we have to dynamically determine which syscall we're supposed to call in this case.
2016-02-05std: Atomically set CLOEXEC for sockets if possibleAlex Crichton-0/+23
This commit adds support for creating sockets with the `SOCK_CLOEXEC` flag. Support for this flag was added in Linux 2.6.27, however, and support does not exist on platforms other than Linux. For this reason we still have the same fallback as before but just special case Linux if we can.
2016-02-04Add File::try_cloneSteven Fackler-39/+1
2015-11-09std: Migrate to the new libcAlex Crichton-17/+42
* Delete `sys::unix::{c, sync}` as these are now all folded into libc itself * Update all references to use `libc` as a result. * Update all references to the new flat namespace. * Moves all windows bindings into sys::c
2015-09-08some more clippy-based improvementsAndre Bogus-1/+1
2015-08-30Atomically set CLOEXEC on duplicated socketsTobias Bucher-5/+25
For Bitrig, NetBSD and OpenBSD the constant was incorrectly in posix01, when it's actually posix08, so we move it. This is a [breaking-change], but we already had one in #27930. Fix NetBSD's F_DUPFD_CLOEXEC constant. For a similar feature detection, see this musl thread: http://comments.gmane.org/gmane.linux.lib.musl.general/2963 This assumes that an int literal has type `c_int` for varidic functions.
2015-08-10Stabilize the Duration APISteven Fackler-4/+4
This commit stabilizes the `std::time` module and the `Duration` type. `Duration::span` remains unstable, and the `Display` implementation for `Duration` has been removed as it is still being reworked and all trait implementations for stable types are de facto stable. This is a [breaking-change] to those using `Duration`'s `Display` implementation.
2015-07-20std: Add IntoRaw{Fd,Handle,Socket} traitsAlex Crichton-1/+5
This commit is an implementation of [RFC 1174][rfc] which adds three new traits to the standard library: * `IntoRawFd` - implemented on Unix for all I/O types (files, sockets, etc) * `IntoRawHandle` - implemented on Windows for files, processes, etc * `IntoRawSocket` - implemented on Windows for networking types [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1174-into-raw-fd-socket-handle-traits.md Closes #27062
2015-05-28Implement RFC 1047 - socket timeoutsSteven Fackler-0/+45
Closes #25619
2015-04-09std: Set CLOEXEC for all fds opened on unixAlex Crichton-5/+10
This commit starts to set the CLOEXEC flag for all files and sockets opened by the standard library by default on all unix platforms. There are a few points of note in this commit: * The implementation is not 100% satisfactory in the face of threads. File descriptors only have the `F_CLOEXEC` flag set *after* they are opened, allowing for a fork/exec to happen in the middle and leak the descriptor. Some platforms do support atomically opening a descriptor while setting the `CLOEXEC` flag, and it is left as a future extension to bind these apis as it is unclear how to do so nicely at this time. * The implementation does not offer a method of opting into the old behavior of not setting `CLOEXEC`. This will possibly be added in the future through extensions on `OpenOptions`, for example. * This change does not yet audit any Windows APIs to see if the handles are inherited by default by accident. This is a breaking change for users who call `fork` or `exec` outside of the standard library itself and expect file descriptors to be inherted. All file descriptors created by the standard library will no longer be inherited. [breaking-change]
2015-03-31rollup merge of #23919: alexcrichton/stabilize-io-errorAlex Crichton-1/+2
Conflicts: src/libstd/fs/tempdir.rs src/libstd/io/error.rs