Skip to content

Commit f06976e

Browse files
committed
docs: update some UDP server comments
1 parent 89bb735 commit f06976e

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

src/servers/udp/server/mod.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
//! Module to handle the UDP server instances.
2-
//!
3-
//! There are two main types in this module:
4-
//!
5-
//! - [`UdpServer`]: a controller to start and stop the server.
6-
//! - [`Udp`]: the server launcher.
7-
//!
8-
//! The `UdpServer` is an state machine for a given configuration. This struct
9-
//! represents concrete configuration and state. It allows to start and
10-
//! stop the server but always keeping the same configuration.
11-
//!
12-
//! The `Udp` is the server launcher. It's responsible for launching the UDP
13-
//! but without keeping any state.
14-
//!
15-
//! For the time being, the `UdpServer` is only used for testing purposes,
16-
//! because we want to be able to start and stop the server multiple times, and
17-
//! we want to know the bound address and the current state of the server.
18-
//! In production, the `Udp` launcher is used directly.
19-
202
use std::fmt::Debug;
213

224
use super::RawRequest;
@@ -37,7 +19,7 @@ pub mod states;
3719
///
3820
/// Some errors triggered while stopping the server are:
3921
///
40-
/// - The [`UdpServer`] cannot send the shutdown signal to the spawned UDP service thread.
22+
/// - The [`Server`] cannot send the shutdown signal to the spawned UDP service thread.
4123
#[derive(Debug)]
4224
pub enum UdpError {
4325
/// Any kind of error starting or stopping the server.
@@ -92,7 +74,7 @@ mod tests {
9274

9375
tokio::time::sleep(Duration::from_secs(1)).await;
9476

95-
assert_eq!(stopped.state.launcher.bind_to, bind_to);
77+
assert_eq!(stopped.state.spawner.bind_to, bind_to);
9678
}
9779

9880
#[tokio::test]
@@ -116,7 +98,7 @@ mod tests {
11698

11799
tokio::time::sleep(Duration::from_secs(1)).await;
118100

119-
assert_eq!(stopped.state.launcher.bind_to, bind_to);
101+
assert_eq!(stopped.state.spawner.bind_to, bind_to);
120102
}
121103
}
122104

src/servers/udp/server/spawner.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! A thin wrapper for tokio spawn to launch the UDP server launcher as a new task.
12
use std::net::SocketAddr;
23
use std::sync::Arc;
34

@@ -16,21 +17,22 @@ pub struct Spawner {
1617
}
1718

1819
impl Spawner {
19-
/// It spawns a new tasks to run the UDP server instance.
20+
/// It spawns a new task to run the UDP server instance.
2021
///
2122
/// # Panics
2223
///
2324
/// It would panic if unable to resolve the `local_addr` from the supplied ´socket´.
24-
pub fn start(
25+
pub fn spawn_launcher(
2526
&self,
2627
tracker: Arc<Tracker>,
2728
tx_start: oneshot::Sender<Started>,
2829
rx_halt: oneshot::Receiver<Halted>,
2930
) -> JoinHandle<Spawner> {
30-
let launcher = Spawner::new(self.bind_to);
31+
let spawner = Self::new(self.bind_to);
32+
3133
tokio::spawn(async move {
32-
Launcher::run_with_graceful_shutdown(tracker, launcher.bind_to, tx_start, rx_halt).await;
33-
launcher
34+
Launcher::run_with_graceful_shutdown(tracker, spawner.bind_to, tx_start, rx_halt).await;
35+
spawner
3436
})
3537
}
3638
}

src/servers/udp/server/states.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub type RunningUdpServer = Server<Running>;
2525
/// A stopped UDP server state.
2626
2727
pub struct Stopped {
28-
pub launcher: Spawner,
28+
pub spawner: Spawner,
2929
}
3030

3131
/// A running UDP server state.
@@ -40,9 +40,9 @@ pub struct Running {
4040
impl Server<Stopped> {
4141
/// Creates a new `UdpServer` instance in `stopped`state.
4242
#[must_use]
43-
pub fn new(launcher: Spawner) -> Self {
43+
pub fn new(spawner: Spawner) -> Self {
4444
Self {
45-
state: Stopped { launcher },
45+
state: Stopped { spawner },
4646
}
4747
}
4848

@@ -64,7 +64,7 @@ impl Server<Stopped> {
6464
assert!(!tx_halt.is_closed(), "Halt channel for UDP tracker should be open");
6565

6666
// May need to wrap in a task to about a tokio bug.
67-
let task = self.state.launcher.start(tracker, tx_start, rx_halt);
67+
let task = self.state.spawner.spawn_launcher(tracker, tx_start, rx_halt);
6868

6969
let binding = rx_start.await.expect("it should be able to start the service").address;
7070
let local_addr = format!("udp://{binding}");
@@ -107,7 +107,7 @@ impl Server<Running> {
107107
let launcher = self.state.task.await.expect("it should shutdown service");
108108

109109
let stopped_api_server: Server<Stopped> = Server {
110-
state: Stopped { launcher },
110+
state: Stopped { spawner: launcher },
111111
};
112112

113113
Ok(stopped_api_server)

0 commit comments

Comments
 (0)