Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pollfd_t.revents is marked private #27

Closed
pwaller opened this issue Feb 4, 2023 · 2 comments
Closed

pollfd_t.revents is marked private #27

pwaller opened this issue Feb 4, 2023 · 2 comments

Comments

@pwaller
Copy link

pwaller commented Feb 4, 2023

This is a field you need to be able to read/write to use poll.

#[repr(C)]
#[derive(Debug, Default, Clone)]
pub struct pollfd_t {
pub fd: i32,
pub events: i16,
revents: i16,
}

@pwaller
Copy link
Author

pwaller commented Feb 4, 2023

Additionally the poll types have a type of i32, but the fields on pollfd_t which use those bits are an i16, so you have to cast the constants unnecessarily currently:

/// These are specified by `iBCS2`
pub const POLLIN: i32 = 0x0001;
pub const POLLPRI: i32 = 0x0002;
pub const POLLOUT: i32 = 0x0004;
pub const POLLERR: i32 = 0x0008;
pub const POLLHUP: i32 = 0x0010;
pub const POLLNVAL: i32 = 0x0020;
/// The rest seem to be more-or-less nonstandard. Check them!
pub const POLLRDNORM: i32 = 0x0040;
pub const POLLRDBAND: i32 = 0x0080;
pub const POLLWRNORM: i32 = 0x0100;
pub const POLLWRBAND: i32 = 0x0200;
pub const POLLMSG: i32 = 0x0400;
pub const POLLREMOVE: i32 = 0x1000;
pub const POLLRDHUP: i32 = 0x2000;

@pwaller
Copy link
Author

pwaller commented Feb 4, 2023

And the poll function returns a useful integer:

pub unsafe fn poll(fds: &mut [pollfd_t], timeout: i32) -> Result<(), Errno> {

Manpage:

Upon successful completion, poll() shall return a non-negative value. A positive value indicates the total number of pollfd structures that have selected events (that is, those for which the revents member is non-zero). A value of 0 indicates that the call timed out and no file descriptors have been selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant