Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread Safe IO #8631

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libstd/rt/io/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use option::{Option, None, Some};

type Port = u16;

#[deriving(Eq, TotalEq)]
#[deriving(Eq, TotalEq, Clone)]
pub enum IpAddr {
Ipv4Addr(u8, u8, u8, u8),
Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16)
Expand Down Expand Up @@ -62,7 +62,7 @@ impl ToStr for IpAddr {
}
}

#[deriving(Eq, TotalEq)]
#[deriving(Eq, TotalEq, Clone)]
pub struct SocketAddr {
ip: IpAddr,
port: Port,
Expand Down
8 changes: 2 additions & 6 deletions src/libstd/rt/io/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ impl Writer for TcpStream {
fn write(&mut self, buf: &[u8]) {
match (**self).write(buf) {
Ok(_) => (),
Err(ioerr) => {
io_error::cond.raise(ioerr);
}
Err(ioerr) => io_error::cond.raise(ioerr),
}
}

Expand Down Expand Up @@ -129,9 +127,7 @@ impl TcpListener {
impl Listener<TcpStream> for TcpListener {
fn accept(&mut self) -> Option<TcpStream> {
match (**self).accept() {
Ok(s) => {
Some(TcpStream::new(s))
}
Ok(s) => Some(TcpStream::new(s)),
Err(ioerr) => {
io_error::cond.raise(ioerr);
return None;
Expand Down
10 changes: 3 additions & 7 deletions src/libstd/rt/io/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Timer {
}

impl RtioTimer for Timer {
fn sleep(&self, msecs: u64) {
fn sleep(&mut self, msecs: u64) {
(**self).sleep(msecs);
}
}
Expand All @@ -50,15 +50,11 @@ impl RtioTimer for Timer {
mod test {
use super::*;
use rt::test::*;
use option::{Some, None};
#[test]
fn test_io_timer_sleep_simple() {
do run_in_newsched_task {
let timer = Timer::new();
match timer {
Some(t) => t.sleep(1),
None => assert!(false)
}
do timer.map_move |mut t| { t.sleep(1) };
}
}
}
}
2 changes: 1 addition & 1 deletion src/libstd/rt/rtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ pub trait RtioUdpSocket : RtioSocket {
}

pub trait RtioTimer {
fn sleep(&self, msecs: u64);
fn sleep(&mut self, msecs: u64);
}
6 changes: 4 additions & 2 deletions src/libstd/rt/uv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ impl StreamWatcher {

extern fn close_cb(handle: *uvll::uv_stream_t) {
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
stream_watcher.get_watcher_data().close_cb.take_unwrap()();
let cb = stream_watcher.get_watcher_data().close_cb.take_unwrap();
stream_watcher.drop_watcher_data();
unsafe { free_handle(handle as *c_void) }
cb();
}
}
}
Expand Down Expand Up @@ -411,9 +412,10 @@ impl UdpWatcher {

extern fn close_cb(handle: *uvll::uv_udp_t) {
let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);
udp_watcher.get_watcher_data().close_cb.take_unwrap()();
let cb = udp_watcher.get_watcher_data().close_cb.take_unwrap();
udp_watcher.drop_watcher_data();
unsafe { free_handle(handle as *c_void) }
cb();
}
}
}
Expand Down
Loading