refactor DNS resolver construction

- System Conf is read as `ClientBuilder::build()` time, providing the
  error earlier.
- If there is an error reading the resolve system conf, a better error
  is reported.
- Resolver only needs to lock a mutex once to spawn the background task,
  instead of every single `resolve` call.
This commit is contained in:
Sean McArthur
2019-01-10 11:17:09 -08:00
parent b129ab0bb4
commit b71787be86
6 changed files with 83 additions and 53 deletions

View File

@@ -75,7 +75,8 @@ impl ClientBuilder {
///
/// # Errors
///
/// This method fails if native TLS backend cannot be initialized.
/// This method fails if TLS backend cannot be initialized, or the resolver
/// cannot load the system configuration.
pub fn build(self) -> ::Result<Client> {
ClientHandle::new(self).map(|handle| Client {
inner: handle,
@@ -300,13 +301,15 @@ impl Client {
///
/// # Panic
///
/// This method panics if native TLS backend cannot be created or
/// initialized. Use `Client::builder()` if you wish to handle the failure
/// as an `Error` instead of panicking.
/// This method panics if TLS backend cannot initialized, or the resolver
/// cannot load the system configuration.
///
/// Use `Client::builder()` if you wish to handle the failure as an `Error`
/// instead of panicking.
pub fn new() -> Client {
ClientBuilder::new()
.build()
.expect("Client failed to initialize")
.expect("Client::new()")
}
/// Creates a `ClientBuilder` to configure a `Client`.