mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +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 collections::TreeMap;
|
||||
use core::cell::RefCell;
|
||||
use serialize::json;
|
||||
use serialize::json::ToJson;
|
||||
use std::io::TcpStream;
|
||||
|
@ -105,6 +106,7 @@ pub struct ConsoleActor {
|
|||
pub name: String,
|
||||
pub pipeline: PipelineId,
|
||||
pub script_chan: Sender<DevtoolScriptControlMsg>,
|
||||
pub streams: RefCell<Vec<TcpStream>>,
|
||||
}
|
||||
|
||||
impl Actor for ConsoleActor {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
/// Supports dynamic attaching and detaching which control notifications of navigation, etc.
|
||||
|
||||
use actor::{Actor, ActorRegistry};
|
||||
use actors::console::ConsoleActor;
|
||||
use protocol::JsonPacketStream;
|
||||
|
||||
use serialize::json;
|
||||
|
@ -74,7 +75,7 @@ impl Actor for TabActor {
|
|||
}
|
||||
|
||||
fn handle_message(&self,
|
||||
_registry: &ActorRegistry,
|
||||
registry: &ActorRegistry,
|
||||
msg_type: &String,
|
||||
_msg: &json::JsonObject,
|
||||
stream: &mut TcpStream) -> bool {
|
||||
|
@ -95,15 +96,21 @@ impl Actor for TabActor {
|
|||
javascriptEnabled: true,
|
||||
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);
|
||||
true
|
||||
}
|
||||
|
||||
//FIXME: The current implementation won't work for multiple connections. Need to ensure 105
|
||||
// that the correct stream is removed.
|
||||
"detach" => {
|
||||
let msg = TabDetachedReply {
|
||||
from: self.name(),
|
||||
__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);
|
||||
true
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ use servo_msg::constellation_msg::PipelineId;
|
|||
use servo_util::task::spawn_named;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::comm;
|
||||
use std::comm::{Disconnected, Empty};
|
||||
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 actor_pipelines: HashMap<PipelineId, String> = HashMap::new();
|
||||
|
||||
/// 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());
|
||||
|
@ -114,7 +117,8 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
|||
// TODO: move this into the root or tab modules?
|
||||
fn handle_new_global(actors: Arc<Mutex<ActorRegistry>>,
|
||||
pipeline: PipelineId,
|
||||
sender: Sender<DevtoolScriptControlMsg>) {
|
||||
sender: Sender<DevtoolScriptControlMsg>,
|
||||
actor_pipelines: &mut HashMap<PipelineId, String>) {
|
||||
let mut actors = actors.lock();
|
||||
|
||||
//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"),
|
||||
script_chan: sender.clone(),
|
||||
pipeline: pipeline,
|
||||
streams: RefCell::new(Vec::new()),
|
||||
};
|
||||
let inspector = InspectorActor {
|
||||
name: actors.new_name("inspector"),
|
||||
|
@ -146,6 +151,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
|||
(tab, console, inspector)
|
||||
};
|
||||
|
||||
actor_pipelines.insert(pipeline, tab.name.clone());
|
||||
actors.register(box tab);
|
||||
actors.register(box console);
|
||||
actors.register(box inspector);
|
||||
|
@ -162,7 +168,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
|
|||
Err(ref e) if e.kind == TimedOut => {
|
||||
match receiver.try_recv() {
|
||||
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)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue