Don't panic if spirc terminates prematurely.

Instead attempt to reconnect and wait for new client connections.
This commit is contained in:
Konstantin Seiler 2020-01-23 01:24:59 +11:00
parent ea1e0925dc
commit 719943aec9

View file

@ -381,6 +381,7 @@ struct Main {
connect: Box<Future<Item = Session, Error = io::Error>>, connect: Box<Future<Item = Session, Error = io::Error>>,
shutdown: bool, shutdown: bool,
last_credentials: Option<Credentials>,
player_event_channel: Option<UnboundedReceiver<PlayerEvent>>, player_event_channel: Option<UnboundedReceiver<PlayerEvent>>,
player_event_program: Option<String>, player_event_program: Option<String>,
@ -404,6 +405,7 @@ impl Main {
spirc: None, spirc: None,
spirc_task: None, spirc_task: None,
shutdown: false, shutdown: false,
last_credentials: None,
signal: Box::new(tokio_signal::ctrl_c().flatten_stream()), signal: Box::new(tokio_signal::ctrl_c().flatten_stream()),
player_event_channel: None, player_event_channel: None,
@ -425,6 +427,7 @@ impl Main {
} }
fn credentials(&mut self, credentials: Credentials) { fn credentials(&mut self, credentials: Credentials) {
self.last_credentials = Some(credentials.clone());
let config = self.session_config.clone(); let config = self.session_config.clone();
let handle = self.handle.clone(); let handle = self.handle.clone();
@ -502,6 +505,10 @@ impl Future for Main {
} else { } else {
warn!("Spirc shut down unexpectedly"); warn!("Spirc shut down unexpectedly");
self.spirc_task = None; self.spirc_task = None;
if let Some(credentials) = self.last_credentials.clone() {
self.credentials(credentials);
progress = true;
}
} }
} }
} }