mirror of
https://github.com/arampoire/nut-rs.git
synced 2025-12-01 00:30:23 -05:00
parent
c56be76906
commit
11f70642dd
6 changed files with 34 additions and 8 deletions
|
|
@ -26,6 +26,12 @@ impl Connection {
|
|||
Ok(conn)
|
||||
}
|
||||
|
||||
/// Gracefully closes the connection.
|
||||
pub fn close(mut self) -> crate::Result<()> {
|
||||
self.logout()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sends username and password, as applicable.
|
||||
fn login(&mut self, config: &Config) -> crate::Result<()> {
|
||||
if let Some(auth) = config.auth.clone() {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ pub enum Command<'a> {
|
|||
StartTLS,
|
||||
/// Queries the network version.
|
||||
NetworkVersion,
|
||||
/// Queries the server version
|
||||
/// Queries the server version.
|
||||
Version,
|
||||
/// Gracefully shuts down the connection.
|
||||
Logout,
|
||||
}
|
||||
|
||||
impl<'a> Command<'a> {
|
||||
|
|
@ -30,6 +32,7 @@ impl<'a> Command<'a> {
|
|||
Self::StartTLS => "STARTTLS",
|
||||
Self::NetworkVersion => "NETVER",
|
||||
Self::Version => "VER",
|
||||
Self::Logout => "LOGOUT",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -503,4 +506,9 @@ implement_action_commands! {
|
|||
pub(crate) fn set_password(password: &str) {
|
||||
Command::SetPassword(password)
|
||||
}
|
||||
|
||||
/// Gracefully shuts down the connection.
|
||||
pub(crate) fn logout() {
|
||||
Command::Logout
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,12 @@ impl Connection {
|
|||
Ok(conn)
|
||||
}
|
||||
|
||||
/// Gracefully closes the connection.
|
||||
pub async fn close(mut self) -> crate::Result<()> {
|
||||
self.logout().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sends username and password, as applicable.
|
||||
async fn login(&mut self, config: &Config) -> crate::Result<()> {
|
||||
if let Some(auth) = config.auth.clone() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue