Skip to content

Commit

Permalink
Also update error handling in tls
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jan 14, 2018
1 parent 838f4ca commit ba6577d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::net::TcpStream;
use proto::{self, Reconnect};
use native_tls::TlsConnector;
use native_tls::TlsStream as NativeTlsStream;
use failure::Error;

/// A reconnectable stream encrypted with TLS.
///
Expand Down Expand Up @@ -39,20 +40,20 @@ impl TlsStream<TcpStream> {
/// ```
///
/// If `url` is given, but does not specify a port, it defaults to 7419.
pub fn connect(url: Option<&str>) -> io::Result<Self> {
TlsStream::with_connector(TlsConnector::builder().unwrap().build().unwrap(), url)
pub fn connect(url: Option<&str>) -> Result<Self, Error> {
TlsStream::with_connector(TlsConnector::builder()?.build()?, url)
}

/// Create a new TLS connection over TCP using a non-default TLS configuration.
///
/// See `connect` for details about the `url` parameter.
pub fn with_connector(tls: TlsConnector, url: Option<&str>) -> io::Result<Self> {
pub fn with_connector(tls: TlsConnector, url: Option<&str>) -> Result<Self, Error> {
let url = match url {
Some(url) => proto::url_parse(url),
None => proto::url_parse(&proto::get_env_url()),
}?;
let stream = TcpStream::connect(proto::host_from_url(&url))?;
TlsStream::new(stream, tls, url.host_str().unwrap())
Ok(TlsStream::new(stream, tls, url.host_str().unwrap())?)
}
}

Expand Down

0 comments on commit ba6577d

Please sign in to comment.