2023-03-23 17:17:37 +00:00
|
|
|
use std::sync::mpsc::{Receiver, TryRecvError};
|
|
|
|
use log::{error, info};
|
2023-03-22 18:34:06 +00:00
|
|
|
use crate::config::TFClientConfig;
|
|
|
|
use crate::daemon::ThreadMessageSender;
|
|
|
|
|
|
|
|
pub enum APIWorkerMessage {
|
2023-03-23 17:17:37 +00:00
|
|
|
Shutdown
|
2023-03-22 18:34:06 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 17:17:37 +00:00
|
|
|
pub fn apiworker_main(_config: TFClientConfig, _transmitters: ThreadMessageSender, rx: Receiver<APIWorkerMessage>) {
|
|
|
|
loop {
|
|
|
|
match rx.try_recv() {
|
|
|
|
Ok(msg) => {
|
|
|
|
match msg {
|
|
|
|
APIWorkerMessage::Shutdown => {
|
|
|
|
info!("recv on command socket: shutdown, stopping");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
match e {
|
|
|
|
TryRecvError::Empty => {}
|
|
|
|
TryRecvError::Disconnected => {
|
|
|
|
error!("apiworker command socket disconnected, shutting down to prevent orphaning");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-22 18:34:06 +00:00
|
|
|
}
|