Skip to content

Commit 69aa114

Browse files
committed
Migrate all streams to synchronous closing
1 parent 57e4717 commit 69aa114

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

src/librustuv/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl rtio::RtioTcpStream for TcpWatcher {
313313
impl Drop for TcpWatcher {
314314
fn drop(&mut self) {
315315
let _m = self.fire_missiles();
316-
self.stream.close(true);
316+
self.stream.close();
317317
}
318318
}
319319

src/librustuv/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl HomingIO for PipeWatcher {
136136
impl Drop for PipeWatcher {
137137
fn drop(&mut self) {
138138
let _m = self.fire_missiles();
139-
self.stream.close(true); // close synchronously
139+
self.stream.close();
140140
}
141141
}
142142

src/librustuv/stream.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use std::cast;
1212
use std::libc::{c_int, size_t, ssize_t, c_void};
13-
use std::ptr;
1413
use std::rt::BlockedTask;
1514
use std::rt::local::Local;
1615
use std::rt::sched::Scheduler;
@@ -124,35 +123,23 @@ impl StreamWatcher {
124123

125124
// This will deallocate an internally used memory, along with closing the
126125
// handle (and freeing it).
127-
//
128-
// The `synchronous` flag dictates whether this handle is closed
129-
// synchronously (the task is blocked) or asynchronously (the task is not
130-
// block, but the handle is still deallocated).
131-
pub fn close(&mut self, synchronous: bool) {
132-
if synchronous {
133-
let mut closing_task = None;
134-
unsafe {
135-
uvll::set_data_for_uv_handle(self.handle, &closing_task);
136-
}
126+
pub fn close(&mut self) {
127+
let mut closing_task = None;
128+
unsafe {
129+
uvll::set_data_for_uv_handle(self.handle, &closing_task);
130+
}
137131

138-
// Wait for this stream to close because it possibly represents a remote
139-
// connection which may have consequences if we close asynchronously.
140-
let sched: ~Scheduler = Local::take();
141-
do sched.deschedule_running_task_and_then |_, task| {
142-
closing_task = Some(task);
143-
unsafe { uvll::uv_close(self.handle, close_cb) }
144-
}
145-
} else {
146-
unsafe {
147-
uvll::set_data_for_uv_handle(self.handle, ptr::null::<u8>());
148-
uvll::uv_close(self.handle, close_cb)
149-
}
132+
// Wait for this stream to close because it possibly represents a remote
133+
// connection which may have consequences if we close asynchronously.
134+
let sched: ~Scheduler = Local::take();
135+
do sched.deschedule_running_task_and_then |_, task| {
136+
closing_task = Some(task);
137+
unsafe { uvll::uv_close(self.handle, close_cb) }
150138
}
151139

152140
extern fn close_cb(handle: *uvll::uv_handle_t) {
153141
let data: *c_void = unsafe { uvll::get_data_for_uv_handle(handle) };
154142
unsafe { uvll::free_handle(handle) }
155-
if data.is_null() { return }
156143

157144
let closing_task: &mut Option<BlockedTask> = unsafe {
158145
cast::transmute(data)

src/librustuv/tty.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,8 @@ impl HomingIO for TtyWatcher {
101101
}
102102

103103
impl Drop for TtyWatcher {
104-
// TTY handles are used for the logger in a task, so this destructor is run
105-
// when a task is destroyed. When a task is being destroyed, a local
106-
// scheduler isn't available, so we can't do the normal "take the scheduler
107-
// and resume once close is done". Instead close operations on a TTY are
108-
// asynchronous.
109104
fn drop(&mut self) {
110105
let _m = self.fire_missiles();
111-
self.stream.close(false);
106+
self.stream.close();
112107
}
113108
}

0 commit comments

Comments
 (0)