Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use crossbeam channel instead of servo channel. Fix rebase issues and…
… add comment
  • Loading branch information
ferjm committed Nov 26, 2018
1 parent ef57ecb commit 4561a97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions components/net/fetch/methods.rs
Expand Up @@ -640,7 +640,7 @@ fn scheme_fetch(

// Setup channel to receive cross-thread messages about the file fetch
// operation.
let (done_sender, done_receiver) = channel();
let (done_sender, done_receiver) = unbounded();
*done_chan = Some((done_sender.clone(), done_receiver));
*response.body.lock().unwrap() = ResponseBody::Receiving(vec![]);

Expand Down Expand Up @@ -687,12 +687,12 @@ fn scheme_fetch(
},
};

let mut response = Response::new(url);
let mut response = Response::new(url, ResourceFetchTiming::new(request.timing_type()));
if is_range_request {
partial_content(&mut response);
}

let (done_sender, done_receiver) = channel();
let (done_sender, done_receiver) = unbounded();
*done_chan = Some((done_sender.clone(), done_receiver));
*response.body.lock().unwrap() = ResponseBody::Receiving(vec![]);
let check_url_validity = true;
Expand Down
11 changes: 7 additions & 4 deletions components/net/filemanager_thread.rs
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::fetch::methods::{CancellationListener, Data, RangeRequestBounds};
use crossbeam_channel::Sender;
use embedder_traits::{EmbedderMsg, EmbedderProxy, FilterPattern};
use headers_ext::{ContentLength, ContentType, HeaderMap, HeaderMapExt};
use http::header::{self, HeaderValue};
Expand All @@ -17,7 +18,6 @@ use net_traits::filemanager_thread::{
use net_traits::http_percent_encode;
use net_traits::response::{Response, ResponseBody};
use servo_arc::Arc as ServoArc;
use servo_channel;
use servo_config::prefs::PREFS;
use std::collections::HashMap;
use std::fs::File;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl FileManager {
// in a separate thread.
pub fn fetch_file(
&self,
done_sender: &servo_channel::Sender<Data>,
done_sender: &Sender<Data>,
cancellation_listener: Arc<Mutex<CancellationListener>>,
id: Uuid,
check_url_validity: bool,
Expand Down Expand Up @@ -526,7 +526,7 @@ impl FileManagerStore {

fn fetch_blob_buf(
&self,
done_sender: &servo_channel::Sender<Data>,
done_sender: &Sender<Data>,
cancellation_listener: Arc<Mutex<CancellationListener>>,
id: &Uuid,
origin_in: &FileOrigin,
Expand Down Expand Up @@ -794,7 +794,7 @@ fn read_file_in_chunks(
}

pub fn fetch_file_in_chunks(
done_sender: servo_channel::Sender<Data>,
done_sender: Sender<Data>,
mut reader: BufReader<File>,
res_body: ServoArc<Mutex<ResponseBody>>,
cancellation_listener: Arc<Mutex<CancellationListener>>,
Expand All @@ -816,6 +816,9 @@ pub fn fetch_file_in_chunks(
let offset = usize::min(
{
if let Some(end) = range.end {
// HTTP Range requests are specified with closed ranges,
// while Rust uses half-open ranges. We add +1 here so
// we don't skip the last requested byte.
let remaining_bytes =
end as usize - range.start as usize - body.len() + 1;
if remaining_bytes <= FILE_CHUNK_SIZE {
Expand Down
3 changes: 1 addition & 2 deletions components/net/tests/fetch.rs
Expand Up @@ -38,7 +38,6 @@ use net_traits::response::{CacheState, Response, ResponseBody, ResponseType};
use net_traits::{
FetchTaskTarget, IncludeSubdomains, NetworkError, ReferrerPolicy, ResourceFetchTiming, ResourceTimingType,
};
use servo_channel::{channel, Sender};
use servo_url::{ImmutableOrigin, ServoUrl};
use std::fs::File;
use std::io::Read;
Expand Down Expand Up @@ -169,7 +168,7 @@ fn test_fetch_blob() {

let mut request = Request::new(url, Some(Origin::Origin(origin.origin())), None);

let (sender, receiver) = channel();
let (sender, receiver) = unbounded();

let mut target = FetchResponseCollector {
sender,
Expand Down

0 comments on commit 4561a97

Please sign in to comment.