about summary refs log tree commit diff
path: root/src/libstd/rt/io
AgeCommit message (Collapse)AuthorLines
2013-11-11Move std::rt::io to std::ioAlex Crichton-8632/+0
2013-11-11auto merge of #10424 : alexcrichton/rust/optimize-buffered, r=brsonbors-2/+13
I was benchmarking rust-http recently, and I saw that 50% of its time was spent creating buffered readers/writers. Albeit rust-http wasn't using std::rt::io::buffered, but the same idea applies here. It's much cheaper to malloc a large region and not initialize it than to set it all to 0. Buffered readers/writers never use uninitialized data, and their internal buffers are encapsulated, so any usage of uninitialized slots are an implementation bug in the readers/writers.
2013-11-12Implemented a ProcessExit enum and helper methods to std::rt::io::process ↵Matthew Iselin-1/+37
for getting process termination status, or the signal that terminated a process. A test has been added to rtio-processes.rs to ensure signal termination is picked up correctly.
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-44/+1
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-11-11Optimize creation of buffered readers/writersAlex Crichton-2/+13
I was benchmarking rust-http recently, and I saw that 50% of its time was spent creating buffered readers/writers. Albeit rust-http wasn't using std::rt::io::buffered, but the same idea applies here. It's much cheaper to malloc a large region and not initialize it than to set it all to 0. Buffered readers/writers never use uninitialized data, and their internal buffers are encapsulated, so any usage of uninitialized slots are an implementation bug in the readers/writers.
2013-11-11auto merge of #10394 : yichoi/rust/make_check_pass_android, r=brsonbors-3/+4
To enable test on android bot #9120 some tests are disabled and can be fixed further.
2013-11-11Clean lint on test buildCorey Richardson-2/+0
2013-11-10Fix usage of libuv for windowsAlex Crichton-7/+13
2013-11-10Another round of test fixes from previous commitsAlex Crichton-21/+21
2013-11-10Fall back from uv tty instances more aggressivelyAlex Crichton-4/+2
It appears that uv's support for interacting with a stdio stream as a tty when it's actually a pipe is pretty problematic. To get around this, promote a check to see if the stream is a tty to the top of the tty constructor, and bail out quickly if it's not identified as a tty. Closes #10237
2013-11-10Assorted test fixes and merge conflictsAlex Crichton-4/+5
2013-11-10Add bindings to uv's utime functionAlex Crichton-4/+45
This exposes the ability to change the modification and access times on a file. Closes #10266
2013-11-10temporarily disable tests on android and tagging issue number #10378Young-il Choi-3/+3
2013-11-10disable tests on android since tcp/ip permission cannot be acquired without ↵Young-il Choi-0/+1
help of apk
2013-11-04Stop extra buffering when stdout isn't a ttyAlex Crichton-13/+5
Right now if you're running a program with its output piped to some location and the program decides to go awry, when you kill the program via some signal none of the program's last 4K of output will get printed to the screen. In theory the solution to this would be to register a signal handler as part of the runtime which then flushes the output stream. I believe that the current behavior is far enough from what's expected that we shouldn't be providing this sort of "super buffering" by default when stdout isn't attached to a tty.
2013-11-04Move io::file to io::fs and fns out of FileAlex Crichton-300/+349
This renames the `file` module to `fs` because that more accurately describes its current purpose (manipulating the filesystem, not just files). Additionally, this adds an UnstableFileStat structure as a nested structure of FileStat to signify that the fields should not be depended on. The structure is currently flagged with #[unstable], but it's unlikely that it has much meaning. Closes #10241
2013-11-03Fill out the remaining functionality in io::fileAlex Crichton-570/+901
This adds bindings to the remaining functions provided by libuv, all of which are useful operations on files which need to get exposed somehow. Some highlights: * Dropped `FileReader` and `FileWriter` and `FileStream` for one `File` type * Moved all file-related methods to be static methods under `File` * All directory related methods are still top-level functions * Created `io::FilePermission` types (backed by u32) that are what you'd expect * Created `io::FileType` and refactored `FileStat` to use FileType and FilePermission * Removed the expanding matrix of `FileMode` operations. The mode of reading a file will not have the O_CREAT flag, but a write mode will always have the O_CREAT flag. Closes #10130 Closes #10131 Closes #10121
2013-11-03Remove all blocking std::os blocking functionsAlex Crichton-413/+895
This commit moves all thread-blocking I/O functions from the std::os module. Their replacements can be found in either std::rt::io::file or in a hidden "old_os" module inside of native::file. I didn't want to outright delete these functions because they have a lot of special casing learned over time for each OS/platform, and I imagine that these will someday get integrated into a blocking implementation of IoFactory. For now, they're moved to a private module to prevent bitrot and still have tests to ensure that they work. I've also expanded the extensions to a few more methods defined on Path, most of which were previously defined in std::os but now have non-thread-blocking implementations as part of using the current IoFactory. The api of io::file is in flux, but I plan on changing it in the next commit as well. Closes #10057
2013-11-01auto merge of #10119 : Kimundi/rust/option_and_generic, r=alexcrichtonbors-1/+1
This takes the last reforms on the `Option` type and applies them to `Result` too. For that, I reordered and grouped the functions in both modules, and also did some refactorings: - Added `as_ref` and `as_mut` adapters to `Result`. - Renamed `Result::map_move` to `Result::map` (same for `_err` variant), deleted other map functions. - Made the `.expect()` methods be generic over anything you can fail with. - Updated some doc comments to the line doc comment style - Cleaned up and extended standard trait implementations on `Option` and `Result` - Removed legacy implementations in the `option` and `result` module
2013-11-01auto merge of #10218 : alexcrichton/rust/stdio-flush-safe, r=cmrbors-14/+27
The previous method was unsound because you could very easily create two mutable pointers which alias the same location (not sound behavior). This hides the function which does so and then exports an explicit flush() function (with documentation about how it works).
2013-11-01Reordered the methods in std::Option and std::ResultMarvin Löbel-1/+1
Cleaned up the source in a few places Renamed `map_move` to `map`, removed other `map` methods Added `as_ref` and `as_mut` adapters to `Result` Added `fmt::Default` impl
2013-10-31Provide a sound method of flushing stdoutAlex Crichton-14/+27
The previous method was unsound because you could very easily create two mutable pointers which alias the same location (not sound behavior). This hides the function which does so and then exports an explicit flush() function (with documentation about how it works).
2013-10-31libstd: Remove mocks.Patrick Walton-181/+131
2013-10-30Make Writer::flush a no-op default methodAlex Crichton-30/+6
Closes #9126
2013-10-30auto merge of #9613 : jld/rust/enum-discrim-size.r0, r=alexcrichtonbors-0/+1
Allows an enum with a discriminant to use any of the primitive integer types to store it. By default the smallest usable type is chosen, but this can be overridden with an attribute: `#[repr(int)]` etc., or `#[repr(C)]` to match the target's C ABI for the equivalent C enum. Also adds a lint pass for using non-FFI safe enums in extern declarations, checks that specified discriminants can be stored in the specified type if any, and fixes assorted code that was assuming int.
2013-10-29auto merge of #10132 : pcwalton/rust/proc, r=pcwaltonbors-7/+9
the feature gate for `once fn` if used with the `~` sigil. r? @brson
2013-10-29librustc: Implement the `proc` type as sugar for `~once fn` and `proc`Patrick Walton-7/+9
notation for closures, and disable the feature gate for `once fn` if used with the `~` sigil.
2013-10-29auto merge of #10058 : alexcrichton/rust/uv-crate, r=brsonbors-2/+4
This is one of the final steps needed to complete #9128. It still needs a little bit of polish before closing that issue, but it's in a pretty much "done" state now. The idea here is that the entire event loop implementation using libuv is now housed in `librustuv` as a completely separate library. This library is then injected (via `extern mod rustv`) into executable builds (similarly to how libstd is injected, tunable via `#[no_uv]`) to bring in the "rust blessed event loop implementation." Codegen-wise, there is a new `event_loop_factory` language item which is tagged on a function with 0 arguments returning `~EventLoop`. This function's symbol is then inserted into the crate map for an executable crate, and if there is no definition of the `event_loop_factory` language item then the value is null. What this means is that embedding rust as a library in another language just got a little harder. Libraries don't have crate maps, which means that there's no way to find the event loop implementation to spin up the runtime. That being said, it's always possible to build the runtime manually. This request also makes more runtime components public which should probably be public anyway. This new public-ness should allow custom scheduler setups everywhere regardless of whether you follow the `rt::start `path.
2013-10-29Add repr attributes in various places that need them.Jed Davis-0/+1
2013-10-29Move rust's uv implementation to its own crateAlex Crichton-2/+4
There are a few reasons that this is a desirable move to take: 1. Proof of concept that a third party event loop is possible 2. Clear separation of responsibility between rt::io and the uv-backend 3. Enforce in the future that the event loop is "pluggable" and replacable Here's a quick summary of the points of this pull request which make this possible: * Two new lang items were introduced: event_loop, and event_loop_factory. The idea of a "factory" is to define a function which can be called with no arguments and will return the new event loop as a trait object. This factory is emitted to the crate map when building an executable. The factory doesn't have to exist, and when it doesn't then an empty slot is in the crate map and a basic event loop with no I/O support is provided to the runtime. * When building an executable, then the rustuv crate will be linked by default (providing a default implementation of the event loop) via a similar method to injecting a dependency on libstd. This is currently the only location where the rustuv crate is ever linked. * There is a new #[no_uv] attribute (implied by #[no_std]) which denies implicitly linking to rustuv by default Closes #5019
2013-10-28auto merge of #10133 : alexcrichton/rust/another-error, r=thestingerbors-1/+2
This cropped up on the bsd bot, and if it's an error that gets thrown then it's fine to just whitelist another type of error in the test.
2013-10-28Handle another possible error in a unix pipe testAlex Crichton-1/+2
This cropped up on the bsd bot, and if it's an error that gets thrown then it's fine to just whitelist another type of error in the test.
2013-10-28Remove the extension traits for Readers/WritersAlex Crichton-606/+487
These methods are all excellent candidates for default methods, so there's no need to require extra imports of various traits.
2013-10-28auto merge of #10093 : alexcrichton/rust/issue-8811, r=pcwaltonbors-6/+12
Closes #8811
2013-10-28auto merge of #10083 : alexcrichton/rust/timer-port, r=pcwaltonbors-4/+131
In addition to being able to sleep the current task, timers should be able to create ports which get notified after a period of time. Closes #10014
2013-10-28Allow fail messages to be caught, and introduce the Any traitMarvin Löbel-3/+4
Some code cleanup, sorting of import blocks Removed std::unstable::UnsafeArc's use of Either Added run-fail tests for the new FailWithCause impls Changed future_result and try to return Result<(), ~Any>. - Internally, there is an enum of possible fail messages passend around. - In case of linked failure or a string message, the ~Any gets lazyly allocated in future_results recv method. - For that, future result now returns a wrapper around a Port. - Moved and renamed task::TaskResult into rt::task::UnwindResult and made it an internal enum. - Introduced a replacement typedef `type TaskResult = Result<(), ~Any>`.
2013-10-26Fix a typo in a rt::io::signal testAlex Crichton-1/+1
It was pretty much a miracle that these tests were ever passing. They would never have passed in the single threaded case because only one sigint in the tests is ever generated, but when run in parallel two sigints will be generated.
2013-10-26Implement another error code found on windows.Alex Crichton-6/+12
Closes #8811
2013-10-25Enhance timers to create portsAlex Crichton-4/+131
In addition to being able to sleep the current task, timers should be able to create ports which get notified after a period of time. Closes #10014
2013-10-25auto merge of #10060 : alexcrichton/rust/cached-stdout, r=brsonbors-20/+108
Almost all languages provide some form of buffering of the stdout stream, and this commit adds this feature for rust. A handle to stdout is lazily initialized in the Task structure as a buffered owned Writer trait object. The buffer behavior depends on where stdout is directed to. Like C, this line-buffers the stream when the output goes to a terminal (flushes on newlines), and also like C this uses a fixed-size buffer when output is not directed at a terminal. We may decide the fixed-size buffering is overkill, but it certainly does reduce write syscall counts when piping output elsewhere. This is a *huge* benefit to any code using logging macros or the printing macros. Formatting emits calls to `write` very frequently, and to have each of them backed by a write syscall was very expensive. In a local benchmark of printing 10000 lines of "what" to stdout, I got the following timings: when | terminal | redirected ----------|---------------|-------- before | 0.575s | 0.525s after | 0.197s | 0.013s C | 0.019s | 0.004s I can also confirm that we're buffering the output appropriately in both situtations. We're still far slower than C, but I believe much of that has to do with the "homing" that all tasks due, we're still performing an order of magnitude more write syscalls than C does.
2013-10-25Cache and buffer stdout per-task for printingAlex Crichton-20/+108
Almost all languages provide some form of buffering of the stdout stream, and this commit adds this feature for rust. A handle to stdout is lazily initialized in the Task structure as a buffered owned Writer trait object. The buffer behavior depends on where stdout is directed to. Like C, this line-buffers the stream when the output goes to a terminal (flushes on newlines), and also like C this uses a fixed-size buffer when output is not directed at a terminal. We may decide the fixed-size buffering is overkill, but it certainly does reduce write syscall counts when piping output elsewhere. This is a *huge* benefit to any code using logging macros or the printing macros. Formatting emits calls to `write` very frequently, and to have each of them backed by a write syscall was very expensive. In a local benchmark of printing 10000 lines of "what" to stdout, I got the following timings: when | terminal | redirected ---------------------------------- before | 0.575s | 0.525s after | 0.197s | 0.013s C | 0.019s | 0.004s I can also confirm that we're buffering the output appropriately in both situtations. We're still far slower than C, but I believe much of that has to do with the "homing" that all tasks due, we're still performing an order of magnitude more write syscalls than C does.
2013-10-24Implement a basic event loop built on LittleLockAlex Crichton-0/+7
It's not guaranteed that there will always be an event loop to run, and this implementation will serve as an incredibly basic one which does not provide any I/O, but allows the scheduler to still run. cc #9128
2013-10-24Another round of test fixes and merge conflictsAlex Crichton-43/+115
2013-10-24Bring io::signal up to date with changes to rt::rtioAlex Crichton-35/+58
2013-10-24wrapping libuv signal for use in RustDo Nhat Minh-0/+193
descriptive names easier-to-use api reorganize and document
2013-10-24Fixing some tests, adding some pipesAlex Crichton-1/+33
This adds constructors to pipe streams in the new runtime to take ownership of file descriptors, and also fixes a few tests relating to the std::run changes (new errors are raised on io_error and one test is xfail'd).
2013-10-24Migrate std::run to libuv processesAlex Crichton-1/+1
2013-10-24Remove std::io once and for all!Alex Crichton-1/+82
2013-10-24Remove std::io from ebmlAlex Crichton-24/+62
2013-10-24Test fixes and merge conflictsAlex Crichton-5/+20