Skip to content

Commit

Permalink
fix(net): ignore EINTR errno response from select (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Sep 1, 2023
1 parent 081a937 commit 855b3af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/tracing/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub enum IoOperation {
NewSocket,
SetNonBlocking,
Select,
SelectRead,
SelectWrite,
RecvFrom,
Read,
Shutdown,
Expand Down Expand Up @@ -99,6 +101,8 @@ impl Display for IoOperation {
Self::NewSocket => write!(f, "create new socket"),
Self::SetNonBlocking => write!(f, "set non-blocking"),
Self::Select => write!(f, "select"),
Self::SelectRead => write!(f, "selectread"),
Self::SelectWrite => write!(f, "selectwrite"),
Self::RecvFrom => write!(f, "recv from"),
Self::Read => write!(f, "read"),
Self::Shutdown => write!(f, "shutdown"),
Expand Down
25 changes: 19 additions & 6 deletions src/tracing/net/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use nix::{
sys::select::FdSet,
sys::socket::{AddressFamily, SockaddrLike},
sys::time::{TimeVal, TimeValLike},
Error,
};
use socket2::{Domain, Protocol, SockAddr, Type};
use std::io;
Expand Down Expand Up @@ -305,9 +306,15 @@ impl TracerSocket for Socket {
None,
None,
Some(&mut TimeVal::milliseconds(timeout.as_millis() as i64)),
)
.map_err(|err| IoError::Other(std::io::Error::from(err), IoOperation::Select))?;
Ok(readable == 1)
);
match readable {
Ok(readable) => Ok(readable == 1),
Err(err) if err == Error::EINTR => Ok(false),
Err(err) => Err(IoError::Other(
std::io::Error::from(err),
IoOperation::SelectRead,
)),
}
}
#[instrument(skip(self))]
fn is_writable(&self) -> IoResult<bool> {
Expand All @@ -319,9 +326,15 @@ impl TracerSocket for Socket {
Some(&mut write),
None,
Some(&mut TimeVal::zero()),
)
.map_err(|err| IoError::Other(std::io::Error::from(err), IoOperation::Select))?;
Ok(writable == 1)
);
match writable {
Ok(writable) => Ok(writable == 1),
Err(err) if err == Error::EINTR => Ok(false),
Err(err) => Err(IoError::Other(
std::io::Error::from(err),
IoOperation::SelectWrite,
)),
}
}
#[instrument(skip(self, buf), ret)]
fn recv_from(&mut self, buf: &mut [u8]) -> IoResult<(usize, Option<SocketAddr>)> {
Expand Down

0 comments on commit 855b3af

Please sign in to comment.