Offer API to reconnect an EppClient

This commit is contained in:
Dirkjan Ochtman 2022-02-05 21:59:44 +01:00 committed by masalachai
parent 36558c429c
commit 386638b6ca
2 changed files with 12 additions and 0 deletions

View File

@ -148,6 +148,10 @@ impl<C: Connector> EppClient<C> {
GreetingDocument::deserialize(&self.connection.greeting).map(|obj| obj.data)
}
pub async fn reconnect(&mut self) -> Result<(), Error> {
self.connection.reconnect().await
}
pub async fn shutdown(mut self) -> Result<(), Error> {
self.connection.shutdown().await
}

View File

@ -14,6 +14,7 @@ use crate::error::Error;
/// EPP Connection struct with some metadata for the connection
pub(crate) struct EppConnection<C: Connector> {
registry: String,
connector: C,
stream: C::Connection,
pub greeting: String,
timeout: Duration,
@ -28,6 +29,7 @@ impl<C: Connector> EppConnection<C> {
let mut this = Self {
registry,
stream: connector.connect(timeout).await?,
connector,
greeting: String::new(),
timeout,
};
@ -88,6 +90,12 @@ impl<C: Connector> EppConnection<C> {
Ok(String::from_utf8(buf)?)
}
pub(crate) async fn reconnect(&mut self) -> Result<(), Error> {
self.stream = self.connector.connect(self.timeout).await?;
self.greeting = self.get_epp_response().await?;
Ok(())
}
/// Sends an EPP XML request to the registry and return the response
/// receieved to the request
pub(crate) async fn transact(&mut self, content: &str) -> Result<String, Error> {