diff options
| author | Steven Fackler <[email protected]> | 2015-10-21 12:27:41 -0400 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2015-10-21 12:27:41 -0400 |
| commit | c897837e4800c93f18d4d33c27974f63dc1f2a5e (patch) | |
| tree | a80fcebc4891737bc833a51b4cf5034dcb63ab6f /openssl/src/ssl/error.rs | |
| parent | Merge pull request #290 from jimmycuadra/master (diff) | |
| parent | Nonblocking streams support. (diff) | |
| download | rust-openssl-c897837e4800c93f18d4d33c27974f63dc1f2a5e.tar.xz rust-openssl-c897837e4800c93f18d4d33c27974f63dc1f2a5e.zip | |
Merge pull request #272 from dropbox/async_support
Nonblocking Socket 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 { |