Skip to content

Commit 9f23349

Browse files
committed
---
yaml --- r: 96923 b: refs/heads/dist-snap c: afd4e2a h: refs/heads/master i: 96921: 5aa3b5c 96919: 6e023e7 v: v3
1 parent 3d92041 commit 9f23349

File tree

13 files changed

+287
-314
lines changed

13 files changed

+287
-314
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: f5d9b2ca6d9a360112f06b3044897c22736c52b8
9+
refs/heads/dist-snap: afd4e2ad8dc4112b99c8d30996ff0bb5b0516b53
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> ~[ai::Info] {
186186
mod test {
187187
use std::io::net::ip::{SocketAddr, Ipv4Addr};
188188
use super::super::local_loop;
189+
use super::GetAddrInfoRequest;
189190

190191
#[test]
191192
fn getaddrinfo_test() {
192-
match GetAddrInfoRequest::run(local_loop(), Some("localhost"), None, None) {
193+
let loop_ = &mut local_loop().loop_;
194+
match GetAddrInfoRequest::run(loop_, Some("localhost"), None, None) {
193195
Ok(infos) => {
194196
let mut found_local = false;
195197
let local_addr = &SocketAddr {
@@ -207,9 +209,10 @@ mod test {
207209

208210
#[test]
209211
fn issue_10663() {
212+
let loop_ = &mut local_loop().loop_;
210213
// Something should happen here, but this certainly shouldn't cause
211214
// everything to die. The actual outcome we don't care too much about.
212-
GetAddrInfoRequest::run(local_loop(), Some("irc.n0v4.com"), None,
215+
GetAddrInfoRequest::run(loop_, Some("irc.n0v4.com"), None,
213216
None);
214217
}
215218
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ impl Drop for AsyncWatcher {
127127
mod test_remote {
128128
use std::rt::rtio::Callback;
129129
use std::rt::thread::Thread;
130-
use std::rt::tube::Tube;
131130

131+
use super::AsyncWatcher;
132132
use super::super::local_loop;
133133

134134
// Make sure that we can fire watchers in remote threads and that they
135135
// actually trigger what they say they will.
136136
#[test]
137137
fn smoke_test() {
138-
struct MyCallback(Option<Tube<int>>);
138+
struct MyCallback(Option<Chan<int>>);
139139
impl Callback for MyCallback {
140140
fn call(&mut self) {
141141
// this can get called more than once, but we only want to send
@@ -146,16 +146,17 @@ mod test_remote {
146146
}
147147
}
148148

149-
let mut tube = Tube::new();
150-
let cb = ~MyCallback(Some(tube.clone()));
151-
let watcher = AsyncWatcher::new(local_loop(), cb as ~Callback);
149+
let (port, chan) = Chan::new();
150+
let cb = ~MyCallback(Some(chan));
151+
let watcher = AsyncWatcher::new(&mut local_loop().loop_,
152+
cb as ~Callback);
152153

153154
let thread = do Thread::start {
154155
let mut watcher = watcher;
155156
watcher.fire();
156157
};
157158

158-
assert_eq!(tube.recv(), 1);
159+
assert_eq!(port.recv(), 1);
159160
thread.join();
160161
}
161162
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ mod test {
448448
use std::io;
449449
use std::str;
450450
use std::vec;
451-
use l = super::super::local_loop;
451+
use super::FsRequest;
452+
use super::super::Loop;
453+
use super::super::local_loop;
454+
455+
fn l() -> &mut Loop { &mut local_loop().loop_ }
452456

453457
#[test]
454458
fn file_test_full_simple_sync() {
@@ -459,7 +463,7 @@ mod test {
459463

460464
{
461465
// open/create
462-
let result = FsRequest::open(l(), &path_str.to_c_str(),
466+
let result = FsRequest::open(local_loop(), &path_str.to_c_str(),
463467
create_flags as int, mode as int);
464468
assert!(result.is_ok());
465469
let result = result.unwrap();
@@ -472,7 +476,7 @@ mod test {
472476

473477
{
474478
// re-open
475-
let result = FsRequest::open(l(), &path_str.to_c_str(),
479+
let result = FsRequest::open(local_loop(), &path_str.to_c_str(),
476480
read_flags as int, 0);
477481
assert!(result.is_ok());
478482
let result = result.unwrap();
@@ -499,7 +503,7 @@ mod test {
499503
let create_flags = (O_RDWR | O_CREAT) as int;
500504
let mode = (S_IWUSR | S_IRUSR) as int;
501505

502-
let result = FsRequest::open(l(), path, create_flags, mode);
506+
let result = FsRequest::open(local_loop(), path, create_flags, mode);
503507
assert!(result.is_ok());
504508
let file = result.unwrap();
505509

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,124 @@ impl Drop for HomingMissile {
142142
self.check("task moved away from the home scheduler");
143143
}
144144
}
145+
146+
#[cfg(test)]
147+
mod test {
148+
// On one thread, create a udp socket. Then send that socket to another
149+
// thread and destroy the socket on the remote thread. This should make sure
150+
// that homing kicks in for the socket to go back home to the original
151+
// thread, close itself, and then come back to the last thread.
152+
//#[test]
153+
//fn test_homing_closes_correctly() {
154+
// let (port, chan) = Chan::new();
155+
156+
// do task::spawn_sched(task::SingleThreaded) {
157+
// let listener = UdpWatcher::bind(local_loop(), next_test_ip4()).unwrap();
158+
// chan.send(listener);
159+
// }
160+
161+
// do task::spawn_sched(task::SingleThreaded) {
162+
// port.recv();
163+
// }
164+
//}
165+
166+
// This is a bit of a crufty old test, but it has its uses.
167+
//#[test]
168+
//fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() {
169+
// use std::cast;
170+
// use std::rt::local::Local;
171+
// use std::rt::rtio::{EventLoop, IoFactory};
172+
// use std::rt::sched::Scheduler;
173+
// use std::rt::sched::{Shutdown, TaskFromFriend};
174+
// use std::rt::sleeper_list::SleeperList;
175+
// use std::rt::task::Task;
176+
// use std::rt::task::UnwindResult;
177+
// use std::rt::thread::Thread;
178+
// use std::rt::deque::BufferPool;
179+
// use std::unstable::run_in_bare_thread;
180+
// use uvio::UvEventLoop;
181+
182+
// do run_in_bare_thread {
183+
// let sleepers = SleeperList::new();
184+
// let mut pool = BufferPool::new();
185+
// let (worker1, stealer1) = pool.deque();
186+
// let (worker2, stealer2) = pool.deque();
187+
// let queues = ~[stealer1, stealer2];
188+
189+
// let loop1 = ~UvEventLoop::new() as ~EventLoop;
190+
// let mut sched1 = ~Scheduler::new(loop1, worker1, queues.clone(),
191+
// sleepers.clone());
192+
// let loop2 = ~UvEventLoop::new() as ~EventLoop;
193+
// let mut sched2 = ~Scheduler::new(loop2, worker2, queues.clone(),
194+
// sleepers.clone());
195+
196+
// let handle1 = sched1.make_handle();
197+
// let handle2 = sched2.make_handle();
198+
// let tasksFriendHandle = sched2.make_handle();
199+
200+
// let on_exit: proc(UnwindResult) = proc(exit_status) {
201+
// let mut handle1 = handle1;
202+
// let mut handle2 = handle2;
203+
// handle1.send(Shutdown);
204+
// handle2.send(Shutdown);
205+
// assert!(exit_status.is_success());
206+
// };
207+
208+
// unsafe fn local_io() -> &'static mut IoFactory {
209+
// let mut sched = Local::borrow(None::<Scheduler>);
210+
// let io = sched.get().event_loop.io();
211+
// cast::transmute(io.unwrap())
212+
// }
213+
214+
// let test_function: proc() = proc() {
215+
// let io = unsafe { local_io() };
216+
// let addr = next_test_ip4();
217+
// let maybe_socket = io.udp_bind(addr);
218+
// // this socket is bound to this event loop
219+
// assert!(maybe_socket.is_ok());
220+
221+
// // block self on sched1
222+
// let scheduler: ~Scheduler = Local::take();
223+
// let mut tasksFriendHandle = Some(tasksFriendHandle);
224+
// scheduler.deschedule_running_task_and_then(|_, task| {
225+
// // unblock task
226+
// task.wake().map(|task| {
227+
// // send self to sched2
228+
// tasksFriendHandle.take_unwrap()
229+
// .send(TaskFromFriend(task));
230+
// });
231+
// // sched1 should now sleep since it has nothing else to do
232+
// })
233+
// // sched2 will wake up and get the task as we do nothing else,
234+
// // the function ends and the socket goes out of scope sched2
235+
// // will start to run the destructor the destructor will first
236+
// // block the task, set it's home as sched1, then enqueue it
237+
// // sched2 will dequeue the task, see that it has a home, and
238+
// // send it to sched1 sched1 will wake up, exec the close
239+
// // function on the correct loop, and then we're done
240+
// };
241+
242+
// let mut main_task = ~Task::new_root(&mut sched1.stack_pool, None,
243+
// test_function);
244+
// main_task.death.on_exit = Some(on_exit);
245+
246+
// let null_task = ~do Task::new_root(&mut sched2.stack_pool, None) {
247+
// // nothing
248+
// };
249+
250+
// let main_task = main_task;
251+
// let sched1 = sched1;
252+
// let thread1 = do Thread::start {
253+
// sched1.bootstrap(main_task);
254+
// };
255+
256+
// let sched2 = sched2;
257+
// let thread2 = do Thread::start {
258+
// sched2.bootstrap(null_task);
259+
// };
260+
261+
// thread1.join();
262+
// thread2.join();
263+
// }
264+
//}
265+
}

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

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,71 +97,102 @@ impl Drop for IdleWatcher {
9797

9898
#[cfg(test)]
9999
mod test {
100-
use std::rt::tube::Tube;
101-
use std::rt::rtio::{Callback, PausableIdleCallback};
100+
use std::cast;
101+
use std::cell::RefCell;
102+
use std::rc::Rc;
103+
use std::rt::rtio::{Callback, PausibleIdleCallback};
104+
use std::rt::task::{BlockedTask, Task};
105+
use std::rt::local::Local;
106+
use super::IdleWatcher;
102107
use super::super::local_loop;
103108

104-
struct MyCallback(Tube<int>, int);
109+
type Chan = Rc<RefCell<(Option<BlockedTask>, uint)>>;
110+
111+
struct MyCallback(Rc<RefCell<(Option<BlockedTask>, uint)>>, uint);
105112
impl Callback for MyCallback {
106113
fn call(&mut self) {
107-
match *self {
108-
MyCallback(ref mut tube, val) => tube.send(val)
109-
}
114+
let task = match *self {
115+
MyCallback(ref rc, n) => {
116+
let mut slot = rc.borrow().borrow_mut();
117+
match *slot.get() {
118+
(ref mut task, ref mut val) => {
119+
*val = n;
120+
task.take_unwrap()
121+
}
122+
}
123+
}
124+
};
125+
task.wake().map(|t| t.reawaken(true));
110126
}
111127
}
112128

129+
fn mk(v: uint) -> (~IdleWatcher, Chan) {
130+
let rc = Rc::from_send(RefCell::new((None, 0)));
131+
let cb = ~MyCallback(rc.clone(), v);
132+
let cb = cb as ~Callback:;
133+
let cb = unsafe { cast::transmute(cb) };
134+
(IdleWatcher::new(&mut local_loop().loop_, cb), rc)
135+
}
136+
137+
fn sleep(chan: &Chan) -> uint {
138+
let task: ~Task = Local::take();
139+
task.deschedule(1, |task| {
140+
let mut slot = chan.borrow().borrow_mut();
141+
match *slot.get() {
142+
(ref mut slot, _) => {
143+
assert!(slot.is_none());
144+
*slot = Some(task);
145+
}
146+
}
147+
Ok(())
148+
});
149+
150+
let slot = chan.borrow().borrow();
151+
match *slot.get() { (_, n) => n }
152+
}
153+
113154
#[test]
114155
fn not_used() {
115-
let cb = ~MyCallback(Tube::new(), 1);
116-
let _idle = IdleWatcher::new(local_loop(), cb as ~Callback);
156+
let (_idle, _chan) = mk(1);
117157
}
118158

119159
#[test]
120160
fn smoke_test() {
121-
let mut tube = Tube::new();
122-
let cb = ~MyCallback(tube.clone(), 1);
123-
let mut idle = IdleWatcher::new(local_loop(), cb as ~Callback);
161+
let (mut idle, chan) = mk(1);
124162
idle.resume();
125-
tube.recv();
163+
assert_eq!(sleep(&chan), 1);
126164
}
127165

128166
#[test] #[should_fail]
129167
fn smoke_fail() {
130-
let tube = Tube::new();
131-
let cb = ~MyCallback(tube.clone(), 1);
132-
let mut idle = IdleWatcher::new(local_loop(), cb as ~Callback);
168+
let (mut idle, _chan) = mk(1);
133169
idle.resume();
134170
fail!();
135171
}
136172

137173
#[test]
138174
fn fun_combinations_of_methods() {
139-
let mut tube = Tube::new();
140-
let cb = ~MyCallback(tube.clone(), 1);
141-
let mut idle = IdleWatcher::new(local_loop(), cb as ~Callback);
175+
let (mut idle, chan) = mk(1);
142176
idle.resume();
143-
tube.recv();
177+
assert_eq!(sleep(&chan), 1);
144178
idle.pause();
145179
idle.resume();
146180
idle.resume();
147-
tube.recv();
181+
assert_eq!(sleep(&chan), 1);
148182
idle.pause();
149183
idle.pause();
150184
idle.resume();
151-
tube.recv();
185+
assert_eq!(sleep(&chan), 1);
152186
}
153187

154188
#[test]
155189
fn pause_pauses() {
156-
let mut tube = Tube::new();
157-
let cb = ~MyCallback(tube.clone(), 1);
158-
let mut idle1 = IdleWatcher::new(local_loop(), cb as ~Callback);
159-
let cb = ~MyCallback(tube.clone(), 2);
160-
let mut idle2 = IdleWatcher::new(local_loop(), cb as ~Callback);
190+
let (mut idle1, chan1) = mk(1);
191+
let (mut idle2, chan2) = mk(2);
161192
idle2.resume();
162-
assert_eq!(tube.recv(), 2);
193+
assert_eq!(sleep(&chan2), 2);
163194
idle2.pause();
164195
idle1.resume();
165-
assert_eq!(tube.recv(), 1);
196+
assert_eq!(sleep(&chan1), 1);
166197
}
167198
}

0 commit comments

Comments
 (0)