mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
auto merge of #5345 : aweinstock314/servo/master, r=jdm
This commit is contained in:
commit
1f0291c4db
2 changed files with 34 additions and 36 deletions
|
@ -10,7 +10,7 @@
|
||||||
#![crate_name = "devtools"]
|
#![crate_name = "devtools"]
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
|
|
||||||
#![feature(int_uint, box_syntax, io, old_io, core, rustc_private)]
|
#![feature(int_uint, box_syntax, old_io, core, rustc_private)]
|
||||||
#![feature(collections, std_misc)]
|
#![feature(collections, std_misc)]
|
||||||
|
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
@ -41,10 +41,9 @@ use util::task::spawn_named;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender, RecvError};
|
||||||
use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
|
|
||||||
use std::old_io::{TcpListener, TcpStream};
|
use std::old_io::{TcpListener, TcpStream};
|
||||||
use std::old_io::{Acceptor, Listener, TimedOut};
|
use std::old_io::{Acceptor, Listener};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use time::precise_time_ns;
|
use time::precise_time_ns;
|
||||||
|
|
||||||
|
@ -78,20 +77,22 @@ struct ConsoleMsg {
|
||||||
/// Spin up a devtools server that listens for connections on the specified port.
|
/// Spin up a devtools server that listens for connections on the specified port.
|
||||||
pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> {
|
pub fn start_server(port: u16) -> Sender<DevtoolsControlMsg> {
|
||||||
let (sender, receiver) = channel();
|
let (sender, receiver) = channel();
|
||||||
spawn_named("Devtools".to_owned(), move || {
|
{
|
||||||
run_server(receiver, port)
|
let sender = sender.clone();
|
||||||
});
|
spawn_named("Devtools".to_owned(), move || {
|
||||||
|
run_server(sender, receiver, port)
|
||||||
|
});
|
||||||
|
}
|
||||||
sender
|
sender
|
||||||
}
|
}
|
||||||
|
|
||||||
static POLL_TIMEOUT: u64 = 300;
|
fn run_server(sender: Sender<DevtoolsControlMsg>,
|
||||||
|
receiver: Receiver<DevtoolsControlMsg>,
|
||||||
fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
port: u16) {
|
||||||
let listener = TcpListener::bind(&*format!("{}:{}", "127.0.0.1", port));
|
let listener = TcpListener::bind(&*format!("{}:{}", "127.0.0.1", port));
|
||||||
|
|
||||||
// bind the listener to the specified address
|
// bind the listener to the specified address
|
||||||
let mut acceptor = listener.listen().unwrap();
|
let mut acceptor = listener.listen().unwrap();
|
||||||
acceptor.set_timeout(Some(POLL_TIMEOUT));
|
|
||||||
|
|
||||||
let mut registry = ActorRegistry::new();
|
let mut registry = ActorRegistry::new();
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
// TODO: move this into the root or tab modules?
|
// TODO: move this into the root or tab modules?
|
||||||
fn handle_new_global(actors: Arc<Mutex<ActorRegistry>>,
|
fn handle_new_global(actors: Arc<Mutex<ActorRegistry>>,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
sender: Sender<DevtoolScriptControlMsg>,
|
scriptSender: Sender<DevtoolScriptControlMsg>,
|
||||||
actor_pipelines: &mut HashMap<PipelineId, String>,
|
actor_pipelines: &mut HashMap<PipelineId, String>,
|
||||||
page_info: DevtoolsPageInfo) {
|
page_info: DevtoolsPageInfo) {
|
||||||
let mut actors = actors.lock().unwrap();
|
let mut actors = actors.lock().unwrap();
|
||||||
|
@ -154,7 +155,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
let (tab, console, inspector) = {
|
let (tab, console, inspector) = {
|
||||||
let console = ConsoleActor {
|
let console = ConsoleActor {
|
||||||
name: actors.new_name("console"),
|
name: actors.new_name("console"),
|
||||||
script_chan: sender.clone(),
|
script_chan: scriptSender.clone(),
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
streams: RefCell::new(Vec::new()),
|
streams: RefCell::new(Vec::new()),
|
||||||
};
|
};
|
||||||
|
@ -163,7 +164,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
walker: RefCell::new(None),
|
walker: RefCell::new(None),
|
||||||
pageStyle: RefCell::new(None),
|
pageStyle: RefCell::new(None),
|
||||||
highlighter: RefCell::new(None),
|
highlighter: RefCell::new(None),
|
||||||
script_chan: sender,
|
script_chan: scriptSender,
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,35 +226,30 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
return console_actor_name;
|
return console_actor_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: figure out some system that allows us to watch for new connections,
|
spawn_named("DevtoolsClientAcceptor".to_owned(), move || {
|
||||||
// shut down existing ones at arbitrary times, and also watch for messages
|
// accept connections and process them, spawning a new task for each one
|
||||||
// from multiple script tasks simultaneously. Polling for new connections
|
for stream in acceptor.incoming() {
|
||||||
// for 300ms and then checking the receiver is not a good compromise
|
// connection succeeded
|
||||||
// (and makes Servo hang on exit if there's an open connection, no less).
|
sender.send(DevtoolsControlMsg::AddClient(stream.unwrap())).unwrap();
|
||||||
// accept connections and process them, spawning a new tasks for each one
|
}
|
||||||
|
});
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match acceptor.accept() {
|
match receiver.recv() {
|
||||||
Err(ref e) if e.kind == TimedOut => {
|
Ok(DevtoolsControlMsg::AddClient(stream)) => {
|
||||||
match receiver.try_recv() {
|
|
||||||
Ok(DevtoolsControlMsg::ServerExitMsg) | Err(Disconnected) => break,
|
|
||||||
Ok(DevtoolsControlMsg::NewGlobal(id, sender, pageinfo)) =>
|
|
||||||
handle_new_global(actors.clone(), id,sender, &mut actor_pipelines,
|
|
||||||
pageinfo),
|
|
||||||
Ok(DevtoolsControlMsg::SendConsoleMessage(id, console_message)) =>
|
|
||||||
handle_console_message(actors.clone(), id, console_message,
|
|
||||||
&actor_pipelines),
|
|
||||||
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_e) => { /* connection failed */ }
|
|
||||||
Ok(stream) => {
|
|
||||||
let actors = actors.clone();
|
let actors = actors.clone();
|
||||||
accepted_connections.push(stream.clone());
|
accepted_connections.push(stream.clone());
|
||||||
spawn_named("DevtoolsClientHandler".to_owned(), move || {
|
spawn_named("DevtoolsClientHandler".to_owned(), move || {
|
||||||
// connection succeeded
|
|
||||||
handle_client(actors, stream.clone())
|
handle_client(actors, stream.clone())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Ok(DevtoolsControlMsg::ServerExitMsg) | Err(RecvError) => break,
|
||||||
|
Ok(DevtoolsControlMsg::NewGlobal(id, scriptSender, pageinfo)) =>
|
||||||
|
handle_new_global(actors.clone(), id, scriptSender, &mut actor_pipelines,
|
||||||
|
pageinfo),
|
||||||
|
Ok(DevtoolsControlMsg::SendConsoleMessage(id, console_message)) =>
|
||||||
|
handle_console_message(actors.clone(), id, console_message,
|
||||||
|
&actor_pipelines),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ use msg::constellation_msg::PipelineId;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use std::old_io::TcpStream;
|
||||||
use std::sync::mpsc::{Sender, Receiver};
|
use std::sync::mpsc::{Sender, Receiver};
|
||||||
|
|
||||||
pub type DevtoolsControlChan = Sender<DevtoolsControlMsg>;
|
pub type DevtoolsControlChan = Sender<DevtoolsControlMsg>;
|
||||||
|
@ -38,6 +39,7 @@ pub struct DevtoolsPageInfo {
|
||||||
/// Messages to the instruct the devtools server to update its known actors/state
|
/// Messages to the instruct the devtools server to update its known actors/state
|
||||||
/// according to changes in the browser.
|
/// according to changes in the browser.
|
||||||
pub enum DevtoolsControlMsg {
|
pub enum DevtoolsControlMsg {
|
||||||
|
AddClient(TcpStream),
|
||||||
NewGlobal(PipelineId, Sender<DevtoolScriptControlMsg>, DevtoolsPageInfo),
|
NewGlobal(PipelineId, Sender<DevtoolScriptControlMsg>, DevtoolsPageInfo),
|
||||||
SendConsoleMessage(PipelineId, ConsoleMessage),
|
SendConsoleMessage(PipelineId, ConsoleMessage),
|
||||||
ServerExitMsg
|
ServerExitMsg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue