nix
nix copied to clipboard
Expose the RawFd wrapped by struct PollFd
Could you please tell me a little bit more about what you're trying to accomplish?
I am trying to figure out which fd produced an event. Maybe I am overlooking something blatantly obvious, but how would you know which descriptor had some activity?
let mut fds = [PollFd::new(pty.master, PollFlags::POLLIN),
PollFd::new(STDIN_FILENO, PollFlags::POLLIN)];
'polling: loop {
if poll(&mut fds, 1000)? > 0 {
for fd in fds.iter() {
if let Some(flags) = fd.revents() {
if flags.contains(PollFlags::POLLIN) {
let other = if fd.raw_fd() == pty.master {
STDOUT_FILENO
} else {
pty.master
};
let mut buf = MaybeUninit::<[u8; 512]>::uninit();
if let Ok(size) = read(fd.raw_fd(), unsafe { &mut *buf.as_mut_ptr() }) {
let slice = &unsafe { buf.assume_init() }[0..size];
write(other, slice)?;
}
} else if flags.contains(PollFlags::POLLHUP) {
break 'polling
}
}
}
}
}
-- CYa, ⡍⠁⠗⠊⠕
PollFd implements AsRawFd so you can access the file descriptor by calling fd.as_raw_fd()
.
Thanks for your contributing!
That issue has already been fixed, so I am gonna close this PR, I am sorry about this.