feat(lib): switch to non-blocking (asynchronous) IO
BREAKING CHANGE: This breaks a lot of the Client and Server APIs. Check the documentation for how Handlers can be used for asynchronous events.
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/error.rs
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/error.rs
									
									
									
									
									
								
							| @@ -7,7 +7,6 @@ use std::string::FromUtf8Error; | ||||
|  | ||||
| use httparse; | ||||
| use url; | ||||
| use solicit::http::HttpError as Http2Error; | ||||
|  | ||||
| #[cfg(feature = "openssl")] | ||||
| use openssl::ssl::error::SslError; | ||||
| @@ -18,10 +17,11 @@ use self::Error::{ | ||||
|     Version, | ||||
|     Header, | ||||
|     Status, | ||||
|     Timeout, | ||||
|     Io, | ||||
|     Ssl, | ||||
|     TooLarge, | ||||
|     Http2, | ||||
|     Incomplete, | ||||
|     Utf8 | ||||
| }; | ||||
|  | ||||
| @@ -42,14 +42,16 @@ pub enum Error { | ||||
|     Header, | ||||
|     /// A message head is too large to be reasonable. | ||||
|     TooLarge, | ||||
|     /// A message reached EOF before being a complete message. | ||||
|     Incomplete, | ||||
|     /// An invalid `Status`, such as `1337 ELITE`. | ||||
|     Status, | ||||
|     /// A timeout occurred waiting for an IO event. | ||||
|     Timeout, | ||||
|     /// An `io::Error` that occurred while trying to read or write to a network stream. | ||||
|     Io(IoError), | ||||
|     /// An error from a SSL library. | ||||
|     Ssl(Box<StdError + Send + Sync>), | ||||
|     /// An HTTP/2-specific error, coming from the `solicit` library. | ||||
|     Http2(Http2Error), | ||||
|     /// Parsing a field as string failed | ||||
|     Utf8(Utf8Error), | ||||
|  | ||||
| @@ -80,10 +82,11 @@ impl StdError for Error { | ||||
|             Header => "Invalid Header provided", | ||||
|             TooLarge => "Message head is too large", | ||||
|             Status => "Invalid Status provided", | ||||
|             Incomplete => "Message is incomplete", | ||||
|             Timeout => "Timeout", | ||||
|             Uri(ref e) => e.description(), | ||||
|             Io(ref e) => e.description(), | ||||
|             Ssl(ref e) => e.description(), | ||||
|             Http2(ref e) => e.description(), | ||||
|             Utf8(ref e) => e.description(), | ||||
|             Error::__Nonexhaustive(ref void) =>  match *void {} | ||||
|         } | ||||
| @@ -94,7 +97,6 @@ impl StdError for Error { | ||||
|             Io(ref error) => Some(error), | ||||
|             Ssl(ref error) => Some(&**error), | ||||
|             Uri(ref error) => Some(error), | ||||
|             Http2(ref error) => Some(error), | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| @@ -148,18 +150,11 @@ impl From<httparse::Error> for Error { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<Http2Error> for Error { | ||||
|     fn from(err: Http2Error) -> Error { | ||||
|         Error::Http2(err) | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use std::error::Error as StdError; | ||||
|     use std::io; | ||||
|     use httparse; | ||||
|     use solicit::http::HttpError as Http2Error; | ||||
|     use url; | ||||
|     use super::Error; | ||||
|     use super::Error::*; | ||||
| @@ -201,7 +196,6 @@ mod tests { | ||||
|  | ||||
|         from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => Io(..)); | ||||
|         from_and_cause!(url::ParseError::EmptyHost => Uri(..)); | ||||
|         from_and_cause!(Http2Error::UnknownStreamId => Http2(..)); | ||||
|  | ||||
|         from!(httparse::Error::HeaderName => Header); | ||||
|         from!(httparse::Error::HeaderName => Header); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user