net: Use a thread for each AsyncResponseTarget to avoid having to send

trait objects across process boundaries.
This commit is contained in:
Patrick Walton 2015-07-09 16:50:06 -07:00
parent 9c9d7dc93b
commit 44d13f7fd4
10 changed files with 78 additions and 31 deletions

View file

@ -68,7 +68,7 @@ use msg::constellation_msg::{Failure, WindowSizeData, PipelineExitType};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::webdriver_msg::WebDriverScriptCommand;
use net_traits::LoadData as NetLoadData;
use net_traits::{ResourceTask, LoadConsumer, ControlMsg, Metadata};
use net_traits::{AsyncResponseTarget, ResourceTask, LoadConsumer, ControlMsg, Metadata};
use net_traits::{SerializableContentType, SerializableHeaders, SerializableMethod};
use net_traits::{SerializableUrl};
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask, ImageCacheResult};
@ -105,6 +105,7 @@ use std::rc::Rc;
use std::result::Result;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{channel, Sender, Receiver, Select};
use std::thread;
use time::Tm;
use hyper::header::{ContentType, HttpDate};
@ -1686,9 +1687,15 @@ impl ScriptTask {
let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, script_chan.clone(),
load_data.url.clone())));
let (action_sender, action_receiver) = channel();
let listener = box NetworkListener {
context: context,
script_chan: script_chan.clone(),
receiver: action_receiver,
};
thread::spawn(move || listener.run());
let response_target = AsyncResponseTarget {
sender: action_sender,
};
if load_data.url.scheme == "javascript" {
@ -1703,7 +1710,7 @@ impl ScriptTask {
data: load_data.data,
cors: None,
pipeline_id: Some(id),
}, LoadConsumer::Listener(listener))).unwrap();
}, LoadConsumer::Listener(response_target))).unwrap();
self.incomplete_loads.borrow_mut().push(incomplete);
}