mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
Added match for UnexpectedEOF when parsing action
This commit is contained in:
parent
7690095890
commit
ec6de604f9
@ -15,6 +15,7 @@ pub struct GpuStats {
|
||||
pub power_avg: i32,
|
||||
pub power_max: i32,
|
||||
pub fan_speed: i32,
|
||||
pub max_fan_speed: i32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@ -53,7 +54,6 @@ pub struct GpuInfo {
|
||||
pub link_speed: String,
|
||||
pub link_width: u8,
|
||||
pub vulkan_info: VulkanInfo,
|
||||
pub max_fan_speed: i32,
|
||||
}
|
||||
|
||||
impl GpuController {
|
||||
@ -171,7 +171,6 @@ impl GpuController {
|
||||
};
|
||||
|
||||
let vulkan_info = GpuController::get_vulkan_info(&model_id);
|
||||
let max_fan_speed = self.hw_mon.fan_max_speed;
|
||||
|
||||
GpuInfo {
|
||||
gpu_vendor: vendor,
|
||||
@ -186,7 +185,6 @@ impl GpuController {
|
||||
link_speed,
|
||||
link_width,
|
||||
vulkan_info,
|
||||
max_fan_speed,
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,6 +208,7 @@ impl GpuController {
|
||||
let gpu_temp = self.hw_mon.get_gpu_temp();
|
||||
let (power_avg, power_max) = (self.hw_mon.get_power_avg(), self.hw_mon.get_power_cap());
|
||||
let fan_speed = self.hw_mon.get_fan_speed();
|
||||
let max_fan_speed = self.hw_mon.fan_max_speed;
|
||||
|
||||
GpuStats {
|
||||
mem_total,
|
||||
@ -220,6 +219,7 @@ impl GpuController {
|
||||
power_avg,
|
||||
power_max,
|
||||
fan_speed,
|
||||
max_fan_speed,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,66 +113,73 @@ impl Daemon {
|
||||
stream.read_to_end(&mut buffer).unwrap();
|
||||
//log::trace!("finished reading, buffer size {}", buffer.len());
|
||||
log::trace!("Attempting to deserialize {:?}", &buffer);
|
||||
let action: Action = bincode::deserialize(&buffer).expect("Failed to deserialize buffer");
|
||||
//log::trace!("{:?}", action);
|
||||
|
||||
log::trace!("Executing action {:?}", action);
|
||||
let response: Result<DaemonResponse, DaemonError> = match action {
|
||||
Action::CheckAlive => Ok(DaemonResponse::OK),
|
||||
Action::GetGpus => {
|
||||
let mut gpus: HashMap<u32, String> = HashMap::new();
|
||||
for controller in gpu_controllers {
|
||||
gpus.insert(*controller.0, controller.1.gpu_info.gpu_model.clone());
|
||||
}
|
||||
Ok(DaemonResponse::Gpus(gpus))
|
||||
},
|
||||
Action::GetStats(i) => match gpu_controllers.get(&i) {
|
||||
Some(controller) => Ok(DaemonResponse::GpuStats(controller.get_stats())),
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::GetInfo(i) => match gpu_controllers.get(&i) {
|
||||
Some(controller) => Ok(DaemonResponse::GpuInfo(controller.gpu_info.clone())),
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::StartFanControl(i) => match gpu_controllers.get_mut(&i) {
|
||||
Some(controller) => match controller.start_fan_control() {
|
||||
Ok(_) => Ok(DaemonResponse::OK),
|
||||
Err(_) => Err(DaemonError::HWMonError),
|
||||
}
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::StopFanControl(i) => match gpu_controllers.get_mut(&i) {
|
||||
Some(controller) => match controller.stop_fan_control() {
|
||||
Ok(_) => Ok(DaemonResponse::OK),
|
||||
Err(_) => Err(DaemonError::HWMonError),
|
||||
},
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::GetFanControl(i) => match gpu_controllers.get(&i) {
|
||||
Some(controller) => Ok(DaemonResponse::FanControlInfo(controller.get_fan_control())),
|
||||
None => Err(DaemonError::InvalidID),
|
||||
}
|
||||
Action::SetFanCurve(i, curve) => match gpu_controllers.get_mut(&i) {
|
||||
Some(controller) => {
|
||||
match bincode::deserialize::<Action>(&buffer) {
|
||||
Ok(action) => {
|
||||
log::trace!("Executing action {:?}", action);
|
||||
let response: Result<DaemonResponse, DaemonError> = match action {
|
||||
Action::CheckAlive => Ok(DaemonResponse::OK),
|
||||
Action::GetGpus => {
|
||||
let mut gpus: HashMap<u32, String> = HashMap::new();
|
||||
for controller in gpu_controllers {
|
||||
gpus.insert(*controller.0, controller.1.gpu_info.gpu_model.clone());
|
||||
}
|
||||
Ok(DaemonResponse::Gpus(gpus))
|
||||
},
|
||||
Action::GetStats(i) => match gpu_controllers.get(&i) {
|
||||
Some(controller) => Ok(DaemonResponse::GpuStats(controller.get_stats())),
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::GetInfo(i) => match gpu_controllers.get(&i) {
|
||||
Some(controller) => Ok(DaemonResponse::GpuInfo(controller.gpu_info.clone())),
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::StartFanControl(i) => match gpu_controllers.get_mut(&i) {
|
||||
Some(controller) => match controller.start_fan_control() {
|
||||
Ok(_) => Ok(DaemonResponse::OK),
|
||||
Err(_) => Err(DaemonError::HWMonError),
|
||||
}
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::StopFanControl(i) => match gpu_controllers.get_mut(&i) {
|
||||
Some(controller) => match controller.stop_fan_control() {
|
||||
Ok(_) => Ok(DaemonResponse::OK),
|
||||
Err(_) => Err(DaemonError::HWMonError),
|
||||
},
|
||||
None => Err(DaemonError::InvalidID),
|
||||
},
|
||||
Action::GetFanControl(i) => match gpu_controllers.get(&i) {
|
||||
Some(controller) => Ok(DaemonResponse::FanControlInfo(controller.get_fan_control())),
|
||||
None => Err(DaemonError::InvalidID),
|
||||
}
|
||||
Action::SetFanCurve(i, curve) => match gpu_controllers.get_mut(&i) {
|
||||
Some(controller) => {
|
||||
|
||||
let mut buffer = Vec::new();
|
||||
stream.read_to_end(&mut buffer).unwrap();
|
||||
|
||||
controller.set_fan_curve(curve);
|
||||
|
||||
Ok(DaemonResponse::OK)
|
||||
},
|
||||
None => Err(DaemonError::InvalidID),
|
||||
}
|
||||
Action::Shutdown => std::process::exit(0),
|
||||
};
|
||||
let mut buffer = Vec::new();
|
||||
stream.read_to_end(&mut buffer).unwrap();
|
||||
|
||||
controller.set_fan_curve(curve);
|
||||
|
||||
Ok(DaemonResponse::OK)
|
||||
},
|
||||
None => Err(DaemonError::InvalidID),
|
||||
}
|
||||
Action::Shutdown => std::process::exit(0),
|
||||
};
|
||||
|
||||
log::trace!("Responding");
|
||||
stream.write_all(&bincode::serialize(&response).unwrap()).expect("Failed writing response");
|
||||
//stream
|
||||
// .shutdown(std::net::Shutdown::Write)
|
||||
// .expect("Could not shut down");
|
||||
log::trace!("Finished responding");
|
||||
},
|
||||
Err(_) => {
|
||||
println!("Failed deserializing action");
|
||||
}
|
||||
}
|
||||
|
||||
log::trace!("Responding");
|
||||
stream.write_all(&bincode::serialize(&response).unwrap()).expect("Failed writing response");
|
||||
//stream
|
||||
// .shutdown(std::net::Shutdown::Write)
|
||||
// .expect("Could not shut down");
|
||||
log::trace!("Finished responding");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user