Skip to content

Commit b63861c

Browse files
committed
Prefer poll() for sidecar channel
This fixes paninc()'ing on a fd number higher than FD_SETSIZE. Signed-off-by: Bob Weinand <[email protected]>
1 parent 158b594 commit b63861c

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

datadog-ipc/src/platform/unix/channel.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
use crate::handles::TransferHandles;
55
use crate::platform::{Message, PlatformHandle};
6-
use nix::sys::select::FdSet;
7-
use nix::sys::time::{TimeVal, TimeValLike};
6+
use nix::poll::{poll, PollFd, PollFlags, PollTimeout};
87
use std::{
98
io::{self, ErrorKind, Read, Write},
109
os::{
@@ -61,11 +60,13 @@ impl Channel {
6160
pub fn probe_readable(&self) -> bool {
6261
#[allow(clippy::unwrap_used)]
6362
let raw_fd = self.inner.as_owned_fd().unwrap().as_fd();
64-
let mut fds = FdSet::new();
65-
fds.insert(raw_fd);
66-
nix::sys::select::select(None, Some(&mut fds), None, None, Some(&mut TimeVal::zero()))
67-
.is_err()
68-
|| fds.contains(raw_fd)
63+
64+
let mut fds = [PollFd::new(raw_fd, PollFlags::POLLIN)];
65+
poll(&mut fds, PollTimeout::ZERO).is_err()
66+
|| fds[0]
67+
.revents()
68+
.unwrap_or(PollFlags::empty())
69+
.intersects(PollFlags::POLLIN | PollFlags::POLLHUP | PollFlags::POLLERR)
6970
}
7071

7172
pub fn create_message<T>(&mut self, item: T) -> Result<Message<T>, io::Error>

0 commit comments

Comments
 (0)