Skip to content

Commit

Permalink
Lte link fix + clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
diondokter committed Sep 5, 2023
1 parent 2d793f9 commit 1498d28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.4 (05-09-23)

- Fixed issue where LTE link waiting couldn't be cancelled

## 0.3.3 (07-08-23)

- Fixed issue where a split socket polled on two different tasks would not properly wake up one of the two tasks if both were waiting on the same socket. (#14)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nrf-modem"
version = "0.3.3"
version = "0.3.4"
edition = "2021"
rust-version = "1.64"
license = "MIT OR Apache-2.0"
Expand Down
14 changes: 12 additions & 2 deletions src/lte_link.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementation of [LteLink]
use crate::{at, at_notifications::AtNotificationStream, error::Error, CancellationToken};
use core::{mem, ops::ControlFlow};
use core::{mem, ops::ControlFlow, task::Poll};

/// An object that keeps the modem connected.
/// As long as there is an instance, the modem will be kept on.
Expand Down Expand Up @@ -77,7 +77,15 @@ impl LteLink {
let mut stream = notification_stream
.map(|notif| Self::get_cereg_stat_control_flow(Self::parse_cereg(notif.as_str())));

while let Some(cereg) = stream.next().await {
while let Some(cereg) = core::future::poll_fn(|cx| {
if token.is_cancelled() {
Poll::Ready(None)
} else {
stream.poll_next_unpin(cx)
}
})
.await
{
match cereg {
ControlFlow::Continue(_) => {
token.as_result()?;
Expand All @@ -86,6 +94,8 @@ impl LteLink {
}
}

token.as_result()?;

unreachable!()
}

Expand Down
6 changes: 3 additions & 3 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl Socket {
register_socket_waker(cx.waker().clone(), self.fd, SocketDirection::RX);

let mut receive_result = unsafe {
nrfxlib_sys::nrf_recv(self.fd, buffer.as_ptr() as *mut _, buffer.len(), 0)
nrfxlib_sys::nrf_recv(self.fd, buffer.as_mut_ptr() as *mut _, buffer.len(), 0)
};

if receive_result == -1 {
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Socket {
let mut receive_result = unsafe {
nrfxlib_sys::nrf_recvfrom(
self.fd,
buffer.as_ptr() as *mut _,
buffer.as_mut_ptr() as *mut _,
buffer.len(),
0,
socket_addr_ptr,
Expand Down Expand Up @@ -540,7 +540,7 @@ impl Drop for Socket {
let e = unsafe { nrfxlib_sys::nrf_close(self.fd) };

if e == -1 {
Result::<(), _>::Err(Error::NrfError(get_last_error())).unwrap();
panic!("{:?}", Error::NrfError(get_last_error()));
}
}
}
Expand Down

0 comments on commit 1498d28

Please sign in to comment.