Skip to content

Commit

Permalink
add async waker methods and async feature
Browse files Browse the repository at this point in the history
  • Loading branch information
liamkinne committed Jun 5, 2024
1 parent 670649d commit 3ec3670
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions tritiumcan-smoltcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ zerocopy = { version = "0.7.34", features = ["derive"] }

[features]
defmt-03 = ["dep:defmt", "smoltcp/defmt", "tritiumcan/defmt-03"]
async = ["smoltcp/async"]
30 changes: 30 additions & 0 deletions tritiumcan-smoltcp/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,34 @@ impl Server {
Ok(Some(frame))
}
}

/// Register a waker for receive operations.
///
/// See [smoltcp documentation](https://docs.rs/smoltcp/latest/smoltcp/socket/tcp/struct.Socket.html#method.register_recv_waker)
/// for the rules around receive wakers.
#[cfg(feature = "async")]
pub fn register_recv_waker(
&mut self,
sockets: &mut SocketSet,
waker: &core::task::Waker,
) {
let socket = sockets.get_mut::<Socket>(self.handle);

socket.register_recv_waker(waker);
}

/// Register a waker for send operations.
///
/// See [smoltcp documentation](https://docs.rs/smoltcp/latest/smoltcp/socket/tcp/struct.Socket.html#method.register_send_waker)
/// for the rules around receive wakers.
#[cfg(feature = "async")]
pub fn register_send_waker(
&mut self,
sockets: &mut SocketSet,
waker: &core::task::Waker,
) {
let socket = sockets.get_mut::<Socket>(self.handle);

socket.register_send_waker(waker);
}
}
30 changes: 30 additions & 0 deletions tritiumcan-smoltcp/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,34 @@ impl Server {
Ok(Some(packet.frame.into()))
}
}

/// Register a waker for receive operations.
///
/// See [smoltcp documentation](https://docs.rs/smoltcp/latest/smoltcp/socket/udp/struct.Socket.html#method.register_recv_waker)
/// for the rules around receive wakers.
#[cfg(feature = "async")]
pub fn register_recv_waker(
&mut self,
sockets: &mut SocketSet,
waker: &core::task::Waker,
) {
let socket = sockets.get_mut::<Socket>(self.handle);

socket.register_recv_waker(waker);
}

/// Register a waker for send operations.
///
/// See [smoltcp documentation](https://docs.rs/smoltcp/latest/smoltcp/socket/udp/struct.Socket.html#method.register_send_waker)
/// for the rules around receive wakers.
#[cfg(feature = "async")]
pub fn register_send_waker(
&mut self,
sockets: &mut SocketSet,
waker: &core::task::Waker,
) {
let socket = sockets.get_mut::<Socket>(self.handle);

socket.register_send_waker(waker);
}
}

0 comments on commit 3ec3670

Please sign in to comment.