From e1d9c956beb6921b0d549248bea3a6853fde5f46 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sat, 28 Sep 2024 01:08:16 -0500 Subject: fix: clean up unused code and fix TCP client --- src/service/tcp.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src/service/tcp.rs') diff --git a/src/service/tcp.rs b/src/service/tcp.rs index 5ec5f36..42791bc 100644 --- a/src/service/tcp.rs +++ b/src/service/tcp.rs @@ -1,9 +1,7 @@ use std::{fmt::Display, net::SocketAddr, time::Duration}; -use futures::Stream; use serde::Deserialize; use tokio::{io::Interest, net::TcpSocket, sync::watch::Sender}; -use tokio_stream::wrappers::WatchStream; use crate::{Error, Status}; @@ -21,7 +19,6 @@ impl Display for Tcp { } impl ServiceSpawner for Tcp { - #[tracing::instrument(skip(tx))] async fn spawn(self, tx: Sender) -> Result<(), Error> { let mut interval = tokio::time::interval(Duration::from_secs(5)); @@ -33,14 +30,11 @@ impl ServiceSpawner for Tcp { match sock.connect(self.address).await { Ok(conn) => { - tracing::info!("Connected"); + // TODO: figure out how to wait for connection to close + conn.ready(Interest::READABLE).await?; tx.send_if_modified(|s| s.update(Status::Pass)); - conn.ready(Interest::ERROR).await?; - tx.send_replace(Status::Fail(Some("Disconnected".into()))); - tracing::info!("Disconnected"); } Err(err) => { - tracing::error!("Failed to connect"); tx.send_if_modified(|s| s.update(err.into())); } }; @@ -48,14 +42,6 @@ impl ServiceSpawner for Tcp { } } -impl Tcp { - pub fn into_stream(self) -> impl Stream { - let (tx, rx) = tokio::sync::watch::channel(Status::default()); - tokio::spawn(self.spawn(tx)); - WatchStream::new(rx) - } -} - #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3-70-g09d2