Skip to content

Commit

Permalink
io: don't panic when socket address is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Dec 24, 2024
1 parent 7761222 commit 1b5ea98
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/io/recv_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ where
// Recover the buffer
let mut buf = self.buf;

let socket_addr = (*self.socket_addr).as_socket();
let socket_addr = match (*self.socket_addr).as_socket() {
Some(sa) => sa,
None => return (Err(io::Error::from(io::ErrorKind::AddrNotAvailable)), buf),
};

let res = res.map(|n| {
let socket_addr: SocketAddr = socket_addr.unwrap();

// Safety: the kernel wrote `n` bytes to the buffer.
unsafe {
buf.set_init(n);
Expand Down

0 comments on commit 1b5ea98

Please sign in to comment.