9bcf557589
This commit re-organizes the io::native module slightly in order to have a working implementation of rtio::IoFactory which uses native implementations. The goal is to seamlessly multiplex among libuv/native implementations wherever necessary. Right now most of the native I/O is unimplemented, but we have existing bindings for file descriptors and processes which have been hooked up. What this means is that you can now invoke println!() from libstd with no local task, no local scheduler, and even without libuv. There's still plenty of work to do on the native I/O factory, but this is the first steps into making it an official portion of the standard library. I don't expect anyone to reach into io::native directly, but rather only std::io primitives will be used. Each std::io interface seamlessly falls back onto the native I/O implementation if the local scheduler doesn't have a libuv one (hurray trait ojects!)
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
#[macro_escape];
|
|
|
|
use std::fmt;
|
|
|
|
macro_rules! uverrln (
|
|
($($arg:tt)*) => ( {
|
|
format_args!(::macros::dumb_println, $($arg)*)
|
|
} )
|
|
)
|
|
|
|
// Some basic logging. Enabled by passing `--cfg uvdebug` to the libstd build.
|
|
macro_rules! uvdebug (
|
|
($($arg:tt)*) => ( {
|
|
if cfg!(uvdebug) {
|
|
uverrln!($($arg)*)
|
|
}
|
|
})
|
|
)
|
|
|
|
// get a handle for the current scheduler
|
|
macro_rules! get_handle_to_current_scheduler(
|
|
() => (do Local::borrow |sched: &mut Scheduler| { sched.make_handle() })
|
|
)
|
|
|
|
pub fn dumb_println(args: &fmt::Arguments) {
|
|
use std::io::native::file::FileDesc;
|
|
use std::io;
|
|
use std::libc;
|
|
let mut out = FileDesc::new(libc::STDERR_FILENO, false);
|
|
fmt::writeln(&mut out as &mut io::Writer, args);
|
|
}
|