diff --git a/README.md b/README.md index fdfb21a..1435399 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ async fn main() { response.data.res_data.unwrap().check_data.domain_list .iter() .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available)); + + client.close().await.unwrap(); } ``` diff --git a/epp-client/src/config.rs b/epp-client/src/config.rs index 8227940..8a80290 100644 --- a/epp-client/src/config.rs +++ b/epp-client/src/config.rs @@ -50,8 +50,8 @@ use std::{fs, io}; /// Paths to the client certificate and client key PEM files #[derive(Serialize, Deserialize, Debug)] pub struct EppClientTlsFiles { - cert_chain: String, - key: String, + pub cert_chain: String, + pub key: String, } /// Connection details to connect to and authenticate with a registry diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index ba1a19e..f9b4eb6 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -46,7 +46,6 @@ //! } //! ``` -use futures::executor::block_on; use std::time::SystemTime; use std::{error::Error, fmt::Debug}; @@ -187,10 +186,10 @@ impl EppClient { self.transact::<_, EppLogoutResponse>(&epp_logout).await } -} -impl Drop for EppClient { - fn drop(&mut self) { - let _ = block_on(self.logout()); + pub async fn close(&mut self) -> Result<(), error::Error> { + self.logout().await?; + + Ok(self.connection.close().await?) } } diff --git a/epp-client/src/connection/registry.rs b/epp-client/src/connection/registry.rs index a76151f..beea771 100644 --- a/epp-client/src/connection/registry.rs +++ b/epp-client/src/connection/registry.rs @@ -1,7 +1,6 @@ //! Manages registry connections and reading/writing to them use bytes::BytesMut; -use futures::executor::block_on; use rustls::{OwnedTrustAnchor, RootCertStore}; use std::convert::TryInto; use std::sync::Arc; @@ -129,7 +128,7 @@ impl EppConnection { } /// Closes the socket - async fn close(&mut self) -> Result<(), Box> { + pub async fn close(&mut self) -> Result<(), Box> { info!("{}: Closing connection", self.registry); self.stream.writer.shutdown().await?; @@ -137,12 +136,6 @@ impl EppConnection { } } -impl Drop for EppConnection { - fn drop(&mut self) { - let _ = block_on(self.close()); - } -} - /// Establishes a TLS connection to a registry and returns a ConnectionStream instance containing the /// socket stream to read/write to the connection pub async fn epp_connect( diff --git a/epp-client/src/epp/request/contact/check.rs b/epp-client/src/epp/request/contact/check.rs index 053503f..4a35f23 100644 --- a/epp-client/src/epp/request/contact/check.rs +++ b/epp-client/src/epp/request/contact/check.rs @@ -51,6 +51,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppContactCheckResponse>(&contact_check).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppContactCheck = EppObject>; diff --git a/epp-client/src/epp/request/contact/create.rs b/epp-client/src/epp/request/contact/create.rs index 0b35bc2..5297ec3 100644 --- a/epp-client/src/epp/request/contact/create.rs +++ b/epp-client/src/epp/request/contact/create.rs @@ -68,6 +68,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppContactCreateResponse>(&contact_create).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppContactCreate = EppObject>; diff --git a/epp-client/src/epp/request/contact/delete.rs b/epp-client/src/epp/request/contact/delete.rs index 5c68107..9e5ce94 100644 --- a/epp-client/src/epp/request/contact/delete.rs +++ b/epp-client/src/epp/request/contact/delete.rs @@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppContactDelete = EppObject>; diff --git a/epp-client/src/epp/request/contact/info.rs b/epp-client/src/epp/request/contact/info.rs index 52055f9..50a9da5 100644 --- a/epp-client/src/epp/request/contact/info.rs +++ b/epp-client/src/epp/request/contact/info.rs @@ -54,6 +54,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppContactInfo = EppObject>; diff --git a/epp-client/src/epp/request/contact/update.rs b/epp-client/src/epp/request/contact/update.rs index 59afb46..791b5b4 100644 --- a/epp-client/src/epp/request/contact/update.rs +++ b/epp-client/src/epp/request/contact/update.rs @@ -64,6 +64,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppContactUpdateResponse>(&contact_update).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppContactUpdate = EppObject>; diff --git a/epp-client/src/epp/request/domain/check.rs b/epp-client/src/epp/request/domain/check.rs index 4ed1e25..8cdcfc0 100644 --- a/epp-client/src/epp/request/domain/check.rs +++ b/epp-client/src/epp/request/domain/check.rs @@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainCheck = EppObject>; diff --git a/epp-client/src/epp/request/domain/create.rs b/epp-client/src/epp/request/domain/create.rs index 696f9fa..30cb38c 100644 --- a/epp-client/src/epp/request/domain/create.rs +++ b/epp-client/src/epp/request/domain/create.rs @@ -72,6 +72,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainCreateResponse>(&domain_create).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainCreate = EppObject>; diff --git a/epp-client/src/epp/request/domain/delete.rs b/epp-client/src/epp/request/domain/delete.rs index 64a5117..7b47717 100644 --- a/epp-client/src/epp/request/domain/delete.rs +++ b/epp-client/src/epp/request/domain/delete.rs @@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainDeleteResponse>(&domain_delete).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainDelete = EppObject>; diff --git a/epp-client/src/epp/request/domain/info.rs b/epp-client/src/epp/request/domain/info.rs index 916ed30..986dff2 100644 --- a/epp-client/src/epp/request/domain/info.rs +++ b/epp-client/src/epp/request/domain/info.rs @@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainInfoResponse>(&domain_info).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainInfo = EppObject>; diff --git a/epp-client/src/epp/request/domain/renew.rs b/epp-client/src/epp/request/domain/renew.rs index 52d7cbe..ab93915 100644 --- a/epp-client/src/epp/request/domain/renew.rs +++ b/epp-client/src/epp/request/domain/renew.rs @@ -56,6 +56,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainRenewResponse>(&domain_renew).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainRenew = EppObject>; diff --git a/epp-client/src/epp/request/domain/rgp/report.rs b/epp-client/src/epp/request/domain/rgp/report.rs index c888a7e..a1ac3b2 100644 --- a/epp-client/src/epp/request/domain/rgp/report.rs +++ b/epp-client/src/epp/request/domain/rgp/report.rs @@ -79,6 +79,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainRgpRestoreReportResponse>(&domain_restore_report).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainRgpRestoreReport = diff --git a/epp-client/src/epp/request/domain/rgp/request.rs b/epp-client/src/epp/request/domain/rgp/request.rs index febd2ef..e4c89b0 100644 --- a/epp-client/src/epp/request/domain/rgp/request.rs +++ b/epp-client/src/epp/request/domain/rgp/request.rs @@ -56,6 +56,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainRgpRestoreRequestResponse>(&domain_restore_req).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainRgpRestoreRequest = diff --git a/epp-client/src/epp/request/domain/transfer.rs b/epp-client/src/epp/request/domain/transfer.rs index 3c63087..3be1e2f 100644 --- a/epp-client/src/epp/request/domain/transfer.rs +++ b/epp-client/src/epp/request/domain/transfer.rs @@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainTransferRequestResponse>(&domain_transfer_request).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainTransferRequest = EppObject>; @@ -100,6 +102,8 @@ pub type EppDomainTransferRequest = EppObject>; /// let response = client.transact::<_, EppDomainTransferApproveResponse>(&domain_transfer_approve).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainTransferApprove = EppObject>; @@ -148,6 +152,8 @@ pub type EppDomainTransferApprove = EppObject>; /// let response = client.transact::<_, EppDomainTransferRejectResponse>(&domain_transfer_reject).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainTransferReject = EppObject>; @@ -196,6 +202,8 @@ pub type EppDomainTransferReject = EppObject>; /// let response = client.transact::<_, EppDomainTransferCancelResponse>(&domain_transfer_cancel).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainTransferCancel = EppObject>; @@ -244,6 +252,8 @@ pub type EppDomainTransferCancel = EppObject>; /// let response = client.transact::<_, EppDomainTransferQueryResponse>(&domain_transfer_query).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainTransferQuery = EppObject>; diff --git a/epp-client/src/epp/request/domain/update.rs b/epp-client/src/epp/request/domain/update.rs index c16bd04..52224c8 100644 --- a/epp-client/src/epp/request/domain/update.rs +++ b/epp-client/src/epp/request/domain/update.rs @@ -76,6 +76,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppDomainUpdateResponse>(&domain_update).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppDomainUpdate = EppObject>>; diff --git a/epp-client/src/epp/request/host/check.rs b/epp-client/src/epp/request/host/check.rs index c0917c8..56ddafe 100644 --- a/epp-client/src/epp/request/host/check.rs +++ b/epp-client/src/epp/request/host/check.rs @@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppHostCheckResponse>(&host_check).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppHostCheck = EppObject>; diff --git a/epp-client/src/epp/request/host/create.rs b/epp-client/src/epp/request/host/create.rs index e16fadc..7f868a5 100644 --- a/epp-client/src/epp/request/host/create.rs +++ b/epp-client/src/epp/request/host/create.rs @@ -57,6 +57,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppHostCreateResponse>(&host_create).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppHostCreate = EppObject>; diff --git a/epp-client/src/epp/request/host/delete.rs b/epp-client/src/epp/request/host/delete.rs index bda9d45..8a85de3 100644 --- a/epp-client/src/epp/request/host/delete.rs +++ b/epp-client/src/epp/request/host/delete.rs @@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppHostDeleteResponse>(&host_delete).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppHostDelete = EppObject>; diff --git a/epp-client/src/epp/request/host/info.rs b/epp-client/src/epp/request/host/info.rs index 07ef154..bcfcfed 100644 --- a/epp-client/src/epp/request/host/info.rs +++ b/epp-client/src/epp/request/host/info.rs @@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppHostInfoResponse>(&host_info).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppHostInfo = EppObject>; diff --git a/epp-client/src/epp/request/host/update.rs b/epp-client/src/epp/request/host/update.rs index ff59e2c..d67445e 100644 --- a/epp-client/src/epp/request/host/update.rs +++ b/epp-client/src/epp/request/host/update.rs @@ -73,6 +73,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppHostUpdateResponse>(&host_update).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppHostUpdate = EppObject>; diff --git a/epp-client/src/epp/request/message/ack.rs b/epp-client/src/epp/request/message/ack.rs index a999519..46cfda8 100644 --- a/epp-client/src/epp/request/message/ack.rs +++ b/epp-client/src/epp/request/message/ack.rs @@ -47,6 +47,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppMessageAckResponse>(&message_ack).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppMessageAck = EppObject>; diff --git a/epp-client/src/epp/request/message/poll.rs b/epp-client/src/epp/request/message/poll.rs index 0dde150..71d39a3 100644 --- a/epp-client/src/epp/request/message/poll.rs +++ b/epp-client/src/epp/request/message/poll.rs @@ -48,6 +48,8 @@ use serde::{Deserialize, Serialize}; /// let response = client.transact::<_, EppMessagePollResponse>(&message_poll).await.unwrap(); /// /// println!("{:?}", response); +/// +/// client.close().await.unwrap(); /// } /// ``` pub type EppMessagePoll = EppObject>;