about summary refs log tree commit diff
path: root/src/libstd/rt/io/stdio.rs
AgeCommit message (Collapse)AuthorLines
2013-11-11Move std::rt::io to std::ioAlex Crichton-321/+0
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-2/+0
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-10Fix usage of libuv for windowsAlex Crichton-1/+11
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-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-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-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-30Make Writer::flush a no-op default methodAlex Crichton-2/+0
Closes #9126
2013-10-25Cache and buffer stdout per-task for printingAlex Crichton-13/+55
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-24Another round of test fixes and merge conflictsAlex Crichton-34/+99
2013-10-24Move stdin to using libuv's pipes instead of a ttyAlex Crichton-24/+12
I was seeing a lot of weird behavior with stdin behaving as a tty, and it doesn't really quite make sense, so instead this moves to using libuv's pipes instead (which make more sense for stdin specifically). This prevents piping input to rustc hanging forever.
2013-10-24Move as much I/O as possible off of native::ioAlex Crichton-24/+44
When uv's TTY I/O is used for the stdio streams, the file descriptors are put into a non-blocking mode. This means that other concurrent writes to the same stream can fail with EAGAIN or EWOULDBLOCK. By all I/O to event-loop I/O, we avoid this error. There is one location which cannot move, which is the runtime's dumb_println function. This was implemented to handle the EAGAIN and EWOULDBLOCK errors and simply retry again and again.
2013-10-24Don't attempt to export uv functions directlyAlex Crichton-14/+0
2013-10-24Remove IoFactoryObject for ~IoFactoryAlex Crichton-17/+28
This involved changing a fair amount of code, rooted in how we access the local IoFactory instance. I added a helper method to the rtio module to access the optional local IoFactory. This is different than before in which it was assumed that a local IoFactory was *always* present. Now, a separate io_error is raised when an IoFactory is not present, yet I/O is requested.
2013-10-24Migrate Rtio objects to true trait objectsAlex Crichton-3/+3
This moves as many as I could over to ~Trait instead of ~Typedef. The only remaining one is the IoFactoryObject which should be coming soon...
2013-10-24Move rt::io::stdio from FileStream to a TTYAlex Crichton-14/+88
We get a little more functionality from libuv for these kinds of streams (things like terminal dimentions), and it also appears to more gracefully handle the stream being a window. Beforehand, if you used stdio and hit CTRL+d on a process, libuv would continually return 0-length successful reads instead of interpreting that the stream was closed. I was hoping to be able to write tests for this, but currently the testing infrastructure doesn't allow tests with a stdin and a stdout, but this has been manually tested! (not that it means much)
2013-10-20Don't allocate a string when calling printlnAlex Crichton-1/+18
Instead use format_args! to pass around a struct to pass along into std::fmt
2013-10-10Implement rt::io::stdioAlex Crichton-24/+81
Additionally, this moves the prelude imports of print/println from std::io to std::rt::io. Closes #6846
2013-09-30std: Remove usage of fmt!Alex Crichton-11/+11
2013-06-13automated whitespace fixesDaniel Micay-1/+0
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-0/+53
This only changes the directory names; it does not change the "real" metadata names.