Fixed some deprecation errors in components/net.

This commit is contained in:
Avi Weinstock 2015-03-23 14:33:55 -04:00
parent 5ce7d8accf
commit cf0657a403
3 changed files with 18 additions and 21 deletions

View file

@ -13,8 +13,9 @@ use time::{Tm, now, at, Timespec};
use url::Url; use url::Url;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::i64; use std::i64;
use std::old_io::net::ip::IpAddr; use std::net::{Ipv4Addr, Ipv6Addr};
use std::time::Duration; use std::time::Duration;
use std::str::FromStr;
/// A stored cookie that wraps the definition in cookie-rs. This is used to implement /// A stored cookie that wraps the definition in cookie-rs. This is used to implement
/// various behaviours defined in the spec that rely on an associated request URL, /// various behaviours defined in the spec that rely on an associated request URL,
@ -121,7 +122,8 @@ impl Cookie {
} }
if string.ends_with(domain_string) if string.ends_with(domain_string)
&& string.char_at(string.len()-domain_string.len()-1) == '.' && string.char_at(string.len()-domain_string.len()-1) == '.'
&& string.parse::<IpAddr>().is_err() { && Ipv4Addr::from_str(string).is_err()
&& Ipv6Addr::from_str(string).is_err() {
return true; return true;
} }
false false

View file

@ -6,28 +6,24 @@ use resource_task::{ProgressMsg, Metadata, LoadData, start_sending, TargetedLoad
use resource_task::ProgressMsg::{Payload, Done}; use resource_task::ProgressMsg::{Payload, Done};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::old_io as io; use std::io;
use std::old_io::File; use std::fs::File;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use util::task::spawn_named; use util::task::spawn_named;
static READ_SIZE: uint = 8192; static READ_SIZE: uint = 8192;
fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>) fn read_all(reader: &mut io::Read, progress_chan: &Sender<ProgressMsg>)
-> Result<(), String> { -> Result<(), String> {
loop { loop {
let mut buf = vec!(); let mut buf = vec![0; READ_SIZE];
match reader.push_at_least(READ_SIZE, READ_SIZE, &mut buf) { match reader.read(buf.as_mut_slice()) {
Ok(_) => progress_chan.send(Payload(buf)).unwrap(), Ok(0) => return Ok(()),
Err(e) => match e.kind { Ok(n) => {
io::EndOfFile => { buf.truncate(n);
if buf.len() > 0 { progress_chan.send(Payload(buf)).unwrap();
progress_chan.send(Payload(buf)).unwrap(); },
} Err(e) => return Err(e.description().to_string()),
return Ok(());
}
_ => return Err(e.desc.to_string()),
}
} }
} }
} }
@ -44,13 +40,13 @@ pub fn factory(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {
let file_path: Result<Path, ()> = url.to_file_path(); let file_path: Result<Path, ()> = url.to_file_path();
match file_path { match file_path {
Ok(file_path) => { Ok(file_path) => {
match File::open_mode(&Path::new(file_path), io::Open, io::Read) { match File::open(&Path::new(file_path)) {
Ok(ref mut reader) => { Ok(ref mut reader) => {
let res = read_all(reader as &mut io::Stream, &progress_chan); let res = read_all(reader, &progress_chan);
progress_chan.send(Done(res)).unwrap(); progress_chan.send(Done(res)).unwrap();
} }
Err(e) => { Err(e) => {
progress_chan.send(Done(Err(e.desc.to_string()))).unwrap(); progress_chan.send(Done(Err(e.description().to_string()))).unwrap();
} }
} }
} }

View file

@ -8,7 +8,6 @@
#![feature(core)] #![feature(core)]
#![feature(int_uint)] #![feature(int_uint)]
#![feature(io)] #![feature(io)]
#![feature(old_io)]
#![feature(old_path)] #![feature(old_path)]
#![feature(path)] #![feature(path)]
#![feature(path_ext)] #![feature(path_ext)]