nix icon indicating copy to clipboard operation
nix copied to clipboard

`PollFd<'fd>` is poorly designed for server implementation

Open StackOverflowExcept1on opened this issue 4 months ago • 0 comments

let mut fds = vec![
    PollFd::new(socket_fd.as_fd(), PollFlags::POLLIN),
    // client fds
];

loop {
    poll(&mut fds, PollTimeout::from(1_u8))?;

    match accept(socket_fd.as_raw_fd()) {
        Ok(client_fd) => {
            let owned_client_fd = unsafe { OwnedFd::from_raw_fd(client_fd) };
            // different lifetime from `socket_fd.as_fd()`
            fds.push(PollFd::new(owned_client_fd.as_fd(), PollFlags::POLLIN));
        }
        _ => {}
    }
}

StackOverflowExcept1on avatar Aug 24 '25 15:08 StackOverflowExcept1on