Skip to content

Commit 1b2fadd

Browse files
committed
PollFd event flags renamed to PollFlags from EventFlags.
Most of the EventFlags have been renamed already, but Poll was the only one remaining. This commit fixes that. Issue 317 #317
1 parent 7ae7a1f commit 1b2fadd

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
- Add IP_RECVIF & IP_RECVDSTADDR. Enable IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
99
([#1002](https://github.com/nix-rust/nix/pull/1002))
1010
### Changed
11+
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
1112
### Fixed
1213
### Removed
1314

src/poll.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ pub struct PollFd {
2727
impl PollFd {
2828
/// Creates a new `PollFd` specifying the events of interest
2929
/// for a given file descriptor.
30-
pub fn new(fd: RawFd, events: EventFlags) -> PollFd {
30+
pub fn new(fd: RawFd, events: PollFlags) -> PollFd {
3131
PollFd {
3232
pollfd: libc::pollfd {
3333
fd: fd,
3434
events: events.bits(),
35-
revents: EventFlags::empty().bits(),
35+
revents: PollFlags::empty().bits(),
3636
},
3737
}
3838
}
3939

4040
/// Returns the events that occured in the last call to `poll` or `ppoll`.
41-
pub fn revents(&self) -> Option<EventFlags> {
42-
EventFlags::from_bits(self.pollfd.revents)
41+
pub fn revents(&self) -> Option<PollFlags> {
42+
PollFlags::from_bits(self.pollfd.revents)
4343
}
4444
}
4545

@@ -48,11 +48,11 @@ impl fmt::Debug for PollFd {
4848
let pfd = self.pollfd;
4949
let mut ds = f.debug_struct("PollFd");
5050
ds.field("fd", &pfd.fd);
51-
match EventFlags::from_bits(pfd.events) {
51+
match PollFlags::from_bits(pfd.events) {
5252
None => ds.field("events", &pfd.events),
5353
Some(ef) => ds.field("events", &ef),
5454
};
55-
match EventFlags::from_bits(pfd.revents) {
55+
match PollFlags::from_bits(pfd.revents) {
5656
None => ds.field("revents", &pfd.revents),
5757
Some(ef) => ds.field("revents", &ef),
5858
};
@@ -62,7 +62,7 @@ impl fmt::Debug for PollFd {
6262

6363
libc_bitflags! {
6464
/// These flags define the different events that can be monitored by `poll` and `ppoll`
65-
pub struct EventFlags: libc::c_short {
65+
pub struct PollFlags: libc::c_short {
6666
/// There is data to read.
6767
POLLIN;
6868
/// There is some exceptional condition on the file descriptor.

test/test_poll.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
use nix::poll::{EventFlags, poll, PollFd};
1+
use nix::poll::{PollFlags, poll, PollFd};
22
use nix::unistd::{write, pipe, close};
33

44
#[test]
55
fn test_poll() {
66
let (r, w) = pipe().unwrap();
7-
let mut fds = [PollFd::new(r, EventFlags::POLLIN)];
7+
let mut fds = [PollFd::new(r, PollFlags::POLLIN)];
88

99
// Poll an idle pipe. Should timeout
1010
let nfds = poll(&mut fds, 100).unwrap();
1111
assert_eq!(nfds, 0);
12-
assert!(!fds[0].revents().unwrap().contains(EventFlags::POLLIN));
12+
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
1313

1414
write(w, b".").unwrap();
1515

1616
// Poll a readable pipe. Should return an event.
1717
let nfds = poll(&mut fds, 100).unwrap();
1818
assert_eq!(nfds, 1);
19-
assert!(fds[0].revents().unwrap().contains(EventFlags::POLLIN));
19+
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
2020
}
2121

2222
#[test]
2323
fn test_poll_debug() {
24-
assert_eq!(format!("{:?}", PollFd::new(0, EventFlags::empty())),
24+
assert_eq!(format!("{:?}", PollFd::new(0, PollFlags::empty())),
2525
"PollFd { fd: 0, events: (empty), revents: (empty) }");
26-
assert_eq!(format!("{:?}", PollFd::new(1, EventFlags::POLLIN)),
26+
assert_eq!(format!("{:?}", PollFd::new(1, PollFlags::POLLIN)),
2727
"PollFd { fd: 1, events: POLLIN, revents: (empty) }");
2828

2929
// Testing revents requires doing some I/O
3030
let (r, w) = pipe().unwrap();
31-
let mut fds = [PollFd::new(r, EventFlags::POLLIN)];
31+
let mut fds = [PollFd::new(r, PollFlags::POLLIN)];
3232
write(w, b" ").unwrap();
3333
close(w).unwrap();
3434
poll(&mut fds, -1).unwrap();
@@ -52,17 +52,17 @@ fn test_ppoll() {
5252

5353
let timeout = TimeSpec::milliseconds(1);
5454
let (r, w) = pipe().unwrap();
55-
let mut fds = [PollFd::new(r, EventFlags::POLLIN)];
55+
let mut fds = [PollFd::new(r, PollFlags::POLLIN)];
5656

5757
// Poll an idle pipe. Should timeout
5858
let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
5959
assert_eq!(nfds, 0);
60-
assert!(!fds[0].revents().unwrap().contains(EventFlags::POLLIN));
60+
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
6161

6262
write(w, b".").unwrap();
6363

6464
// Poll a readable pipe. Should return an event.
6565
let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
6666
assert_eq!(nfds, 1);
67-
assert!(fds[0].revents().unwrap().contains(EventFlags::POLLIN));
67+
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
6868
}

0 commit comments

Comments
 (0)