2013-10-22 15:13:18 -07:00
|
|
|
// 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.
|
|
|
|
|
2014-04-27 22:05:41 -04:00
|
|
|
//! The implementation of `rtio` for libuv
|
|
|
|
|
2013-10-29 23:31:07 -07:00
|
|
|
use std::c_str::CString;
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
use std::mem;
|
2014-02-26 12:58:41 -05:00
|
|
|
use libc::c_int;
|
|
|
|
use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR,
|
2013-12-12 17:47:48 -08:00
|
|
|
S_IWUSR};
|
2014-02-26 12:58:41 -05:00
|
|
|
use libc;
|
2013-12-12 17:47:48 -08:00
|
|
|
use std::rt::rtio;
|
2014-06-04 00:00:59 -07:00
|
|
|
use std::rt::rtio::{ProcessConfig, IoFactory, EventLoop, IoResult};
|
2013-10-22 15:13:18 -07:00
|
|
|
|
2014-05-15 14:59:01 -07:00
|
|
|
#[cfg(test)] use std::rt::thread::Thread;
|
2013-10-22 15:13:18 -07:00
|
|
|
|
2013-12-12 17:47:48 -08:00
|
|
|
use super::{uv_error_to_io_error, Loop};
|
2013-10-22 15:13:18 -07:00
|
|
|
|
2013-12-12 17:47:48 -08:00
|
|
|
use addrinfo::GetAddrInfoRequest;
|
|
|
|
use async::AsyncWatcher;
|
|
|
|
use file::{FsRequest, FileWatcher};
|
|
|
|
use queue::QueuePool;
|
|
|
|
use homing::HomeHandle;
|
|
|
|
use idle::IdleWatcher;
|
|
|
|
use net::{TcpWatcher, TcpListener, UdpWatcher};
|
|
|
|
use pipe::{PipeWatcher, PipeListener};
|
|
|
|
use process::Process;
|
|
|
|
use signal::SignalWatcher;
|
|
|
|
use timer::TimerWatcher;
|
|
|
|
use tty::TtyWatcher;
|
|
|
|
use uvll;
|
2013-10-22 15:13:18 -07:00
|
|
|
|
|
|
|
// Obviously an Event Loop is always home.
|
|
|
|
pub struct UvEventLoop {
|
2014-03-28 10:27:14 -07:00
|
|
|
uvio: UvIoFactory
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UvEventLoop {
|
|
|
|
pub fn new() -> UvEventLoop {
|
2013-12-12 17:47:48 -08:00
|
|
|
let mut loop_ = Loop::new();
|
|
|
|
let handle_pool = QueuePool::new(&mut loop_);
|
2013-10-22 15:13:18 -07:00
|
|
|
UvEventLoop {
|
2013-12-12 17:47:48 -08:00
|
|
|
uvio: UvIoFactory {
|
|
|
|
loop_: loop_,
|
2013-12-15 00:56:29 -08:00
|
|
|
handle_pool: Some(handle_pool),
|
2013-12-12 17:47:48 -08:00
|
|
|
}
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for UvEventLoop {
|
|
|
|
fn drop(&mut self) {
|
2013-12-15 00:56:29 -08:00
|
|
|
// Must first destroy the pool of handles before we destroy the loop
|
|
|
|
// because otherwise the contained async handle will be destroyed after
|
2013-12-15 22:20:53 -08:00
|
|
|
// the loop is free'd (use-after-free). We also must free the uv handle
|
|
|
|
// after the loop has been closed because during the closing of the loop
|
|
|
|
// the handle is required to be used apparently.
|
2014-04-18 19:09:31 -07:00
|
|
|
//
|
|
|
|
// Lastly, after we've closed the pool of handles we pump the event loop
|
|
|
|
// one last time to run any closing callbacks to make sure the loop
|
|
|
|
// shuts down cleanly.
|
2013-12-15 22:20:53 -08:00
|
|
|
let handle = self.uvio.handle_pool.get_ref().handle();
|
2014-01-30 14:28:36 -08:00
|
|
|
drop(self.uvio.handle_pool.take());
|
2014-04-18 19:09:31 -07:00
|
|
|
self.run();
|
|
|
|
|
2013-12-12 17:47:48 -08:00
|
|
|
self.uvio.loop_.close();
|
2013-12-15 22:20:53 -08:00
|
|
|
unsafe { uvll::free_handle(handle) }
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-18 19:09:31 -07:00
|
|
|
impl EventLoop for UvEventLoop {
|
2013-10-22 15:13:18 -07:00
|
|
|
fn run(&mut self) {
|
2013-12-12 17:47:48 -08:00
|
|
|
self.uvio.loop_.run();
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2013-11-04 12:45:05 -08:00
|
|
|
fn callback(&mut self, f: proc()) {
|
2013-12-12 17:47:48 -08:00
|
|
|
IdleWatcher::onetime(&mut self.uvio.loop_, f);
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2014-06-14 11:03:34 -07:00
|
|
|
fn pausable_idle_callback(&mut self, cb: Box<rtio::Callback + Send>)
|
|
|
|
-> Box<rtio::PausableIdleCallback + Send> {
|
2014-05-05 18:56:44 -07:00
|
|
|
IdleWatcher::new(&mut self.uvio.loop_, cb)
|
2014-06-14 11:03:34 -07:00
|
|
|
as Box<rtio::PausableIdleCallback + Send>
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2014-06-14 11:03:34 -07:00
|
|
|
fn remote_callback(&mut self, f: Box<rtio::Callback + Send>)
|
|
|
|
-> Box<rtio::RemoteCallback + Send> {
|
2014-05-05 18:56:44 -07:00
|
|
|
box AsyncWatcher::new(&mut self.uvio.loop_, f) as
|
2014-06-14 11:03:34 -07:00
|
|
|
Box<rtio::RemoteCallback + Send>
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2013-12-12 17:47:48 -08:00
|
|
|
fn io<'a>(&'a mut self) -> Option<&'a mut rtio::IoFactory> {
|
|
|
|
let factory = &mut self.uvio as &mut rtio::IoFactory;
|
2013-12-05 17:37:02 -08:00
|
|
|
Some(factory)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-02-10 19:59:35 -08:00
|
|
|
|
|
|
|
fn has_active_io(&self) -> bool {
|
|
|
|
self.uvio.loop_.get_blockers() > 0
|
|
|
|
}
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_callback_run_once() {
|
2014-05-14 01:13:29 -07:00
|
|
|
Thread::start(proc() {
|
2013-10-22 15:13:18 -07:00
|
|
|
let mut event_loop = UvEventLoop::new();
|
|
|
|
let mut count = 0;
|
|
|
|
let count_ptr: *mut int = &mut count;
|
2014-01-26 22:57:42 -05:00
|
|
|
event_loop.callback(proc() {
|
2013-10-22 15:13:18 -07:00
|
|
|
unsafe { *count_ptr += 1 }
|
2014-01-26 22:57:42 -05:00
|
|
|
});
|
2013-10-22 15:13:18 -07:00
|
|
|
event_loop.run();
|
|
|
|
assert_eq!(count, 1);
|
2014-05-14 01:13:29 -07:00
|
|
|
}).join();
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2013-12-12 17:47:48 -08:00
|
|
|
pub struct UvIoFactory {
|
2014-03-28 10:27:14 -07:00
|
|
|
pub loop_: Loop,
|
2014-05-05 18:56:44 -07:00
|
|
|
handle_pool: Option<Box<QueuePool>>,
|
2013-12-12 17:47:48 -08:00
|
|
|
}
|
2013-10-22 15:13:18 -07:00
|
|
|
|
|
|
|
impl UvIoFactory {
|
2014-06-25 12:47:34 -07:00
|
|
|
pub fn uv_loop<'a>(&mut self) -> *mut uvll::uv_loop_t { self.loop_.handle }
|
2013-12-12 17:47:48 -08:00
|
|
|
|
|
|
|
pub fn make_handle(&mut self) -> HomeHandle {
|
2013-12-18 10:14:44 -08:00
|
|
|
// It's understood by the homing code that the "local id" is just the
|
|
|
|
// pointer of the local I/O factory cast to a uint.
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
let id: uint = unsafe { mem::transmute_copy(&self) };
|
2013-12-18 10:14:44 -08:00
|
|
|
HomeHandle::new(id, &mut **self.handle_pool.get_mut_ref())
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IoFactory for UvIoFactory {
|
|
|
|
// Connect to an address and return a new stream
|
|
|
|
// NB: This blocks the task waiting on the connection.
|
|
|
|
// It would probably be better to return a future
|
2014-06-04 00:00:59 -07:00
|
|
|
fn tcp_connect(&mut self, addr: rtio::SocketAddr, timeout: Option<u64>)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioTcpStream + Send>> {
|
2014-04-18 13:23:56 -07:00
|
|
|
match TcpWatcher::connect(self, addr, timeout) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(t) => Ok(box t as Box<rtio::RtioTcpStream + Send>),
|
2013-11-05 00:27:41 -08:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 00:00:59 -07:00
|
|
|
fn tcp_bind(&mut self, addr: rtio::SocketAddr)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioTcpListener + Send>> {
|
2013-12-12 17:47:48 -08:00
|
|
|
match TcpListener::bind(self, addr) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(t) => Ok(t as Box<rtio::RtioTcpListener + Send>),
|
2013-11-05 00:27:41 -08:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 00:00:59 -07:00
|
|
|
fn udp_bind(&mut self, addr: rtio::SocketAddr)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioUdpSocket + Send>> {
|
2013-12-12 17:47:48 -08:00
|
|
|
match UdpWatcher::bind(self, addr) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(u) => Ok(box u as Box<rtio::RtioUdpSocket + Send>),
|
2013-11-05 00:27:41 -08:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-14 11:03:34 -07:00
|
|
|
fn timer_init(&mut self) -> IoResult<Box<rtio::RtioTimer + Send>> {
|
|
|
|
Ok(TimerWatcher::new(self) as Box<rtio::RtioTimer + Send>)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2013-10-29 23:31:07 -07:00
|
|
|
fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
|
2014-06-04 00:00:59 -07:00
|
|
|
hint: Option<rtio::AddrinfoHint>)
|
|
|
|
-> IoResult<Vec<rtio::AddrinfoInfo>>
|
|
|
|
{
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = GetAddrInfoRequest::run(&self.loop_, host, servname, hint);
|
2013-11-04 22:52:33 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-29 23:31:07 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
fn fs_from_raw_fd(&mut self, fd: c_int, close: rtio::CloseBehavior)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> Box<rtio::RtioFileStream + Send> {
|
2014-05-05 18:56:44 -07:00
|
|
|
box FileWatcher::new(self, fd, close) as
|
2014-06-14 11:03:34 -07:00
|
|
|
Box<rtio::RtioFileStream + Send>
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_open(&mut self, path: &CString, fm: rtio::FileMode,
|
|
|
|
fa: rtio::FileAccess)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioFileStream + Send>>
|
2014-06-04 00:00:59 -07:00
|
|
|
{
|
2013-10-29 23:31:07 -07:00
|
|
|
let flags = match fm {
|
2014-06-04 00:00:59 -07:00
|
|
|
rtio::Open => 0,
|
|
|
|
rtio::Append => libc::O_APPEND,
|
|
|
|
rtio::Truncate => libc::O_TRUNC,
|
2013-10-22 15:13:18 -07:00
|
|
|
};
|
2013-10-29 23:31:07 -07:00
|
|
|
// Opening with a write permission must silently create the file.
|
|
|
|
let (flags, mode) = match fa {
|
2014-06-04 00:00:59 -07:00
|
|
|
rtio::Read => (flags | libc::O_RDONLY, 0),
|
|
|
|
rtio::Write => (flags | libc::O_WRONLY | libc::O_CREAT,
|
|
|
|
libc::S_IRUSR | libc::S_IWUSR),
|
|
|
|
rtio::ReadWrite => (flags | libc::O_RDWR | libc::O_CREAT,
|
|
|
|
libc::S_IRUSR | libc::S_IWUSR),
|
2013-10-22 15:13:18 -07:00
|
|
|
};
|
2013-11-04 21:08:25 -08:00
|
|
|
|
2013-12-12 17:47:48 -08:00
|
|
|
match FsRequest::open(self, path, flags as int, mode as int) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(fs) => Ok(box fs as Box<rtio::RtioFileStream + Send>),
|
2013-11-04 21:08:25 -08:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e))
|
|
|
|
}
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_unlink(&mut self, path: &CString) -> IoResult<()> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::unlink(&self.loop_, path);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_lstat(&mut self, path: &CString) -> IoResult<rtio::FileStat> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::lstat(&self.loop_, path);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_stat(&mut self, path: &CString) -> IoResult<rtio::FileStat> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::stat(&self.loop_, path);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_mkdir(&mut self, path: &CString, perm: uint) -> IoResult<()> {
|
|
|
|
let r = FsRequest::mkdir(&self.loop_, path, perm as c_int);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::rmdir(&self.loop_, path);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::rename(&self.loop_, path, to);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-25 16:50:08 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_chmod(&mut self, path: &CString, perm: uint) -> IoResult<()> {
|
|
|
|
let r = FsRequest::chmod(&self.loop_, path, perm as c_int);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-25 17:04:37 -07:00
|
|
|
}
|
2013-11-04 21:08:25 -08:00
|
|
|
fn fs_readdir(&mut self, path: &CString, flags: c_int)
|
2014-06-04 00:00:59 -07:00
|
|
|
-> IoResult<Vec<CString>>
|
2013-11-04 21:08:25 -08:00
|
|
|
{
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::readdir(&self.loop_, path, flags);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_link(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::link(&self.loop_, src, dst);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-29 23:31:07 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_symlink(&mut self, src: &CString, dst: &CString) -> IoResult<()> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::symlink(&self.loop_, src, dst);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-29 23:31:07 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) -> IoResult<()> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::chown(&self.loop_, path, uid, gid);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-29 23:31:07 -07:00
|
|
|
}
|
2014-06-04 00:00:59 -07:00
|
|
|
fn fs_readlink(&mut self, path: &CString) -> IoResult<CString> {
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::readlink(&self.loop_, path);
|
2013-11-04 21:08:25 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
2013-10-29 23:31:07 -07:00
|
|
|
}
|
2013-11-05 15:48:27 -08:00
|
|
|
fn fs_utime(&mut self, path: &CString, atime: u64, mtime: u64)
|
2014-06-04 00:00:59 -07:00
|
|
|
-> IoResult<()>
|
2013-11-05 15:48:27 -08:00
|
|
|
{
|
2013-12-12 17:47:48 -08:00
|
|
|
let r = FsRequest::utime(&self.loop_, path, atime, mtime);
|
2013-11-05 15:48:27 -08:00
|
|
|
r.map_err(uv_error_to_io_error)
|
|
|
|
}
|
2013-10-22 15:13:18 -07:00
|
|
|
|
2014-05-05 14:33:55 -07:00
|
|
|
fn spawn(&mut self, cfg: ProcessConfig)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<(Box<rtio::RtioProcess + Send>,
|
|
|
|
Vec<Option<Box<rtio::RtioPipe + Send>>>)>
|
2013-10-22 15:13:18 -07:00
|
|
|
{
|
2014-05-05 14:33:55 -07:00
|
|
|
match Process::spawn(self, cfg) {
|
2013-11-01 10:26:43 -07:00
|
|
|
Ok((p, io)) => {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok((p as Box<rtio::RtioProcess + Send>,
|
2014-05-05 18:56:44 -07:00
|
|
|
io.move_iter().map(|i| i.map(|p| {
|
2014-06-14 11:03:34 -07:00
|
|
|
box p as Box<rtio::RtioPipe + Send>
|
2014-05-05 18:56:44 -07:00
|
|
|
})).collect()))
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
2013-11-01 10:26:43 -07:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 00:00:59 -07:00
|
|
|
fn kill(&mut self, pid: libc::pid_t, signum: int) -> IoResult<()> {
|
2014-02-18 12:04:51 -08:00
|
|
|
Process::kill(pid, signum).map_err(uv_error_to_io_error)
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
fn unix_bind(&mut self, path: &CString)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioUnixListener + Send>> {
|
2013-12-12 17:47:48 -08:00
|
|
|
match PipeListener::bind(self, path) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(p) => Ok(p as Box<rtio::RtioUnixListener + Send>),
|
2013-10-22 15:13:18 -07:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
fn unix_connect(&mut self, path: &CString, timeout: Option<u64>)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioPipe + Send>> {
|
2014-04-22 18:38:59 -07:00
|
|
|
match PipeWatcher::connect(self, path, timeout) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(p) => Ok(box p as Box<rtio::RtioPipe + Send>),
|
2013-11-04 16:42:05 -08:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
2013-10-22 15:13:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tty_open(&mut self, fd: c_int, readable: bool)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioTTY + Send>> {
|
2013-12-12 17:47:48 -08:00
|
|
|
match TtyWatcher::new(self, fd, readable) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(tty) => Ok(box tty as Box<rtio::RtioTTY + Send>),
|
2013-10-22 15:13:18 -07:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
fn pipe_open(&mut self, fd: c_int)
|
2014-06-14 11:03:34 -07:00
|
|
|
-> IoResult<Box<rtio::RtioPipe + Send>>
|
2014-06-04 00:00:59 -07:00
|
|
|
{
|
2013-12-12 17:47:48 -08:00
|
|
|
match PipeWatcher::open(self, fd) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(s) => Ok(box s as Box<rtio::RtioPipe + Send>),
|
2013-10-22 15:13:18 -07:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-14 11:03:34 -07:00
|
|
|
fn signal(&mut self, signum: int, cb: Box<rtio::Callback + Send>)
|
|
|
|
-> IoResult<Box<rtio::RtioSignal + Send>>
|
2014-06-04 00:00:59 -07:00
|
|
|
{
|
|
|
|
match SignalWatcher::new(self, signum, cb) {
|
2014-06-14 11:03:34 -07:00
|
|
|
Ok(s) => Ok(s as Box<rtio::RtioSignal + Send>),
|
2013-10-22 15:13:18 -07:00
|
|
|
Err(e) => Err(uv_error_to_io_error(e)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|