diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-11-05 19:14:17 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-10 01:37:11 -0800 |
| commit | 1bdaea827ed957ce404fffee27923e9606584ce0 (patch) | |
| tree | 5b6331c7b312b7ee1e73740607ed8f01ed7e036c | |
| parent | f9abd998d6a5368c54162deb0bf187e94e31dc27 (diff) | |
| download | rust-1bdaea827ed957ce404fffee27923e9606584ce0.tar.gz rust-1bdaea827ed957ce404fffee27923e9606584ce0.zip | |
Migrate all streams to synchronous closing
| -rw-r--r-- | src/librustuv/net.rs | 2 | ||||
| -rw-r--r-- | src/librustuv/pipe.rs | 2 | ||||
| -rw-r--r-- | src/librustuv/stream.rs | 35 | ||||
| -rw-r--r-- | src/librustuv/tty.rs | 7 |
4 files changed, 14 insertions, 32 deletions
diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 01847a19304..28c2c4df12a 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -313,7 +313,7 @@ impl rtio::RtioTcpStream for TcpWatcher { impl Drop for TcpWatcher { fn drop(&mut self) { let _m = self.fire_missiles(); - self.stream.close(true); + self.stream.close(); } } diff --git a/src/librustuv/pipe.rs b/src/librustuv/pipe.rs index e1cb8464114..f79043797ae 100644 --- a/src/librustuv/pipe.rs +++ b/src/librustuv/pipe.rs @@ -136,7 +136,7 @@ impl HomingIO for PipeWatcher { impl Drop for PipeWatcher { fn drop(&mut self) { let _m = self.fire_missiles(); - self.stream.close(true); // close synchronously + self.stream.close(); } } diff --git a/src/librustuv/stream.rs b/src/librustuv/stream.rs index 4958ca4838e..745cb5a6fa0 100644 --- a/src/librustuv/stream.rs +++ b/src/librustuv/stream.rs @@ -10,7 +10,6 @@ use std::cast; use std::libc::{c_int, size_t, ssize_t, c_void}; -use std::ptr; use std::rt::BlockedTask; use std::rt::local::Local; use std::rt::sched::Scheduler; @@ -124,35 +123,23 @@ impl StreamWatcher { // This will deallocate an internally used memory, along with closing the // handle (and freeing it). - // - // The `synchronous` flag dictates whether this handle is closed - // synchronously (the task is blocked) or asynchronously (the task is not - // block, but the handle is still deallocated). - pub fn close(&mut self, synchronous: bool) { - if synchronous { - let mut closing_task = None; - unsafe { - uvll::set_data_for_uv_handle(self.handle, &closing_task); - } + pub fn close(&mut self) { + let mut closing_task = None; + unsafe { + uvll::set_data_for_uv_handle(self.handle, &closing_task); + } - // Wait for this stream to close because it possibly represents a remote - // connection which may have consequences if we close asynchronously. - let sched: ~Scheduler = Local::take(); - do sched.deschedule_running_task_and_then |_, task| { - closing_task = Some(task); - unsafe { uvll::uv_close(self.handle, close_cb) } - } - } else { - unsafe { - uvll::set_data_for_uv_handle(self.handle, ptr::null::<u8>()); - uvll::uv_close(self.handle, close_cb) - } + // Wait for this stream to close because it possibly represents a remote + // connection which may have consequences if we close asynchronously. + let sched: ~Scheduler = Local::take(); + do sched.deschedule_running_task_and_then |_, task| { + closing_task = Some(task); + unsafe { uvll::uv_close(self.handle, close_cb) } } extern fn close_cb(handle: *uvll::uv_handle_t) { let data: *c_void = unsafe { uvll::get_data_for_uv_handle(handle) }; unsafe { uvll::free_handle(handle) } - if data.is_null() { return } let closing_task: &mut Option<BlockedTask> = unsafe { cast::transmute(data) diff --git a/src/librustuv/tty.rs b/src/librustuv/tty.rs index 9d84f785f25..b1bc378e617 100644 --- a/src/librustuv/tty.rs +++ b/src/librustuv/tty.rs @@ -101,13 +101,8 @@ impl HomingIO for TtyWatcher { } impl Drop for TtyWatcher { - // TTY handles are used for the logger in a task, so this destructor is run - // when a task is destroyed. When a task is being destroyed, a local - // scheduler isn't available, so we can't do the normal "take the scheduler - // and resume once close is done". Instead close operations on a TTY are - // asynchronous. fn drop(&mut self) { let _m = self.fire_missiles(); - self.stream.close(false); + self.stream.close(); } } |
