Skip to content

Commit

Permalink
Attempt to fix the issues mentioned
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Sep 13, 2024
1 parent e17fa82 commit 2538684
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/async_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,22 @@ impl AsyncSession {
loop {
match self.session.try_receive() {
Ok(Some(packet)) => {
// it seems to be standard practice to truncate rather than return an error,
// in the context of TUN/TAP the packet lengths can be read anyway
let size = packet.bytes.len().min(buf.len());
let size = packet.bytes.len();
if buf.len() < size {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Buffer too small"));
}
buf[..size].copy_from_slice(&packet.bytes[..size]);
return Ok(size);
}
Ok(None) => {
let read_event = self.session.get_read_wait_event()?;
let shutdown_event = self.session.shutdown_event.get_handle();
blocking::unblock(move || Self::wait_for_read(read_event, shutdown_event)).await;
match blocking::unblock(move || Self::wait_for_read(read_event, shutdown_event)).await {
WaitingStopReason::Shutdown => {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Shutdown"));
}
WaitingStopReason::Ready => continue,
}
}
Err(err) => return Err(std::io::Error::new(std::io::ErrorKind::Other, err)),
}
Expand Down

0 comments on commit 2538684

Please sign in to comment.