aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2015-02-16 22:38:34 -0800
committerSteven Fackler <[email protected]>2015-02-16 22:38:34 -0800
commite52d02171bb29f18a1f9580cadac076bafb81abe (patch)
tree036f84381a3a67a697d3a34126bcdbaff2cf325a /openssl/src
parentDeal with openssl errors in read (diff)
downloadrust-openssl-e52d02171bb29f18a1f9580cadac076bafb81abe.tar.xz
rust-openssl-e52d02171bb29f18a1f9580cadac076bafb81abe.zip
Properly handle errors in write
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/ssl/mod.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 0c698f54..a16f7483 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -38,19 +38,19 @@ fn init() {
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum SslMethod {
#[cfg(feature = "sslv2")]
- /// Only support the SSLv2 protocol, requires `feature="sslv2"`
+ /// Only support the SSLv2 protocol, requires the `sslv2` feature.
Sslv2,
- /// Support the SSLv2, SSLv3 and TLSv1 protocols
+ /// Support the SSLv2, SSLv3 and TLSv1 protocols.
Sslv23,
- /// Only support the SSLv3 protocol
+ /// Only support the SSLv3 protocol.
Sslv3,
- /// Only support the TLSv1 protocol
+ /// Only support the TLSv1 protocol.
Tlsv1,
#[cfg(feature = "tlsv1_1")]
- /// Support TLSv1.1 protocol, requires `feature="tlsv1_1"`
+ /// Support TLSv1.1 protocol, requires the `tlsv1_1` feature.
Tlsv1_1,
#[cfg(feature = "tlsv1_2")]
- /// Support TLSv1.2 protocol, requires `feature="tlsv1_2"`
+ /// Support TLSv1.2 protocol, requires the `tlsv1_2` feature.
Tlsv1_2,
}
@@ -552,17 +552,18 @@ impl<S: Stream> Reader for SslStream<S> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
match self.in_retry_wrapper(|ssl| { ssl.read(buf) }) {
Ok(len) => Ok(len as usize),
- Err(SslSessionClosed) =>
+ Err(SslSessionClosed) => {
Err(IoError {
kind: EndOfFile,
desc: "SSL session closed",
detail: None
- }),
+ })
+ }
Err(StreamError(e)) => Err(e),
Err(e @ OpenSslErrors(_)) => {
Err(IoError {
kind: OtherIoError,
- desc: "SSL error",
+ desc: "OpenSSL error",
detail: Some(format!("{}", e)),
})
}
@@ -571,15 +572,25 @@ impl<S: Stream> Reader for SslStream<S> {
}
impl<S: Stream> Writer for SslStream<S> {
- fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
- let mut start = 0;
- while start < buf.len() {
- let ret = self.in_retry_wrapper(|ssl| {
- ssl.write_all(buf.split_at(start).1)
- });
- match ret {
- Ok(len) => start += len as usize,
- _ => unreachable!()
+ fn write_all(&mut self, mut buf: &[u8]) -> IoResult<()> {
+ while !buf.is_empty() {
+ match self.in_retry_wrapper(|ssl| ssl.write_all(buf)) {
+ Ok(len) => buf = &buf[len as usize..],
+ Err(SslSessionClosed) => {
+ return Err(IoError {
+ kind: EndOfFile,
+ desc: "SSL session closed",
+ detail: None,
+ });
+ }
+ Err(StreamError(e)) => return Err(e),
+ Err(e @ OpenSslErrors(_)) => {
+ return Err(IoError {
+ kind: OtherIoError,
+ desc: "OpenSSL error",
+ detail: Some(format!("{}", e)),
+ });
+ }
}
try!(self.write_through());
}