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

@ -40,12 +40,14 @@ use js::jsval::UndefinedValue;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{Encoding, EncodingRef, DecoderTrap};
use net_traits::{Metadata, AsyncResponseListener};
use net_traits::{Metadata, AsyncResponseListener, AsyncResponseTarget};
use util::str::{DOMString, HTML_SPACE_CHARACTERS, StaticStringVec};
use html5ever::tree_builder::NextParserState;
use std::cell::{RefCell, Cell};
use std::mem;
use std::sync::mpsc;
use std::sync::{Arc, Mutex};
use std::thread;
use string_cache::Atom;
use url::{Url, UrlParser};
@ -330,12 +332,18 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement {
url: url.clone(),
}));
let (action_sender, action_receiver) = mpsc::channel();
let listener = box NetworkListener {
context: context,
script_chan: script_chan,
receiver: action_receiver,
};
let response_target = AsyncResponseTarget {
sender: action_sender,
};
thread::spawn(move || listener.run());
doc.r().load_async(LoadType::Script(url), listener);
doc.r().load_async(LoadType::Script(url), response_target);
if self.parser_inserted.get() {
doc.r().get_current_parser().unwrap().r().suspend();