Auto merge of #10725 - frewsxcv:net-cleanup, r=KiChjang

A few minor `net` component cleanups.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10725)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-20 05:30:59 +05:30
commit bebc1dc859
3 changed files with 15 additions and 20 deletions

View file

@ -66,7 +66,7 @@ impl Cookie {
// Step 7
let mut path = cookie.path.unwrap_or("".to_owned());
if path.is_empty() || path.as_bytes()[0] != b'/' {
if path.chars().next() != Some('/') {
let url_path = request.serialize_path();
let url_path = url_path.as_ref().map(|path| &**path);
path = Cookie::default_path(url_path.unwrap_or("")).to_owned();
@ -96,7 +96,7 @@ impl Cookie {
// http://tools.ietf.org/html/rfc6265#section-5.1.4
pub fn default_path(request_path: &str) -> &str {
// Step 2
if request_path.is_empty() || !request_path.starts_with("/") {
if request_path.chars().next() != Some('/') {
return "/";
}

View file

@ -44,17 +44,14 @@ fn read_block(reader: &mut File) -> Result<ReadStatus, String> {
fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener: &CancellationListener)
-> Result<LoadResult, String> {
loop {
if cancel_listener.is_cancelled() {
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
return Ok(LoadResult::Cancelled);
}
while !cancel_listener.is_cancelled() {
match try!(read_block(reader)) {
ReadStatus::Partial(buf) => progress_chan.send(Payload(buf)).unwrap(),
ReadStatus::EOF => return Ok(LoadResult::Finished),
}
}
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
Ok(LoadResult::Cancelled)
}
fn get_progress_chan(load_data: LoadData, file_path: PathBuf,

View file

@ -227,17 +227,15 @@ impl CancellationListener {
}
pub fn is_cancelled(&self) -> bool {
match self.cancel_resource {
Some(ref resource) => {
match resource.cancel_receiver.try_recv() {
Ok(_) => {
let resource = match self.cancel_resource {
Some(ref resource) => resource,
None => return false, // channel doesn't exist!
};
if resource.cancel_receiver.try_recv().is_ok() {
self.cancel_status.set(true);
true
},
Err(_) => self.cancel_status.get(),
}
},
None => false, // channel doesn't exist!
} else {
self.cancel_status.get()
}
}
}