Support for Separated Read Write

This commit is contained in:
Sagar Muchhal 2014-12-03 21:14:03 -05:00 committed by Josh Matthews
parent ad9aedac77
commit 75ffda9fb8
3 changed files with 18 additions and 3 deletions

View file

@ -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 {

View file

@ -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
}