Implement native::IoFactory
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!)
This commit is contained in:
@@ -18,6 +18,7 @@ use cast;
|
||||
use rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausibleIdleCallback,
|
||||
Callback};
|
||||
use unstable::sync::Exclusive;
|
||||
use io::native;
|
||||
use util;
|
||||
|
||||
/// This is the only exported function from this module.
|
||||
@@ -30,7 +31,8 @@ struct BasicLoop {
|
||||
idle: Option<*mut BasicPausible>, // only one is allowed
|
||||
remotes: ~[(uint, ~Callback)],
|
||||
next_remote: uint,
|
||||
messages: Exclusive<~[Message]>
|
||||
messages: Exclusive<~[Message]>,
|
||||
io: ~IoFactory,
|
||||
}
|
||||
|
||||
enum Message { RunRemote(uint), RemoveRemote(uint) }
|
||||
@@ -54,6 +56,7 @@ impl BasicLoop {
|
||||
next_remote: 0,
|
||||
remotes: ~[],
|
||||
messages: Exclusive::new(~[]),
|
||||
io: ~native::IoFactory as ~IoFactory,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,8 +170,9 @@ impl EventLoop for BasicLoop {
|
||||
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
|
||||
}
|
||||
|
||||
/// This has no bindings for local I/O
|
||||
fn io<'a>(&'a mut self, _: &fn(&'a mut IoFactory)) {}
|
||||
fn io<'a>(&'a mut self, f: &fn(&'a mut IoFactory)) {
|
||||
f(self.io)
|
||||
}
|
||||
}
|
||||
|
||||
struct BasicRemote {
|
||||
|
||||
Reference in New Issue
Block a user