Skip to content

Commit b89e1c0

Browse files
committed
Implement process bindings to libuv
Closes #6436
1 parent ed20425 commit b89e1c0

File tree

25 files changed

+1082
-1023
lines changed

25 files changed

+1082
-1023
lines changed

mk/rt.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,10 @@ $(LIBUV_MAKEFILE): $(LIBUV_GYP)
271271
$(foreach stage,$(STAGES), \
272272
$(foreach target,$(CFG_TARGET_TRIPLES), \
273273
$(eval $(call DEF_RUNTIME_TARGETS,$(target),$(stage)))))
274+
275+
$(LIBUV_GYP):
276+
mkdir -p $(S)src/libuv/build
277+
git clone https://git.chromium.org/external/gyp.git $(S)src/libuv/build/gyp
278+
279+
$(LIBUV_MAKEFILE): $(LIBUV_GYP)
280+
(cd $(S)src/libuv/ && ./gyp_uv -f make)

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ pub fn run(lib_path: &str,
5454
in_fd: None,
5555
out_fd: None,
5656
err_fd: None
57-
});
57+
}).unwrap();
5858

5959
for input in input.iter() {
60-
proc.input().write_str(*input);
60+
proc.input().write(input.as_bytes());
6161
}
6262
let output = proc.finish_with_output();
6363

src/compiletest/runtest.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,16 @@ use procsrv;
2020
use util;
2121
use util::logv;
2222

23-
use std::cell::Cell;
2423
use std::io;
2524
use std::os;
2625
use std::str;
27-
use std::task::{spawn_sched, SingleThreaded};
2826
use std::vec;
29-
use std::unstable::running_on_valgrind;
3027

3128
use extra::test::MetricMap;
3229

3330
pub fn run(config: config, testfile: ~str) {
34-
let config = Cell::new(config);
35-
let testfile = Cell::new(testfile);
36-
// FIXME #6436: Creating another thread to run the test because this
37-
// is going to call waitpid. The new scheduler has some strange
38-
// interaction between the blocking tasks and 'friend' schedulers
39-
// that destroys parallelism if we let normal schedulers block.
40-
// It should be possible to remove this spawn once std::run is
41-
// rewritten to be non-blocking.
42-
//
43-
// We do _not_ create another thread if we're running on V because
44-
// it serializes all threads anyways.
45-
if running_on_valgrind() {
46-
let config = config.take();
47-
let testfile = testfile.take();
48-
let mut _mm = MetricMap::new();
49-
run_metrics(config, testfile, &mut _mm);
50-
} else {
51-
do spawn_sched(SingleThreaded) {
52-
let config = config.take();
53-
let testfile = testfile.take();
54-
let mut _mm = MetricMap::new();
55-
run_metrics(config, testfile, &mut _mm);
56-
}
57-
}
31+
let mut _mm = MetricMap::new();
32+
run_metrics(config, testfile, &mut _mm);
5833
}
5934

6035
pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) {

src/librustdoc/markdown_writer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ fn pandoc_writer(
104104
];
105105
106106
do generic_writer |markdown| {
107-
use std::io::WriterUtil;
108-
109107
debug!("pandoc cmd: %s", pandoc_cmd);
110108
debug!("pandoc args: %s", pandoc_args.connect(" "));
111109

112-
let mut proc = run::Process::new(pandoc_cmd, pandoc_args, run::ProcessOptions::new());
110+
let proc = run::Process::new(pandoc_cmd, pandoc_args,
111+
run::ProcessOptions::new());
112+
let mut proc = proc.unwrap();
113113

114-
proc.input().write_str(markdown);
114+
proc.input().write(markdown.as_bytes());
115115
let output = proc.finish_with_output();
116116

117117
debug!("pandoc result: %i", output.status);

src/librustpkg/source_control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn git_clone_general(source: &str, target: &Path, v: &Version) -> bool {
8989

9090
fn process_output_in_cwd(prog: &str, args: &[~str], cwd: &Path) -> ProcessOutput {
9191
let mut prog = Process::new(prog, args, ProcessOptions{ dir: Some(cwd)
92-
,..ProcessOptions::new()});
92+
,..ProcessOptions::new()}).unwrap();
9393
prog.finish_with_output()
9494
}
9595

src/librustpkg/tests.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ fn mk_temp_workspace(short_name: &Path, version: &Version) -> Path {
112112

113113
fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &str) {
114114
let cwd = (*cwd).clone();
115-
let mut prog = run::Process::new("git", args, run::ProcessOptions {
115+
let prog = run::Process::new("git", args, run::ProcessOptions {
116116
env: env,
117117
dir: Some(&cwd),
118118
in_fd: None,
119119
out_fd: None,
120120
err_fd: None
121121
});
122+
let mut prog = prog.unwrap();
122123
let rslt = prog.finish_with_output();
123124
if rslt.status != 0 {
124125
fail!("%s [git returned %?, output = %s, error = %s]", err_msg,
@@ -226,7 +227,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
226227
in_fd: None,
227228
out_fd: None,
228229
err_fd: None
229-
});
230+
}).unwrap();
230231
let output = prog.finish_with_output();
231232
debug!("Output from command %s with args %? was %s {%s}[%?]",
232233
cmd, args, str::from_bytes(output.output),
@@ -1024,16 +1025,17 @@ fn test_extern_mod() {
10241025
test_sysroot().to_str(),
10251026
exec_file.to_str());
10261027
1027-
let mut prog = run::Process::new(rustc.to_str(), [main_file.to_str(),
1028-
~"--sysroot", test_sysroot().to_str(),
1029-
~"-o", exec_file.to_str()],
1030-
run::ProcessOptions {
1028+
let prog = run::Process::new(rustc.to_str(), [main_file.to_str(),
1029+
~"--sysroot", test_sysroot().to_str(),
1030+
~"-o", exec_file.to_str()],
1031+
run::ProcessOptions {
10311032
env: env,
10321033
dir: Some(&dir),
10331034
in_fd: None,
10341035
out_fd: None,
10351036
err_fd: None
10361037
});
1038+
let mut prog = prog.unwrap();
10371039
let outp = prog.finish_with_output();
10381040
if outp.status != 0 {
10391041
fail!("output was %s, error was %s",

src/libstd/rt/io/file.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ pub struct FileStream {
7171
last_nread: int,
7272
}
7373

74-
impl FileStream {
75-
}
76-
7774
impl Reader for FileStream {
7875
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
7976
match self.fd.read(buf) {

src/libstd/rt/io/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ pub use self::extensions::WriterByteConversions;
268268
/// Synchronous, non-blocking file I/O.
269269
pub mod file;
270270

271+
/// Synchronous, in-memory I/O.
272+
pub mod pipe;
273+
271274
/// Synchronous, non-blocking network I/O.
272275
pub mod net {
273276
pub mod tcp;

src/libstd/rt/io/net/tcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rt::io::{io_error, read_error, EndOfFile};
1616
use rt::rtio::{IoFactory, IoFactoryObject,
1717
RtioSocket, RtioTcpListener,
1818
RtioTcpListenerObject, RtioTcpStream,
19-
RtioTcpStreamObject};
19+
RtioTcpStreamObject, RtioStream};
2020
use rt::local::Local;
2121

2222
pub struct TcpStream(~RtioTcpStreamObject);
@@ -69,7 +69,7 @@ impl TcpStream {
6969

7070
impl Reader for TcpStream {
7171
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
72-
match (**self).read(buf) {
72+
match (***self).read(buf) {
7373
Ok(read) => Some(read),
7474
Err(ioerr) => {
7575
// EOF is indicated by returning None
@@ -86,7 +86,7 @@ impl Reader for TcpStream {
8686

8787
impl Writer for TcpStream {
8888
fn write(&mut self, buf: &[u8]) {
89-
match (**self).write(buf) {
89+
match (***self).write(buf) {
9090
Ok(_) => (),
9191
Err(ioerr) => io_error::cond.raise(ioerr),
9292
}

src/libstd/rt/io/pipe.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Synchronous, in-memory pipes.
12+
//!
13+
//! Currently these aren't particularly useful, there only exists bindings
14+
//! enough so that pipes can be created to child processes.
15+
16+
use prelude::*;
17+
use super::{Reader, Writer};
18+
use rt::io::{io_error, read_error, EndOfFile};
19+
use rt::local::Local;
20+
use rt::rtio::{RtioPipeObject, RtioStream, IoFactoryObject, IoFactory};
21+
use rt::uv::pipe;
22+
23+
pub struct PipeStream(~RtioPipeObject);
24+
25+
impl PipeStream {
26+
/// Creates a new pipe initialized, but not bound to any particular
27+
/// source/destination
28+
pub fn new() -> Option<PipeStream> {
29+
let pipe = unsafe {
30+
let io: *mut IoFactoryObject = Local::unsafe_borrow();
31+
(*io).pipe_init(false)
32+
};
33+
match pipe {
34+
Ok(p) => Some(PipeStream(p)),
35+
Err(ioerr) => {
36+
io_error::cond.raise(ioerr);
37+
None
38+
}
39+
}
40+
}
41+
42+
/// Extracts the underlying libuv pipe to be bound to another source.
43+
pub fn uv_pipe(&self) -> pipe::Pipe {
44+
// Did someone say multiple layers of indirection?
45+
(**self).uv_pipe()
46+
}
47+
}
48+
49+
impl Reader for PipeStream {
50+
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
51+
match (***self).read(buf) {
52+
Ok(read) => Some(read),
53+
Err(ioerr) => {
54+
// EOF is indicated by returning None
55+
if ioerr.kind != EndOfFile {
56+
read_error::cond.raise(ioerr);
57+
}
58+
return None;
59+
}
60+
}
61+
}
62+
63+
fn eof(&mut self) -> bool { fail!() }
64+
}
65+
66+
impl Writer for PipeStream {
67+
fn write(&mut self, buf: &[u8]) {
68+
match (***self).write(buf) {
69+
Ok(_) => (),
70+
Err(ioerr) => {
71+
io_error::cond.raise(ioerr);
72+
}
73+
}
74+
}
75+
76+
fn flush(&mut self) { fail!() }
77+
}

src/libstd/rt/rtio.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use libc;
1112
use option::*;
1213
use result::*;
1314
use libc::c_int;
1415

1516
use rt::io::IoError;
1617
use super::io::net::ip::{IpAddr, SocketAddr};
18+
use rt::uv;
1719
use rt::uv::uvio;
1820
use path::Path;
1921
use super::io::support::PathLike;
@@ -30,6 +32,9 @@ pub type RtioTcpListenerObject = uvio::UvTcpListener;
3032
pub type RtioUdpSocketObject = uvio::UvUdpSocket;
3133
pub type RtioTimerObject = uvio::UvTimer;
3234
pub type PausibleIdleCallback = uvio::UvPausibleIdleCallback;
35+
pub type RtioPipeObject = uvio::UvPipeStream;
36+
pub type RtioProcessObject = uvio::UvProcess;
37+
pub type RtioProcessConfig<'self> = uv::process::Config<'self>;
3338

3439
pub trait EventLoop {
3540
fn run(&mut self);
@@ -72,6 +77,13 @@ pub trait IoFactory {
7277
fn fs_open<P: PathLike>(&mut self, path: &P, fm: FileMode, fa: FileAccess)
7378
-> Result<~RtioFileStream, IoError>;
7479
fn fs_unlink<P: PathLike>(&mut self, path: &P) -> Result<(), IoError>;
80+
fn pipe_init(&mut self, ipc: bool) -> Result<~RtioPipeObject, IoError>;
81+
fn spawn(&mut self, config: &RtioProcessConfig) -> Result<~RtioProcessObject, IoError>;
82+
}
83+
84+
pub trait RtioStream {
85+
fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError>;
86+
fn write(&mut self, buf: &[u8]) -> Result<(), IoError>;
7587
}
7688

7789
pub trait RtioTcpListener : RtioSocket {
@@ -80,9 +92,7 @@ pub trait RtioTcpListener : RtioSocket {
8092
fn dont_accept_simultaneously(&mut self) -> Result<(), IoError>;
8193
}
8294

83-
pub trait RtioTcpStream : RtioSocket {
84-
fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError>;
85-
fn write(&mut self, buf: &[u8]) -> Result<(), IoError>;
95+
pub trait RtioTcpStream : RtioSocket + RtioStream {
8696
fn peer_name(&mut self) -> Result<SocketAddr, IoError>;
8797
fn control_congestion(&mut self) -> Result<(), IoError>;
8898
fn nodelay(&mut self) -> Result<(), IoError>;
@@ -124,3 +134,9 @@ pub trait RtioFileStream {
124134
fn tell(&self) -> Result<u64, IoError>;
125135
fn flush(&mut self) -> Result<(), IoError>;
126136
}
137+
138+
pub trait RtioProcess {
139+
fn id(&self) -> libc::pid_t;
140+
fn kill(&mut self, signal: int) -> Result<(), IoError>;
141+
fn wait(&mut self) -> int;
142+
}

src/libstd/rt/uv/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl AsyncWatcher {
3434

3535
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
3636
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
37-
let status = status_to_maybe_uv_error(watcher, status);
37+
let status = status_to_maybe_uv_error(status);
3838
let data = watcher.get_watcher_data();
3939
let cb = data.async_cb.get_ref();
4040
(*cb)(watcher, status);

0 commit comments

Comments
 (0)