use std::io::net::ip::SocketAddr;
use std::io::net::tcp::TcpStream;
use std::io::{IoResult, IoError, InvalidInput};
use connecter::Connecter;
pub enum NetworkStream {
NormalStream(TcpStream),
}
impl Connecter for NetworkStream {
fn connect(addr: SocketAddr, _host: &str, use_ssl: bool) -> IoResult<NetworkStream> {
if use_ssl {
Err(IoError {
kind: InvalidInput,
desc: "http crate was compiled without SSL support",
detail: None,
})
} else {
let stream = try!(TcpStream::connect(addr));
Ok(NormalStream(stream))
}
}
}
impl Reader for NetworkStream {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
match *self {
NormalStream(ref mut ns) => ns.read(buf),
}
}
}
impl Writer for NetworkStream {
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
match *self {
NormalStream(ref mut ns) => ns.write(buf),
}
}
fn flush(&mut self) -> IoResult<()> {
match *self {
NormalStream(ref mut ns) => ns.flush(),
}
}
}