From 4eb53360541baf3e6df36dc0f0766bc7c1c9f8be Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 17 Oct 2013 17:04:51 -0700 Subject: Move as much I/O as possible off of native::io 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. --- src/libstd/rt/util.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/libstd/rt/util.rs') diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 647d88c26f2..f15aa01db95 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -71,9 +71,18 @@ pub fn default_sched_threads() -> uint { pub fn dumb_println(args: &fmt::Arguments) { use rt::io::native::stdio::stderr; - use rt::io::Writer; + use rt::io::{Writer, io_error, ResourceUnavailable}; let mut out = stderr(); - fmt::writeln(&mut out as &mut Writer, args); + + let mut again = true; + do io_error::cond.trap(|e| { + again = e.kind == ResourceUnavailable; + }).inside { + while again { + again = false; + fmt::writeln(&mut out as &mut Writer, args); + } + } } pub fn abort(msg: &str) -> ! { -- cgit 1.4.1-3-g733a5