about summary refs log tree commit diff
path: root/src/libstd/sys/unix/fd.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-258/+0
2020-07-23Rollup merge of #74606 - cuviper:cloexec, r=sfacklerManish Goregaokar-45/+3
Remove Linux workarounds for missing CLOEXEC support 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`. Closes #74519.
2020-07-23Prefer constant over functionLzu Tao-16/+17
2020-07-21Remove Linux workarounds for missing CLOEXEC supportJosh Stone-45/+3
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-7/+3
2020-04-26Update nameSteven Fackler-2/+2
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-14Add illumos triplePatrick Mooney-0/+2
Co-Authored-By: Jason King <jason.brian.king@gmail.com> Co-Authored-By: Joshua M. Clulow <jmc@oxide.computer>
2019-12-21Require issue = "none" over issue = "0" in unstable attributesRoss MacArthur-1/+1
2019-11-29Format libstd/sys with rustfmtDavid Tolnay-58/+73
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-10-17Update emscripten functions declarationsMateusz Mikuła-32/+2
2019-08-06redox: convert to target_family unixJeremy Soller-2/+4
2019-07-10filedesc: don't use ioctl(FIOCLEX) on LinuxAleksa Sarai-0/+2
All ioctl(2)s will fail on O_PATH file descriptors on Linux (because they use &empty_fops as a security measure against O_PATH descriptors affecting the backing file). As a result, File::try_clone() and various other methods would always fail with -EBADF on O_PATH file descriptors. The solution is to simply use F_SETFD (as is used on other unices) which works on O_PATH descriptors because it operates through the fnctl(2) layer and not through ioctl(2)s. Since this code is usually only used in strange error paths (a broken or ancient kernel), the extra overhead of one syscall shouldn't cause any dramas. Most other systems programming languages also use the fnctl(2) so this brings us in line with them. Fixes: rust-lang/rust#62314 Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
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-28libstd => 2018Taiki Endo-9/+10
2019-02-13Add vectored read and write supportSteven Fackler-1/+19
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-11-13fix various typos in doc commentsAndy Russell-1/+1
2018-11-06refactor: use shorthand fieldsteresy-1/+1
2018-09-05Implement initializer() for FileDescFrançois Bernier-1/+6
in order to avoid constantly zeroing memory when it's not needed.
2018-08-28Fix typo in commentDimitri Merejkowsky-1/+1
2018-05-16Rollup merge of #50638 - tbu-:pr_open_cloexec_once, r=nagisakennytm-0/+7
Don't unconditionally set CLOEXEC twice on every fd we open on Linux Previously, every `open64` was accompanied by a `ioctl(…, FIOCLEX)`, because some old Linux version would ignore the `O_CLOEXEC` flag we pass to the `open64` function. Now, we check whether the `CLOEXEC` flag is set on the first file we open – if it is, we won't do extra syscalls for every opened file. If it is not set, we fall back to the old behavior of unconditionally calling `ioctl(…, FIOCLEX)` on newly opened files. On old Linuxes, this amounts to one extra syscall per process, namely the `fcntl(…, F_GETFD)` call to check the `CLOEXEC` flag. On new Linuxes, this reduces the number of syscalls per opened file by one, except for the first file, where it does the same number of syscalls as before (`fcntl(…, F_GETFD)` to check the flag instead of `ioctl(…, FIOCLEX)` to set it).
2018-05-14Don't unconditionally set CLOEXEC twice on every fd we open on LinuxTobias Bucher-0/+7
Previously, every `open64` was accompanied by a `ioctl(…, FIOCLEX)`, because some old Linux version would ignore the `O_CLOEXEC` flag we pass to the `open64` function. Now, we check whether the `CLOEXEC` flag is set on the first file we open – if it is, we won't do extra syscalls for every opened file. If it is not set, we fall back to the old behavior of unconditionally calling `ioctl(…, FIOCLEX)` on newly opened files. On old Linuxes, this amounts to one extra syscall per process, namely the `fcntl(…, F_GETFD)` call to check the `CLOEXEC` flag. On new Linuxes, this reduces the number of syscalls per opened file by one, except for the first file, where it does the same number of syscalls as before (`fcntl(…, F_GETFD)` to check the flag instead of `ioctl(…, FIOCLEX)` to set it).
2018-05-12Do not silently truncate offsets for `read_at`/`write_at` on emscriptenTobias Bucher-2/+16
Generate an IO error if the offset is out of bounds for the system call.
2017-09-08Add modifications needed for L4re in libstdTobias Schaffner-0/+2
This commit adds the needed modifications to compile the std crate for the L4 Runtime environment (L4Re). A target for the L4Re was introduced in commit: c151220a84e40b65e45308cc0f3bbea4466d3acf In many aspects implementations for linux also apply for the L4Re microkernel. Two uncommon characteristics had to be resolved: * L4Re has no network funktionality * L4Re has a maximum stacksize of 1Mb for threads Co-authored-by: Sebastian Humenda <sebastian.humenda@tu-dresden.de>
2017-08-28Update the libc submoduleAlex Crichton-6/+22
Brings in a few fixes for wasm/asmjs
2017-06-20Add `Read::initializer`.Steven Fackler-5/+0
This is an API that allows types to indicate that they can be passed buffers of uninitialized memory which can improve performance.
2017-03-12Update usages of 'OSX' (and other old names) to 'macOS'.Corey Farwell-1/+1
As of last year with version 'Sierra', the Mac operating system is now called 'macOS'.
2017-02-04Use less syscalls in `FileDesc::set_{nonblocking,cloexec}`Tobias Bucher-2/+17
Only set the flags if they differ from what the OS reported, use `FIONBIO` to atomically set the non-blocking IO flag on Linux.
2016-12-26std: Clamp max read/write sizes on UnixAlex Crichton-5/+22
Turns out that even though all these functions take a `size_t` they don't actually work that well with anything larger than the maximum value of `ssize_t`, the return value. Furthermore it looks like OSX rejects any read/write requests larger than `INT_MAX - 1`. Handle all these cases by just clamping the maximum size of a read/write on Unix to a platform-specific value. Closes #38590
2016-12-18Implement `fmt::Debug` for all structures in libstd.Corey Farwell-0/+1
Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-11-22Fuchsia support for std::process via liblaunchpad.Theodore DeRego-0/+2
2016-10-09Use `try_into` and move some functionsTobias Bucher-23/+30
2016-10-09Dynamically detect presence of `p{read,write}64` on AndroidTobias Bucher-17/+33
2016-10-09Implement reading and writing atomically at certain offsetsTobias Bucher-0/+25
These functions allow to read from and write to a file in one atomic action from multiple threads, avoiding the race between the seek and the read. The functions are named `{read,write}_at` on non-Windows (which don't change the file cursor), and `seek_{read,write}` on Windows (which change the file cursor).
2016-10-08Use less `size_t` casts in libstd since it's now defined as `usize`Tobias Bucher-3/+3
2016-09-25Haiku: Work around the lack of the FIOCLEX ioctlNiels Sascha Reedijk-2/+8
* Hand rebased from Niels original work on 1.9.0
2016-09-25Add support for the Haiku operating system on x86 and x86_64 machinesNiels Sascha Reedijk-2/+2
* Hand rebased from Niels original work on 1.9.0
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-2/+0
2016-06-24Bubble up the errors in `set_nonblocking` and `set_cloexec`Tobias Bucher-16/+15
2016-06-23Don't ignore errors of syscalls in std::sys::unix::fdTobias Bucher-4/+4
If any of these syscalls fail, it indicates a programmer error that should not be silently ignored.
2016-03-22try! -> ?Jorge Aparicio-4/+4
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-09std: Don't spawn threads in `wait_with_output`Alex Crichton-1/+16
Semantically there's actually no reason for us to spawn threads as part of the call to `wait_with_output`, and that's generally an incredibly heavyweight operation for just reading a few bytes (especially when stderr probably rarely has bytes!). An equivalent operation in terms of what's implemented today would be to just drain both pipes of all contents and then call `wait` on the child process itself. On Unix we can implement this through some convenient use of the `select` function, whereas on Windows we can make use of overlapped I/O. Note that on Windows this requires us to use named pipes instead of anonymous pipes, but they're semantically the same under the hood.
2016-03-08std: Funnel read_to_end through to one locationAlex Crichton-2/+21
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-10Fix half of emscripten's failing testsPierre Krieger-2/+2
2016-02-05std: When duplicating fds, skip extra set_cloexecAlex Crichton-6/+15
Similar to the previous commit, if `F_DUPFD_CLOEXEC` succeeds then there's no need for us to then call `set_cloexec` on platforms other than Linux. The bug mentioned of kernels not actually setting the `CLOEXEC` flag has only been repored on Linux, not elsewhere.
2016-02-04Auto merge of #31069 - sfackler:file-try-clone, r=alexcrichtonbors-0/+42
I have it set as stable right now under the rationale that it's extending an existing, stable API to another type in the "obvious" way. r? @alexcrichton cc @reem
2016-02-04Add File::try_cloneSteven Fackler-0/+42
2016-01-31Rename sunos to solarisNikita Baksalyar-2/+2
2016-01-31Add Illumos supportNikita Baksalyar-2/+2