Skip to content
Open
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
30 changes: 28 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,12 @@ fn run<Device: AsyncRead + AsyncWrite + Unpin + Send + 'static>(
tokio::spawn(async move {
loop {
select! {
Ok(n) = device.read(&mut buffer) => {
if let Err(e) = process_device_read(&buffer[offset..n], &mut sessions, &session_remove_tx, &up_pkt_sender, &config, &accept_sender).await {
read_result = device.read(&mut buffer) => {
let num_read = read_result?;
if num_read == 0 {
return Ok(());

@SajjadPourali SajjadPourali Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
We should notify the user about this issue. For now, we can log it, but we might return an error in the future.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation also needs to be updated.

}
if let Err(e) = process_device_read(&buffer[offset..num_read], &mut sessions, &session_remove_tx, &up_pkt_sender, &config, &accept_sender).await {
let io_err: std::io::Error = e.into();
if io_err.kind() == std::io::ErrorKind::ConnectionRefused {
log::trace!("Received junk data: {io_err}");
Expand Down Expand Up @@ -439,3 +443,25 @@ async fn process_upstream_recv<Device: AsyncWrite + Unpin + 'static>(

Ok(())
}

#[cfg(test)]
mod tests {
use std::time::Duration;

use tokio::{io::duplex, time::timeout};

use super::*;

#[tokio::test]
async fn device_eof_closes_accept_channel() {
let (device, peer) = duplex(64);
let mut ip_stack = IpStack::new(IpStackConfig::default(), device);

drop(peer);

let accept_result = timeout(Duration::from_secs(1), ip_stack.accept())
.await
.expect("accept should not hang after device EOF");
assert!(matches!(accept_result, Err(IpStackError::AcceptError)));
}
}
Loading