Skip to content

PollFd<'fd> is poorly designed for server implementation #2665

@StackOverflowExcept1on

Description

@StackOverflowExcept1on
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));
        }
        _ => {}
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions