Skip to content

Commit 22e4e6a

Browse files
committed
auto merge of #13619 : alexcrichton/rust/update-libuv, r=brson
This update brings a few months of changes, but primarily a fix for the following situation. When creating a handle to stdin, libuv used to set the stdin handle to nonblocking mode. This would end up affect this stdin handle across all processes that shared it, which mean that stdin become nonblocking for everyone using the same stdin. On linux, this also affected *stdout* because stdin/stdout roughly point at the same thing. This problem became apparent when running the test suite manually on a local computer. The stdtest suite (running with libgreen) would set stdout to nonblocking mode (as described above), and then the next test suite would always fail for a printing failure (because stdout was returning EAGAIN). This has been fixed upstream, joyent/libuv@342e8c, and this update pulls in this fix. This also brings us in line with a recently upstreamed libuv patch. Closes #12827 Closes #13336 Closes #13355
2 parents 3157c3e + 58a5112 commit 22e4e6a

13 files changed

+42
-47
lines changed

src/librustuv/async.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::cast;
12-
use libc::c_int;
1312
use std::rt::rtio::{Callback, RemoteCallback};
1413
use std::unstable::sync::Exclusive;
1514

@@ -54,8 +53,7 @@ impl UvHandle<uvll::uv_async_t> for AsyncWatcher {
5453
}
5554
}
5655

57-
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
58-
assert!(status == 0);
56+
extern fn async_cb(handle: *uvll::uv_async_t) {
5957
let payload: &mut Payload = unsafe {
6058
cast::transmute(uvll::get_data_for_uv_handle(handle))
6159
};

src/librustuv/file.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::c_str::CString;
1212
use std::c_str;
1313
use std::cast::transmute;
1414
use std::cast;
15-
use libc::{c_int, c_char, c_void, size_t, ssize_t};
15+
use libc::{c_int, c_char, c_void, ssize_t};
1616
use libc;
1717
use std::rt::task::BlockedTask;
1818
use std::io::{FileStat, IoError};
@@ -86,14 +86,12 @@ impl FsRequest {
8686
} else {
8787
offset + written as i64
8888
};
89+
let uvbuf = uvll::uv_buf_t {
90+
base: buf.slice_from(written as uint).as_ptr(),
91+
len: (buf.len() - written) as uvll::uv_buf_len_t,
92+
};
8993
match execute(|req, cb| unsafe {
90-
uvll::uv_fs_write(loop_.handle,
91-
req,
92-
fd,
93-
buf.as_ptr().offset(written as int) as *c_void,
94-
(buf.len() - written) as size_t,
95-
offset,
96-
cb)
94+
uvll::uv_fs_write(loop_.handle, req, fd, &uvbuf, 1, offset, cb)
9795
}).map(|req| req.get_result()) {
9896
Err(e) => return Err(e),
9997
Ok(n) => { written += n as uint; }
@@ -106,9 +104,11 @@ impl FsRequest {
106104
-> Result<int, UvError>
107105
{
108106
execute(|req, cb| unsafe {
109-
uvll::uv_fs_read(loop_.handle, req,
110-
fd, buf.as_ptr() as *c_void,
111-
buf.len() as size_t, offset, cb)
107+
let uvbuf = uvll::uv_buf_t {
108+
base: buf.as_ptr(),
109+
len: buf.len() as uvll::uv_buf_len_t,
110+
};
111+
uvll::uv_fs_read(loop_.handle, req, fd, &uvbuf, 1, offset, cb)
112112
}).map(|req| {
113113
req.get_result() as int
114114
})

src/librustuv/idle.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::cast;
12-
use libc::{c_int, c_void};
12+
use libc::c_void;
1313

1414
use uvll;
1515
use super::{Loop, UvHandle};
@@ -46,8 +46,7 @@ impl IdleWatcher {
4646
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)
4747
}
4848

49-
extern fn onetime_cb(handle: *uvll::uv_idle_t, status: c_int) {
50-
assert_eq!(status, 0);
49+
extern fn onetime_cb(handle: *uvll::uv_idle_t) {
5150
unsafe {
5251
let data = uvll::get_data_for_uv_handle(handle);
5352
let f: ~proc() = cast::transmute(data);
@@ -82,8 +81,7 @@ impl UvHandle<uvll::uv_idle_t> for IdleWatcher {
8281
fn uv_handle(&self) -> *uvll::uv_idle_t { self.handle }
8382
}
8483

85-
extern fn idle_cb(handle: *uvll::uv_idle_t, status: c_int) {
86-
assert_eq!(status, 0);
84+
extern fn idle_cb(handle: *uvll::uv_idle_t) {
8785
let idle: &mut IdleWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
8886
idle.callback.call();
8987
}

src/librustuv/net.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,9 @@ impl TcpWatcher {
255255
n => Err(UvError(n))
256256
};
257257

258-
extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) {
258+
extern fn timer_cb(handle: *uvll::uv_timer_t) {
259259
// Don't close the corresponding tcp request, just wake up the task
260260
// and let RAII take care of the pending watcher.
261-
assert_eq!(status, 0);
262261
let cx: &mut Ctx = unsafe {
263262
&mut *(uvll::get_data_for_uv_handle(handle) as *mut Ctx)
264263
};
@@ -599,8 +598,7 @@ impl rtio::RtioTcpAcceptor for TcpAcceptor {
599598
self.timeout_tx = Some(tx);
600599
self.timeout_rx = Some(rx);
601600

602-
extern fn timer_cb(timer: *uvll::uv_timer_t, status: c_int) {
603-
assert_eq!(status, 0);
601+
extern fn timer_cb(timer: *uvll::uv_timer_t) {
604602
let acceptor: &mut TcpAcceptor = unsafe {
605603
&mut *(uvll::get_data_for_uv_handle(timer) as *mut TcpAcceptor)
606604
};

src/librustuv/queue.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![allow(dead_code)]
2222

2323
use std::cast;
24-
use libc::{c_void, c_int};
24+
use libc::c_void;
2525
use std::rt::task::BlockedTask;
2626
use std::unstable::mutex::NativeMutex;
2727
use std::sync::arc::UnsafeArc;
@@ -55,8 +55,7 @@ pub struct Queue {
5555
queue: UnsafeArc<State>,
5656
}
5757

58-
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
59-
assert_eq!(status, 0);
58+
extern fn async_cb(handle: *uvll::uv_async_t) {
6059
let pool: &mut QueuePool = unsafe {
6160
cast::transmute(uvll::get_data_for_uv_handle(handle))
6261
};

src/librustuv/timer.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use libc::c_int;
1211
use std::mem;
1312
use std::rt::rtio::RtioTimer;
1413
use std::rt::task::BlockedTask;
@@ -137,9 +136,8 @@ impl RtioTimer for TimerWatcher {
137136
}
138137
}
139138

140-
extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) {
139+
extern fn timer_cb(handle: *uvll::uv_timer_t) {
141140
let _f = ForbidSwitch::new("timer callback can't switch");
142-
assert_eq!(status, 0);
143141
let timer: &mut TimerWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
144142

145143
match timer.action.take_unwrap() {

src/librustuv/tty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl TtyWatcher {
4040
// - https://github.com/joyent/libuv/issues/982
4141
// - https://github.com/joyent/libuv/issues/988
4242
let guess = unsafe { uvll::guess_handle(fd) };
43-
if readable && guess != uvll::UV_TTY as libc::c_int {
43+
if guess != uvll::UV_TTY as libc::c_int {
4444
return Err(UvError(uvll::EBADF));
4545
}
4646

src/librustuv/uvio.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR,
2323
use libc;
2424
use std::path::Path;
2525
use std::rt::rtio;
26-
use std::rt::rtio::IoFactory;
26+
use std::rt::rtio::{IoFactory, EventLoop};
2727
use ai = std::io::net::addrinfo;
2828

2929
#[cfg(test)] use std::unstable::run_in_bare_thread;
@@ -69,14 +69,20 @@ impl Drop for UvEventLoop {
6969
// the loop is free'd (use-after-free). We also must free the uv handle
7070
// after the loop has been closed because during the closing of the loop
7171
// the handle is required to be used apparently.
72+
//
73+
// Lastly, after we've closed the pool of handles we pump the event loop
74+
// one last time to run any closing callbacks to make sure the loop
75+
// shuts down cleanly.
7276
let handle = self.uvio.handle_pool.get_ref().handle();
7377
drop(self.uvio.handle_pool.take());
78+
self.run();
79+
7480
self.uvio.loop_.close();
7581
unsafe { uvll::free_handle(handle) }
7682
}
7783
}
7884

79-
impl rtio::EventLoop for UvEventLoop {
85+
impl EventLoop for UvEventLoop {
8086
fn run(&mut self) {
8187
self.uvio.loop_.run();
8288
}
@@ -110,7 +116,6 @@ impl rtio::EventLoop for UvEventLoop {
110116

111117
#[test]
112118
fn test_callback_run_once() {
113-
use std::rt::rtio::EventLoop;
114119
run_in_bare_thread(proc() {
115120
let mut event_loop = UvEventLoop::new();
116121
let mut count = 0;

src/librustuv/uvll.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ impl uv_stat_t {
212212
}
213213
}
214214

215-
pub type uv_idle_cb = extern "C" fn(handle: *uv_idle_t,
216-
status: c_int);
215+
pub type uv_idle_cb = extern "C" fn(handle: *uv_idle_t);
217216
pub type uv_alloc_cb = extern "C" fn(stream: *uv_stream_t,
218217
suggested_size: size_t,
219218
buf: *mut uv_buf_t);
@@ -230,14 +229,12 @@ pub type uv_udp_recv_cb = extern "C" fn(handle: *uv_udp_t,
230229
pub type uv_close_cb = extern "C" fn(handle: *uv_handle_t);
231230
pub type uv_walk_cb = extern "C" fn(handle: *uv_handle_t,
232231
arg: *c_void);
233-
pub type uv_async_cb = extern "C" fn(handle: *uv_async_t,
234-
status: c_int);
232+
pub type uv_async_cb = extern "C" fn(handle: *uv_async_t);
235233
pub type uv_connect_cb = extern "C" fn(handle: *uv_connect_t,
236234
status: c_int);
237235
pub type uv_connection_cb = extern "C" fn(handle: *uv_connection_t,
238236
status: c_int);
239-
pub type uv_timer_cb = extern "C" fn(handle: *uv_timer_t,
240-
status: c_int);
237+
pub type uv_timer_cb = extern "C" fn(handle: *uv_timer_t);
241238
pub type uv_write_cb = extern "C" fn(handle: *uv_write_t,
242239
status: c_int);
243240
pub type uv_getaddrinfo_cb = extern "C" fn(req: *uv_getaddrinfo_t,
@@ -597,10 +594,12 @@ extern {
597594
flags: c_int, mode: c_int, cb: uv_fs_cb) -> c_int;
598595
pub fn uv_fs_unlink(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
599596
cb: uv_fs_cb) -> c_int;
600-
pub fn uv_fs_write(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void,
601-
len: size_t, offset: i64, cb: uv_fs_cb) -> c_int;
602-
pub fn uv_fs_read(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void,
603-
len: size_t, offset: i64, cb: uv_fs_cb) -> c_int;
597+
pub fn uv_fs_write(l: *uv_loop_t, req: *uv_fs_t, fd: c_int,
598+
bufs: *uv_buf_t, nbufs: c_uint,
599+
offset: i64, cb: uv_fs_cb) -> c_int;
600+
pub fn uv_fs_read(l: *uv_loop_t, req: *uv_fs_t, fd: c_int,
601+
bufs: *uv_buf_t, nbufs: c_uint,
602+
offset: i64, cb: uv_fs_cb) -> c_int;
604603
pub fn uv_fs_close(l: *uv_loop_t, req: *uv_fs_t, fd: c_int,
605604
cb: uv_fs_cb) -> c_int;
606605
pub fn uv_fs_stat(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,

src/libstd/hash/sip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ mod tests {
364364
use option::{Some, None};
365365
use str::{Str,StrSlice};
366366
use strbuf::StrBuf;
367-
use slice::{Vector, ImmutableVector, OwnedVector};
367+
use slice::{Vector, ImmutableVector};
368368
use self::test::Bencher;
369369

370370
use super::super::Hash;

src/libstd/rt/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ mod imp {
6767
use clone::Clone;
6868
use option::{Option, Some, None};
6969
use iter::Iterator;
70-
use str::StrSlice;
7170
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
7271
use mem;
72+
#[cfg(not(test))] use str::StrSlice;
7373
#[cfg(not(test))] use ptr::RawPtr;
7474

7575
static mut global_args_ptr: uint = 0;

src/libuv

Submodule libuv updated from 800b56f to 4349589

src/rt/libuv-auto-clean-trigger

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Change the contents of this file to force a full rebuild of libuv
2-
2014-02-16
2+
2014-04-18

0 commit comments

Comments
 (0)