diff options
| author | Jamie Turner <[email protected]> | 2015-09-19 20:50:06 -0700 |
|---|---|---|
| committer | Jamie Turner <[email protected]> | 2015-10-20 23:14:26 -0700 |
| commit | c37767df8fc1775858cd573cbe4d5e3a17fbd370 (patch) | |
| tree | a80fcebc4891737bc833a51b4cf5034dcb63ab6f /openssl/src/ssl/error.rs | |
| parent | Merge pull request #290 from jimmycuadra/master (diff) | |
| download | rust-openssl-c37767df8fc1775858cd573cbe4d5e3a17fbd370.tar.xz rust-openssl-c37767df8fc1775858cd573cbe4d5e3a17fbd370.zip | |
Nonblocking streams support.
Diffstat (limited to 'openssl/src/ssl/error.rs')
| -rw-r--r-- | openssl/src/ssl/error.rs | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/openssl/src/ssl/error.rs b/openssl/src/ssl/error.rs index 9ff6cae9..0126b277 100644 --- a/openssl/src/ssl/error.rs +++ b/openssl/src/ssl/error.rs @@ -17,7 +17,20 @@ pub enum SslError { /// The SSL session has been closed by the other end SslSessionClosed, /// An error in the OpenSSL library - OpenSslErrors(Vec<OpensslError>) + OpenSslErrors(Vec<OpensslError>), +} + +/// An error on a nonblocking stream. +#[derive(Debug)] +pub enum NonblockingSslError { + /// A standard SSL error occurred. + SslError(SslError), + /// The OpenSSL library wants data from the remote socket; + /// the caller should wait for read readiness. + WantRead, + /// The OpenSSL library wants to send data to the remote socket; + /// the caller should wait for write readiness. + WantWrite, } impl fmt::Display for SslError { @@ -59,6 +72,35 @@ impl error::Error for SslError { } } +impl fmt::Display for NonblockingSslError { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.write_str(error::Error::description(self)) + } +} + +impl error::Error for NonblockingSslError { + fn description(&self) -> &str { + match *self { + NonblockingSslError::SslError(ref e) => e.description(), + NonblockingSslError::WantRead => "The OpenSSL library wants data from the remote socket", + NonblockingSslError::WantWrite => "The OpenSSL library want to send data to the remote socket", + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + NonblockingSslError::SslError(ref e) => e.cause(), + _ => None + } + } +} + +impl From<SslError> for NonblockingSslError { + fn from(e: SslError) -> NonblockingSslError { + NonblockingSslError::SslError(e) + } +} + /// An error from the OpenSSL library #[derive(Debug, Clone, PartialEq, Eq)] pub enum OpensslError { |