diff options
-rw-r--r-- | components/devtools/actor.rs | 2 | ||||
-rw-r--r-- | components/devtools/actors/console.rs | 2 | ||||
-rw-r--r-- | components/devtools/actors/inspector.rs | 2 | ||||
-rw-r--r-- | components/devtools/actors/root.rs | 2 | ||||
-rw-r--r-- | components/devtools/actors/tab.rs | 4 | ||||
-rw-r--r-- | components/devtools/lib.rs | 28 | ||||
-rw-r--r-- | components/devtools/protocol.rs | 33 | ||||
-rw-r--r-- | components/devtools_traits/lib.rs | 3 |
8 files changed, 38 insertions, 38 deletions
diff --git a/components/devtools/actor.rs b/components/devtools/actor.rs index 4f197ccb74e..2ea8e75c061 100644 --- a/components/devtools/actor.rs +++ b/components/devtools/actor.rs @@ -7,8 +7,8 @@ use std::any::{Any, TypeId}; use std::collections::HashMap; use std::cell::{Cell, RefCell}; -use std::old_io::TcpStream; use std::mem::{replace, transmute}; +use std::net::TcpStream; use std::raw::TraitObject; use rustc_serialize::json; diff --git a/components/devtools/actors/console.rs b/components/devtools/actors/console.rs index e11665745fd..a529af8be2c 100644 --- a/components/devtools/actors/console.rs +++ b/components/devtools/actors/console.rs @@ -17,7 +17,7 @@ use msg::constellation_msg::PipelineId; use collections::BTreeMap; use core::cell::RefCell; use rustc_serialize::json::{self, Json, ToJson}; -use std::old_io::TcpStream; +use std::net::TcpStream; use std::num::Float; use std::sync::mpsc::{channel, Sender}; diff --git a/components/devtools/actors/inspector.rs b/components/devtools/actors/inspector.rs index 67c87dbaec8..c9ad64d2315 100644 --- a/components/devtools/actors/inspector.rs +++ b/components/devtools/actors/inspector.rs @@ -15,8 +15,8 @@ use collections::BTreeMap; use msg::constellation_msg::PipelineId; use rustc_serialize::json::{self, Json, ToJson}; use std::cell::RefCell; -use std::old_io::TcpStream; use std::sync::mpsc::{channel, Sender}; +use std::net::TcpStream; use std::num::Float; pub struct InspectorActor { diff --git a/components/devtools/actors/root.rs b/components/devtools/actors/root.rs index dc1b0204d8b..2982d4dff9a 100644 --- a/components/devtools/actors/root.rs +++ b/components/devtools/actors/root.rs @@ -11,7 +11,7 @@ use actors::tab::{TabActor, TabActorMsg}; use protocol::JsonPacketStream; use rustc_serialize::json; -use std::old_io::TcpStream; +use std::net::TcpStream; #[derive(RustcEncodable)] struct ActorTraits { diff --git a/components/devtools/actors/tab.rs b/components/devtools/actors/tab.rs index d1524635648..883b512e34c 100644 --- a/components/devtools/actors/tab.rs +++ b/components/devtools/actors/tab.rs @@ -12,7 +12,7 @@ use devtools_traits::DevtoolScriptControlMsg::WantsLiveNotifications; use protocol::JsonPacketStream; use rustc_serialize::json; -use std::old_io::TcpStream; +use std::net::TcpStream; #[derive(RustcEncodable)] struct TabTraits; @@ -98,7 +98,7 @@ impl Actor for TabActor { traits: TabTraits, }; let console_actor = registry.find::<ConsoleActor>(&self.console); - console_actor.streams.borrow_mut().push(stream.clone()); + console_actor.streams.borrow_mut().push(stream.try_clone().unwrap()); stream.write_json_packet(&msg); console_actor.script_chan.send( WantsLiveNotifications(console_actor.pipeline, true)).unwrap(); diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index 113156541f9..4ae572e3100 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -10,8 +10,10 @@ #![crate_name = "devtools"] #![crate_type = "rlib"] -#![feature(int_uint, box_syntax, old_io, core, rustc_private)] +#![feature(int_uint, box_syntax, core, rustc_private)] #![feature(collections, std_misc)] +#![feature(io)] +#![feature(net)] #![allow(non_snake_case)] @@ -42,8 +44,7 @@ use std::borrow::ToOwned; use std::cell::RefCell; use std::collections::HashMap; use std::sync::mpsc::{channel, Receiver, Sender, RecvError}; -use std::old_io::{TcpListener, TcpStream}; -use std::old_io::{Acceptor, Listener}; +use std::net::{TcpListener, TcpStream, Shutdown}; use std::sync::{Arc, Mutex}; use time::precise_time_ns; @@ -89,10 +90,7 @@ pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> { fn run_server(sender: Sender<DevtoolsControlMsg>, receiver: Receiver<DevtoolsControlMsg>, port: u16) { - let listener = TcpListener::bind(&*format!("{}:{}", "127.0.0.1", port)); - - // bind the listener to the specified address - let mut acceptor = listener.listen().unwrap(); + let listener = TcpListener::bind(&("127.0.0.1", port)).unwrap(); let mut registry = ActorRegistry::new(); @@ -111,7 +109,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>, /// Process the input from a single devtools client until EOF. fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) { - println!("connection established to {}", stream.peer_name().unwrap()); + println!("connection established to {}", stream.peer_addr().unwrap()); { let actors = actors.lock().unwrap(); let msg = actors.find::<RootActor>("root").encodable(); @@ -127,14 +125,13 @@ fn run_server(sender: Sender<DevtoolsControlMsg>, Ok(()) => {}, Err(()) => { println!("error: devtools actor stopped responding"); - let _ = stream.close_read(); - let _ = stream.close_write(); + let _ = stream.shutdown(Shutdown::Both); break 'outer } } } Err(e) => { - println!("error: {}", e.desc); + println!("error: {}", e.description()); break 'outer } } @@ -228,7 +225,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>, spawn_named("DevtoolsClientAcceptor".to_owned(), move || { // accept connections and process them, spawning a new task for each one - for stream in acceptor.incoming() { + for stream in listener.incoming() { // connection succeeded sender.send(DevtoolsControlMsg::AddClient(stream.unwrap())).unwrap(); } @@ -238,9 +235,9 @@ fn run_server(sender: Sender<DevtoolsControlMsg>, match receiver.recv() { Ok(DevtoolsControlMsg::AddClient(stream)) => { let actors = actors.clone(); - accepted_connections.push(stream.clone()); + accepted_connections.push(stream.try_clone().unwrap()); spawn_named("DevtoolsClientHandler".to_owned(), move || { - handle_client(actors, stream.clone()) + handle_client(actors, stream.try_clone().unwrap()) }) } Ok(DevtoolsControlMsg::ServerExitMsg) | Err(RecvError) => break, @@ -254,7 +251,6 @@ fn run_server(sender: Sender<DevtoolsControlMsg>, } for connection in accepted_connections.iter_mut() { - let _read = connection.close_read(); - let _write = connection.close_write(); + let _ = connection.shutdown(Shutdown::Both); } } diff --git a/components/devtools/protocol.rs b/components/devtools/protocol.rs index 6d978a054dd..f8dfea7eac6 100644 --- a/components/devtools/protocol.rs +++ b/components/devtools/protocol.rs @@ -8,42 +8,45 @@ use rustc_serialize::{json, Encodable}; use rustc_serialize::json::Json; -use std::old_io::{IoError, OtherIoError, EndOfFile, TcpStream, IoResult}; +use std::io::{self, Read, ReadExt, Write, ErrorKind}; +use std::net::TcpStream; use std::num; pub trait JsonPacketStream { fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T); - fn read_json_packet(&mut self) -> IoResult<Json>; + fn read_json_packet(&mut self) -> io::Result<Json>; } impl JsonPacketStream for TcpStream { fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T) { let s = json::encode(obj).unwrap().replace("__type__", "type"); println!("<- {}", s); - self.write_str(&s.len().to_string()).unwrap(); - self.write_u8(':' as u8).unwrap(); - self.write_str(&s).unwrap(); + self.write_all(s.len().to_string().as_bytes()).unwrap(); + self.write_all(&[':' as u8]).unwrap(); + self.write_all(s.as_bytes()).unwrap(); } - fn read_json_packet<'a>(&mut self) -> IoResult<Json> { + fn read_json_packet<'a>(&mut self) -> io::Result<Json> { // https://wiki.mozilla.org/Remote_Debugging_Protocol_Stream_Transport // In short, each JSON packet is [ascii length]:[JSON data of given length] let mut buffer = vec!(); loop { - let colon = ':' as u8; - match self.read_byte() { - Ok(c) if c != colon => buffer.push(c as u8), - Ok(_) => { + let mut buf = [0]; + let byte = match try!(self.read(&mut buf)) { + 0 => return Err(io::Error::new(ErrorKind::Other, "EOF", None)), + 1 => buf[0], + _ => unreachable!(), + }; + match byte { + b':' => { let packet_len_str = String::from_utf8(buffer).unwrap(); let packet_len = num::from_str_radix(&packet_len_str, 10).unwrap(); - let packet_buf = self.read_exact(packet_len).unwrap(); - let packet = String::from_utf8(packet_buf).unwrap(); + let mut packet = String::new(); + self.take(packet_len).read_to_string(&mut packet).unwrap(); println!("{}", packet); return Ok(Json::from_str(&packet).unwrap()) }, - Err(ref e) if e.kind == EndOfFile => - return Err(IoError { kind: EndOfFile, desc: "EOF", detail: None }), - _ => return Err(IoError { kind: OtherIoError, desc: "connection error", detail: None }) + c => buffer.push(c), } } } diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 2a3da461ab0..209b29d6ec5 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -10,6 +10,7 @@ #![crate_type = "rlib"] #![feature(int_uint)] +#![feature(net)] #![allow(non_snake_case)] @@ -23,7 +24,7 @@ use msg::constellation_msg::PipelineId; use util::str::DOMString; use url::Url; -use std::old_io::TcpStream; +use std::net::TcpStream; use std::sync::mpsc::{Sender, Receiver}; pub type DevtoolsControlChan = Sender<DevtoolsControlMsg>; |