Skip to content

Commit 5741580

Browse files
committed
---
yaml --- r: 95986 b: refs/heads/dist-snap c: 9286d51 h: refs/heads/master v: v3
1 parent 0563262 commit 5741580

File tree

6 files changed

+57
-88
lines changed

6 files changed

+57
-88
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: ceab326e82dfba2f3cd513926c023dea1af4b1c2
9+
refs/heads/dist-snap: 9286d5113d843e65fb13ff0cf142c1bfb10124f7
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustuv/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ pub type FsCallback = ~fn(&mut FsRequest, Option<UvError>);
191191
pub type AsyncCallback = ~fn(AsyncWatcher, Option<UvError>);
192192
pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
193193
pub type UdpSendCallback = ~fn(UdpWatcher, Option<UvError>);
194-
pub type SignalCallback = ~fn(SignalWatcher, Signum);
195194

196195

197196
/// Callbacks used by StreamWatchers, set as custom data on the foreign handle.
@@ -206,7 +205,6 @@ struct WatcherData {
206205
async_cb: Option<AsyncCallback>,
207206
udp_recv_cb: Option<UdpReceiveCallback>,
208207
udp_send_cb: Option<UdpSendCallback>,
209-
signal_cb: Option<SignalCallback>,
210208
}
211209

