Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions rodbus/src/client/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,13 @@ impl ClientLoop {
/// Run requests over `io` until the session ends, leaving no partial frame behind for the next
pub(crate) async fn run(&mut self, io: &mut PhysLayer) -> SessionEnd {
self.timeout_counter.reset();
let err = loop {
loop {
if let Err(err) = self.poll(io).await {
tracing::warn!("ending session: {err}");
break err;
self.framing.reader.reset();
return err;
}
};
self.framing.reader.reset();
err
}
}

async fn poll(&mut self, io: &mut PhysLayer) -> Result<(), SessionEnd> {
Expand Down Expand Up @@ -387,7 +386,7 @@ impl ClientLoop {
}

// loop until we get the response to this request or we timeout
let response = loop {
loop {
let frame = tokio::select! {
_ = deadline.as_mut() => {
// after the turnaround delay a broadcast write is done
Expand All @@ -401,25 +400,22 @@ impl ClientLoop {
}
};

// a late answer to an earlier request, whose timeout was already reported
if !answers(frame.header, header) {
tracing::debug!(
"ignoring {:?} while expecting a response from unit {} with {:?}",
frame.header,
request.id,
tx_id
);
continue;
if answers(frame.header, header) {
// once we have a response, handle it. This may complete a promise
// successfully or bubble up an error
return request
.handle_response(frame.payload(), self.decode.app)
.map_err(ExchangeError::Rejected);
}

break frame;
};

// once we have a response, handle it. This may complete a promise
// successfully or bubble up an error
request
.handle_response(response.payload(), self.decode.app)
.map_err(ExchangeError::Rejected)
// a late answer to an earlier request, whose timeout was already reported
tracing::debug!(
"ignoring {:?} while expecting a response from unit {} with {:?}",
frame.header,
request.id,
tx_id
);
}
}

pub(crate) fn change_setting(&mut self, setting: Setting) {
Expand Down
1 change: 1 addition & 0 deletions rodbus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
clippy::print_stderr,
clippy::dbg_macro,
clippy::infinite_loop,
clippy::needless_continue,
clippy::large_futures,
clippy::large_stack_arrays,
clippy::iter_over_hash_type,
Expand Down
9 changes: 4 additions & 5 deletions rodbus/src/server/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ where
/// Serve requests over `io` until the session ends, leaving no partial frame behind for the
/// next
pub(crate) async fn run(&mut self, io: &mut PhysLayer) -> SessionEnd {
let end = loop {
loop {
if let Err(end) = self.run_one(io).await {
tracing::warn!("session error: {}", end);
break end;
self.reader.reset();
return end;
}
};
self.reader.reset();
end
}
}

#[cfg(feature = "serial")]
Expand Down
Loading