Skip to content

Commit

Permalink
0.95.2 - Handle socketcan read timeout correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Sep 13, 2023
1 parent 965607c commit 44f10ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ecu_diagnostics"
version = "0.95.1"
version = "0.95.2"
authors = ["Ashcon Mohseninia <ashconm@outlook.com>"]
edition = "2021"
description = "A rust crate for ECU diagnostic servers and communication APIs"
Expand Down
3 changes: 2 additions & 1 deletion src/hardware/socketcan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl PacketChannel<CanFrame> for SocketCanCanChannel {
}
let channel = socketcan::CANSocket::open(&self.device.info.name)?;
channel.filter_accept_all()?;
channel.set_nonblocking(true)?;
channel.set_nonblocking(false)?;
self.channel = Some(channel);
self.device.canbus_active.store(true, Ordering::Relaxed);
Ok(())
Expand Down Expand Up @@ -153,6 +153,7 @@ impl PacketChannel<CanFrame> for SocketCanCanChannel {
let timeout = std::cmp::max(1, timeout_ms) as u128;
let mut result: Vec<CanFrame> = Vec::with_capacity(max);
self.safe_with_iface(|iface| {
iface.set_read_timeout(std::time::Duration::from_millis(timeout_ms as u64))?;
let start = Instant::now();
let mut read: socketcan::CANFrame;
while start.elapsed().as_millis() <= timeout {
Expand Down

0 comments on commit 44f10ad

Please sign in to comment.