212210
pub trait WatcherInterop {

branches/dist-snap/src/librustuv/process.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ impl Process {
103103
extern fn on_exit(handle: *uvll::uv_process_t,
104104
exit_status: libc::c_int,
105105
term_signal: libc::c_int) {
106-
let handle = handle as *uvll::uv_handle_t;
107106
let p: &mut Process = unsafe { UvHandle::from_uv_handle(&handle) };
108107

109108
assert!(p.exit_status.is_none());

branches/dist-snap/src/librustuv/signal.rs

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

11-
use std::cast;
1211
use std::libc::c_int;
1312
use std::rt::io::signal::Signum;
13+
use std::rt::sched::{SchedHandle, Scheduler};
14+
use std::comm::{SharedChan, SendDeferred};
15+
use std::rt::local::Local;
16+
use std::rt::rtio::RtioSignal;
1417

15-
use super::{Loop, NativeHandle, SignalCallback, UvError, Watcher};
18+
use super::{Loop, UvError, UvHandle};
1619
use uvll;
20+
use uvio::HomingIO;
1721

18-
pub struct SignalWatcher(*uvll::uv_signal_t);
22+
pub struct SignalWatcher {
23+
handle: *uvll::uv_signal_t,
24+
home: SchedHandle,
1925

20-
impl Watcher for SignalWatcher { }
26+
channel: SharedChan<Signum>,
27+
signal: Signum,
28+
}
2129

2230
impl SignalWatcher {
23-
pub fn new(loop_: &mut Loop) -> SignalWatcher {
24-
unsafe {
25-
let handle = uvll::malloc_handle(uvll::UV_SIGNAL);
26-
assert!(handle.is_not_null());
27-
assert!(0 == uvll::uv_signal_init(loop_.native_handle(), handle));
28-
let mut watcher: SignalWatcher = NativeHandle::from_native_handle(handle);
29-
watcher.install_watcher_data();
30-
return watcher;
31-
}
32-
}
31+
pub fn new(loop_: &mut Loop, signum: Signum,
32+
channel: SharedChan<Signum>) -> Result<~SignalWatcher, UvError> {
33+
let handle = UvHandle::alloc(None::<SignalWatcher>, uvll::UV_SIGNAL);
34+
assert_eq!(unsafe {
35+
uvll::signal_init(loop_.native_handle(), handle)
36+
}, 0);
3337

34-
pub fn start(&mut self, signum: Signum, callback: SignalCallback)
35-
-> Result<(), UvError>
36-
{
37-
return unsafe {
38-
match uvll::uv_signal_start(self.native_handle(), signal_cb,
39-
signum as c_int) {
40-
0 => {
41-
let data = self.get_watcher_data();
42-
data.signal_cb = Some(callback);
43-
Ok(())
44-
}
45-
n => Err(UvError(n)),
38+
match unsafe { uvll::signal_start(handle, signal_cb, signum as c_int) } {
39+
0 => {
40+
let s = ~SignalWatcher {
41+
handle: handle,
42+
home: get_handle_to_current_scheduler!(),
43+
channel: channel,
44+
signal: signum,
45+
};
46+
Ok(s.install())
47+
}
48+
n => {
49+
unsafe { uvll::free_handle(handle) }
50+
Err(UvError(n))
4651
}
47-
};
48-
49-
extern fn signal_cb(handle: *uvll::uv_signal_t, signum: c_int) {
50-
let mut watcher: SignalWatcher = NativeHandle::from_native_handle(handle);
51-
let data = watcher.get_watcher_data();
52-
let cb = data.signal_cb.get_ref();
53-
(*cb)(watcher, unsafe { cast::transmute(signum as int) });
5452
}
55-
}
5653

57-
pub fn stop(&mut self) {
58-
unsafe {
59-
uvll::uv_signal_stop(self.native_handle());
60-
}
6154
}
6255
}
6356

64-
impl NativeHandle<*uvll::uv_signal_t> for SignalWatcher {
65-
fn from_native_handle(handle: *uvll::uv_signal_t) -> SignalWatcher {
66-
SignalWatcher(handle)
67-
}
57+
extern fn signal_cb(handle: *uvll::uv_signal_t, signum: c_int) {
58+
let s: &mut SignalWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
59+
assert_eq!(signum as int, s.signal as int);
60+
s.channel.send_deferred(s.signal);
61+
}
62+
63+
impl HomingIO for SignalWatcher {
64+
fn home<'r>(&'r mut self) -> &'r mut SchedHandle { &mut self.home }
65+
}
6866

69-
fn native_handle(&self) -> *uvll::uv_signal_t {
70-
match self { &SignalWatcher(ptr) => ptr }
67+
impl UvHandle<uvll::uv_signal_t> for SignalWatcher {
68+
fn uv_handle(&self) -> *uvll::uv_signal_t { self.handle }
69+
}
70+
71+
impl RtioSignal for SignalWatcher {}
72+
73+
impl Drop for SignalWatcher {
74+
fn drop(&mut self) {
75+
do self.home_for_io |self_| {
76+
self_.close_async_();
77+
}
7178
}
7279
}

branches/dist-snap/src/librustuv/timer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ impl RtioTimer for TimerWatcher {
102102
}
103103

104104
extern fn timer_cb(handle: *uvll::uv_timer_t, _status: c_int) {
105-
let handle = handle as *uvll::uv_handle_t;
106-
let timer : &mut TimerWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
105+
let timer: &mut TimerWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
107106

108107
match timer.action.take_unwrap() {
109108
WakeTask(task) => {

branches/dist-snap/src/librustuv/uvio.rs

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use std::cast::transmute;
1313
use std::cast;
1414
use std::cell::Cell;
1515
use std::clone::Clone;
16-
use std::comm::{SendDeferred, SharedChan, GenericChan};
17-
use std::libc::{c_int, c_uint, c_void, pid_t};
16+
use std::comm::{SharedChan, GenericChan};
17+
use std::libc::{c_int, c_uint, c_void};
1818
use std::ptr;
1919
use std::str;
2020
use std::rt::io;
@@ -841,11 +841,8 @@ impl IoFactory for UvIoFactory {
841841

842842
fn signal(&mut self, signum: Signum, channel: SharedChan<Signum>)
843843
-> Result<~RtioSignal, IoError> {
844-
let watcher = SignalWatcher::new(self.uv_loop());
845-
let home = get_handle_to_current_scheduler!();
846-
let mut signal = ~UvSignal::new(watcher, home);
847-
match signal.watcher.start(signum, |_, _| channel.send_deferred(signum)) {
848-
Ok(()) => Ok(signal as ~RtioSignal),
844+
match SignalWatcher::new(self.uv_loop(), signum, channel) {
845+
Ok(s) => Ok(s as ~RtioSignal),
849846
Err(e) => Err(uv_error_to_io_error(e)),
850847
}
851848
}
@@ -1591,37 +1588,6 @@ impl RtioUnixAcceptor for UvUnixAcceptor {
15911588
}
15921589
}
15931590

1594-
pub struct UvSignal {
1595-
watcher: signal::SignalWatcher,
1596-
home: SchedHandle,
1597-
}
1598-
1599-
impl HomingIO for UvSignal {
1600-
fn home<'r>(&'r mut self) -> &'r mut SchedHandle { &mut self.home }
1601-
}
1602-
1603-
impl UvSignal {
1604-
fn new(w: signal::SignalWatcher, home: SchedHandle) -> UvSignal {
1605-
UvSignal { watcher: w, home: home }
1606-
}
1607-
}
1608-
1609-
impl RtioSignal for UvSignal {}
1610-
1611-
impl Drop for UvSignal {
1612-
fn drop(&mut self) {
1613-
let (_m, scheduler) = self.fire_homing_missile_sched();
1614-
uvdebug!("closing UvSignal");
1615-
do scheduler.deschedule_running_task_and_then |_, task| {
1616-
let task_cell = Cell::new(task);
1617-
do self.watcher.close {
1618-
let scheduler: ~Scheduler = Local::take();
1619-
scheduler.resume_blocked_task_immediately(task_cell.take());
1620-
}
1621-
}
1622-
}
1623-
}
1624-
16251591
// this function is full of lies
16261592
unsafe fn local_io() -> &'static mut IoFactory {
16271593
do Local::borrow |sched: &mut Scheduler| {

0 commit comments

Comments
 (0)