about summary refs log tree commit diff
path: root/src/libstd/sys/unix/fd.rs
AgeCommit message (Collapse)AuthorLines
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
2015-12-08Fix a typo in `fd.rs`. Fixes #30231.Richard Diamond-2/+2
2015-11-09std: Migrate to the new libcAlex Crichton-4/+3
* 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-10-28Port the standard crates to PNaCl/NaCl.Richard Diamond-0/+9
2015-08-11Register new snapshotsAlex Crichton-3/+0
* Lots of core prelude imports removed * Makefile support for MSVC env vars and Rust crates removed * Makefile support for morestack removed
2015-08-03syntax: Implement #![no_core]Alex Crichton-1/+2
This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The `#![no_std]` attribute now injects `extern crate core` at the top of the crate as well as the libcore prelude into all modules (in the same manner as the standard library's prelude). The `#![no_core]` attribute disables both std and core injection. [rfc]: https://github.com/rust-lang/rfcs/pull/1184
2015-05-07std: Mark `mem::forget` as a safe functionAlex Crichton-1/+1
This commit is an implementation of [RFC 1066][rfc] where the conclusion was that leaking a value is a safe operation in Rust code, so updating the signature of this function follows suit. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1066-safe-mem-forget.md Closes #25186
2015-04-13pluralize doc comment verbs and add missing periodsAndrew Paseltiner-1/+1
2015-04-10std: Unconditionally close all file descriptorsAlex Crichton-16/+6
The logic for only closing file descriptors >= 3 was inherited from quite some time ago and ends up meaning that some internal APIs are less consistent than they should be. By unconditionally closing everything entering a `FileDesc` we ensure that we're consistent in our behavior as well as robustly handling the stdio case.
2015-04-09std: Set CLOEXEC for all fds opened on unixAlex Crichton-0/+15
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-12std: Remove #[allow] directives in sys modulesAlex Crichton-1/+0
These were suppressing lots of interesting warnings! Turns out there was also quite a bit of dead code.
2015-02-11std: Add a `net` module for TCP/UDPAlex Crichton-2/+5
This commit is an implementation of [RFC 807][rfc] which adds a `std::net` module for basic neworking based on top of `std::io`. This module serves as a replacement for the `std::old_io::net` module and networking primitives in `old_io`. [rfc]: fillmein The major focus of this redesign is to cut back on the level of abstraction to the point that each of the networking types is just a bare socket. To this end functionality such as timeouts and cloning has been removed (although cloning can be done through `duplicate`, it may just yield an error). With this `net` module comes a new implementation of `SocketAddr` and `IpAddr`. This work is entirely based on #20785 and the only changes were to alter the in-memory representation to match the `libc`-expected variants and to move from public fields to accessors.
2015-02-09std: Add a new `fs` moduleAlex Crichton-0/+70
This commit is an implementation of [RFC 739][rfc] which adds a new `std::fs` module to the standard library. This module provides much of the same functionality as `std::old_io::fs` but it has many tweaked APIs as well as uses the new `std::path` module. [rfc]: https://github.com/rust-lang/rfcs/pull/739