From 0e3678d2d6b4f4c0f0f6be7218b01e2b9e6e3fe3 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 25 Jun 2024 08:02:05 +0100 Subject: [PATCH] refactor: rename Socket to BoundSocket and fix format errors" --- src/lib.rs | 2 +- src/servers/udp/server.rs | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bb6826dd..cf283441 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -494,7 +494,7 @@ pub mod bootstrap; pub mod console; pub mod core; pub mod servers; -pub mod shared; +pub mod shared; #[macro_use] extern crate lazy_static; diff --git a/src/servers/udp/server.rs b/src/servers/udp/server.rs index af52e2de..3fb49423 100644 --- a/src/servers/udp/server.rs +++ b/src/servers/udp/server.rs @@ -235,11 +235,11 @@ impl Drop for ActiveRequests { } /// Wrapper for Tokio [`UdpSocket`][`tokio::net::UdpSocket`] that is bound to a particular socket. -struct Socket { +struct BoundSocket { socket: Arc, } -impl Socket { +impl BoundSocket { async fn new(addr: SocketAddr) -> Result> { let socket = tokio::net::UdpSocket::bind(addr).await; @@ -257,7 +257,7 @@ impl Socket { } } -impl Deref for Socket { +impl Deref for BoundSocket { type Target = tokio::net::UdpSocket; fn deref(&self) -> &Self::Target { @@ -265,7 +265,7 @@ impl Deref for Socket { } } -impl Debug for Socket { +impl Debug for BoundSocket { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let local_addr = match self.socket.local_addr() { Ok(socket) => format!("Receiving From: {socket}"), @@ -334,7 +334,7 @@ impl Udp { format!("Halting UDP Service Bound to Socket: {bind_to}"), )); - let socket = tokio::time::timeout(Duration::from_millis(5000), Socket::new(bind_to)) + let socket = tokio::time::timeout(Duration::from_millis(5000), BoundSocket::new(bind_to)) .await .expect("it should bind to the socket within five seconds"); @@ -543,17 +543,14 @@ impl Udp { #[cfg(test)] mod tests { - use std::{sync::Arc, time::Duration}; + use std::sync::Arc; + use std::time::Duration; use torrust_tracker_test_helpers::configuration::ephemeral_mode_public; - use crate::{ - bootstrap::app::initialize_with_configuration, - servers::{ - registar::Registar, - udp::server::{Launcher, UdpServer}, - }, - }; + use crate::bootstrap::app::initialize_with_configuration; + use crate::servers::registar::Registar; + use crate::servers::udp::server::{Launcher, UdpServer}; #[tokio::test] async fn it_should_be_able_to_start_and_stop() {