aboutsummaryrefslogtreecommitdiff
path: root/ssl
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2014-02-04 18:42:32 -0800
committerSteven Fackler <[email protected]>2014-02-04 18:42:32 -0800
commit1a5e625b4f21c9b4870ef30ab1da3c1fed919672 (patch)
treed646e51e83df4c33cad2dba6fafce9a43fdd5366 /ssl
parentRemove unused FFI binding (diff)
downloadrust-openssl-1a5e625b4f21c9b4870ef30ab1da3c1fed919672.tar.xz
rust-openssl-1a5e625b4f21c9b4870ef30ab1da3c1fed919672.zip
Update for IO API update
The error handling needs to be redone still.
Diffstat (limited to 'ssl')
-rw-r--r--ssl/error.rs7
-rw-r--r--ssl/mod.rs33
-rw-r--r--ssl/tests.rs2
3 files changed, 26 insertions, 16 deletions
diff --git a/ssl/error.rs b/ssl/error.rs
index 769cc768..91e879c8 100644
--- a/ssl/error.rs
+++ b/ssl/error.rs
@@ -1,12 +1,13 @@
use std::libc::c_ulong;
+use std::io::IoError;
-use super::ffi;
+use ssl::ffi;
/// An SSL error
#[deriving(ToStr)]
pub enum SslError {
- /// The underlying stream has reported an EOF
- StreamEof,
+ /// The underlying stream has reported an error
+ StreamError(IoError),
/// The SSL session has been closed by the other end
SslSessionClosed,
/// An error in the OpenSSL library
diff --git a/ssl/mod.rs b/ssl/mod.rs
index 8a71f954..6381b754 100644
--- a/ssl/mod.rs
+++ b/ssl/mod.rs
@@ -1,11 +1,12 @@
+use extra::sync::one::{Once, ONCE_INIT};
use std::cast;
use std::libc::{c_int, c_void, c_char};
use std::ptr;
-use std::unstable::mutex::{Mutex, Once, ONCE_INIT};
-use std::io::{Stream, Reader, Writer};
+use std::io::{IoResult, IoError, OtherIoError, Stream, Reader, Writer};
+use std::unstable::mutex::Mutex;
use std::vec;
-use ssl::error::{SslError, SslSessionClosed, StreamEof};
+use ssl::error::{SslError, SslSessionClosed, StreamError};
pub mod error;
mod ffi;
@@ -467,12 +468,12 @@ impl<S: Stream> SslStream<S> {
ErrorWantRead => {
self.flush();
match self.stream.read(self.buf) {
- Some(len) =>
+ Ok(len) =>
self.ssl.get_rbio().write(self.buf.slice_to(len)),
- None => return Err(StreamEof)
+ Err(err) => return Err(StreamError(err))
}
}
- ErrorWantWrite => self.flush(),
+ ErrorWantWrite => { self.flush(); }
ErrorZeroReturn => return Err(SslSessionClosed),
ErrorSsl => return Err(SslError::get()),
_ => unreachable!()
@@ -482,26 +483,33 @@ impl<S: Stream> SslStream<S> {
fn write_through(&mut self) {
loop {
+ // TODO propogate errors
match self.ssl.get_wbio().read(self.buf) {
Some(len) => self.stream.write(self.buf.slice_to(len)),
None => break
- }
+ };
}
}
}
impl<S: Stream> Reader for SslStream<S> {
- fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
+ fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
match self.in_retry_wrapper(|ssl| { ssl.read(buf) }) {
- Ok(len) => Some(len as uint),
- Err(StreamEof) | Err(SslSessionClosed) => None,
+ Ok(len) => Ok(len as uint),
+ Err(SslSessionClosed) =>
+ Err(IoError {
+ kind: OtherIoError,
+ desc: "SSL session closed",
+ detail: None
+ }),
+ Err(StreamError(e)) => Err(e),
_ => unreachable!()
}
}
}
impl<S: Stream> Writer for SslStream<S> {
- fn write(&mut self, buf: &[u8]) {
+ fn write(&mut self, buf: &[u8]) -> IoResult<()> {
let mut start = 0;
while start < buf.len() {
let ret = self.in_retry_wrapper(|ssl| {
@@ -513,9 +521,10 @@ impl<S: Stream> Writer for SslStream<S> {
}
self.write_through();
}
+ Ok(())
}
- fn flush(&mut self) {
+ fn flush(&mut self) -> IoResult<()> {
self.write_through();
self.stream.flush()
}
diff --git a/ssl/tests.rs b/ssl/tests.rs
index 266acc4c..39a756cd 100644
--- a/ssl/tests.rs
+++ b/ssl/tests.rs
@@ -155,6 +155,6 @@ fn test_read() {
let mut stream = SslStream::new(&SslContext::new(Sslv23), stream);
stream.write("GET /\r\n\r\n".as_bytes());
stream.flush();
- let buf = stream.read_to_end();
+ let buf = stream.read_to_end().ok().expect("read error");
print!("{}", str::from_utf8(buf));
}