mirror of
https://github.com/servo/servo.git
synced 2025-06-16 04:14:29 +00:00
Support for Separated Read Write
This commit is contained in:
parent
ad9aedac77
commit
75ffda9fb8
3 changed files with 18 additions and 3 deletions
|
@ -14,6 +14,7 @@ use devtools_traits::{ActorValue, DevtoolScriptControlMsg};
|
||||||
use servo_msg::constellation_msg::PipelineId;
|
use servo_msg::constellation_msg::PipelineId;
|
||||||
|
|
||||||
use collections::TreeMap;
|
use collections::TreeMap;
|
||||||
|
use core::cell::RefCell;
|
||||||
use serialize::json;
|
use serialize::json;
|
||||||
use serialize::json::ToJson;
|
use serialize::json::ToJson;
|
||||||
use std::io::TcpStream;
|
use std::io::TcpStream;
|
||||||
|
@ -105,6 +106,7 @@ pub struct ConsoleActor {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub pipeline: PipelineId,
|
pub pipeline: PipelineId,
|
||||||
pub script_chan: Sender<DevtoolScriptControlMsg>,
|
pub script_chan: Sender<DevtoolScriptControlMsg>,
|
||||||
|
pub streams: RefCell<Vec<TcpStream>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Actor for ConsoleActor {
|
impl Actor for ConsoleActor {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
/// Supports dynamic attaching and detaching which control notifications of navigation, etc.
|
/// Supports dynamic attaching and detaching which control notifications of navigation, etc.
|
||||||
|
|
||||||
use actor::{Actor, ActorRegistry};
|
use actor::{Actor, ActorRegistry};
|
||||||
|
use actors::console::ConsoleActor;
|
||||||
use protocol::JsonPacketStream;
|
use protocol::JsonPacketStream;
|
||||||
|
|
||||||
use serialize::json;
|
use serialize::json;
|
||||||
|
@ -74,7 +75,7 @@ impl Actor for TabActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_message(&self,
|
fn handle_message(&self,
|
||||||
_registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
_msg: &json::JsonObject,
|
_msg: &json::JsonObject,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> bool {
|
||||||
|
@ -95,15 +96,21 @@ impl Actor for TabActor {
|
||||||
javascriptEnabled: true,
|
javascriptEnabled: true,
|
||||||
traits: TabTraits,
|
traits: TabTraits,
|
||||||
};
|
};
|
||||||
|
let console_actor = registry.find::<ConsoleActor>(self.console.as_slice());
|
||||||
|
console_actor.streams.borrow_mut().push(stream.clone());
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: The current implementation won't work for multiple connections. Need to ensure 105
|
||||||
|
// that the correct stream is removed.
|
||||||
"detach" => {
|
"detach" => {
|
||||||
let msg = TabDetachedReply {
|
let msg = TabDetachedReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
__type__: "detached".to_string(),
|
__type__: "detached".to_string(),
|
||||||
};
|
};
|
||||||
|
let console_actor = registry.find::<ConsoleActor>(self.console.as_slice());
|
||||||
|
console_actor.streams.borrow_mut().pop();
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ use servo_msg::constellation_msg::PipelineId;
|
||||||
use servo_util::task::spawn_named;
|
use servo_util::task::spawn_named;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::comm;
|
use std::comm;
|
||||||
use std::comm::{Disconnected, Empty};
|
use std::comm::{Disconnected, Empty};
|
||||||
use std::io::{TcpListener, TcpStream};
|
use std::io::{TcpListener, TcpStream};
|
||||||
|
@ -87,6 +88,8 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
|
|
||||||
let mut accepted_connections: Vec<TcpStream> = Vec::new();
|
let mut accepted_connections: Vec<TcpStream> = Vec::new();
|
||||||
|
|
||||||
|
let mut actor_pipelines: HashMap<PipelineId, String> = HashMap::new();
|
||||||
|
|
||||||
/// Process the input from a single devtools client until EOF.
|
/// Process the input from a single devtools client until EOF.
|
||||||
fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) {
|
fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) {
|
||||||
println!("connection established to {}", stream.peer_name().unwrap());
|
println!("connection established to {}", stream.peer_name().unwrap());
|
||||||
|
@ -114,7 +117,8 @@ 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>) {
|
sender: Sender<DevtoolScriptControlMsg>,
|
||||||
|
actor_pipelines: &mut HashMap<PipelineId, String>) {
|
||||||
let mut actors = actors.lock();
|
let mut actors = actors.lock();
|
||||||
|
|
||||||
//TODO: move all this actor creation into a constructor method on TabActor
|
//TODO: move all this actor creation into a constructor method on TabActor
|
||||||
|
@ -123,6 +127,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
name: actors.new_name("console"),
|
name: actors.new_name("console"),
|
||||||
script_chan: sender.clone(),
|
script_chan: sender.clone(),
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
|
streams: RefCell::new(Vec::new()),
|
||||||
};
|
};
|
||||||
let inspector = InspectorActor {
|
let inspector = InspectorActor {
|
||||||
name: actors.new_name("inspector"),
|
name: actors.new_name("inspector"),
|
||||||
|
@ -146,6 +151,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
(tab, console, inspector)
|
(tab, console, inspector)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
actor_pipelines.insert(pipeline, tab.name.clone());
|
||||||
actors.register(box tab);
|
actors.register(box tab);
|
||||||
actors.register(box console);
|
actors.register(box console);
|
||||||
actors.register(box inspector);
|
actors.register(box inspector);
|
||||||
|
@ -162,7 +168,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
||||||
Err(ref e) if e.kind == TimedOut => {
|
Err(ref e) if e.kind == TimedOut => {
|
||||||
match receiver.try_recv() {
|
match receiver.try_recv() {
|
||||||
Ok(ServerExitMsg) | Err(Disconnected) => break,
|
Ok(ServerExitMsg) | Err(Disconnected) => break,
|
||||||
Ok(NewGlobal(id, sender)) => handle_new_global(actors.clone(), id, sender),
|
Ok(NewGlobal(id, sender)) => handle_new_global(actors.clone(), id, sender, &mut actor_pipelines),
|
||||||
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
|
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue