Skip to content

Commit

Permalink
Rename terminate method to stop
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofl committed Feb 29, 2024
1 parent bca473a commit acfe956
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/servers/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl FTPRunner for Server {
let m = receiver.recv().await.unwrap();
let mut receiver2 = self.sender.subscribe();

if m.terminate { return };
if m.stop { return };
if m.connect {
// Define new server
let server =
Expand All @@ -49,7 +49,7 @@ impl FTPRunner for Server {
.shutdown_indicator(async move {
loop {
let m2 = receiver2.recv().await.unwrap();
if m2.terminate { break }
if m2.stop { break }
if m2.connect { continue } // Not for me. Go wait another msg
else { break }
}
Expand Down
4 changes: 2 additions & 2 deletions src/servers/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl HTTPRunner for Server {
info!("Started runner. Waiting to start...");
let m = receiver.recv().await.unwrap();

if m.terminate { return };
if m.stop { return };
if m.connect {
info!("Command received: connect...");
// Spin and await the actual server here
Expand All @@ -55,7 +55,7 @@ impl HTTPRunner for Server {
loop {
info!("Running and waiting for command to finish");
let m = receiver.recv().await.unwrap();
if m.terminate { return };
if m.stop { return };
if m.connect { continue } // Not for me. Go wait another msg
else { break }
}
Expand Down
12 changes: 6 additions & 6 deletions src/servers/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Protocol {
#[derive(Default, Clone, Debug)]
pub struct Message {
pub connect: bool,
pub terminate: bool,
pub stop: bool,
}

pub struct Server {
Expand Down Expand Up @@ -62,20 +62,20 @@ impl Server {
info!("Starting {} server bind to {}:{}", self.protocol.to_string(), self.bind_address, self.port);
info!("Serving {}", self.path.to_string_lossy());

let s = Message{connect: true, terminate: false};
let s = Message{connect: true, stop: false};
let _ = self.sender.send(s).map_err(|err| format!("Error sending message: {:?}", err))?;
Ok(())
}

pub fn terminate(&self){
pub fn stop(&self){
// Stop the serving loop to exit the application.
// Mostly required by the headless version (single sessions).

// First stop and to then terminate
// First stop and to then stop
let mut m = Message::default();
m.connect = false;
m.terminate = true;
// Send twice. Once to make sure the server is terminated (inner loop)
m.stop = true;
// Send twice. Once to make sure the server is stopped (inner loop)
// and the second to ensure runner exits.
let _ = self.sender.send(m.clone());
let _ = self.sender.send(m);
Expand Down
4 changes: 2 additions & 2 deletions src/servers/tftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TFTPRunner for Server {
loop {
let msg = receiver.recv().await.unwrap();

if msg.terminate { return };
if msg.stop { return };
if msg.connect {
let tsk = tokio::spawn({
let me = Arc::clone(&self);
Expand All @@ -60,7 +60,7 @@ impl TFTPRunner for Server {
if !msg.connect {
tsk.abort();
debug!("TFTP server stopped");
if msg.terminate { return };
if msg.stop { return };
}
}
}
Expand Down

0 comments on commit acfe956

Please sign in to comment.