Skip to content

Commit

Permalink
Update to nix-0.28
Browse files Browse the repository at this point in the history
While at it, use std::os::fd::owned::OwnedFd instead of custom implementation.
  • Loading branch information
neumann-paulmann committed Apr 3, 2024
1 parent 361664b commit 2d859aa
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ categories = ["hardware-support"]
[target."cfg(unix)".dependencies]
bitflags = "2.4.0"
cfg-if = "1.0.0"
nix = { version = "0.26", default-features = false, features = ["fs", "ioctl", "poll", "signal", "term"] }
nix = { version = "0.28", default-features = false, features = ["fs", "ioctl", "poll", "signal", "term"] }

[target.'cfg(all(target_os = "linux", not(target_env = "musl")))'.dependencies]
libudev = { version = "0.3.0", optional = true }
Expand Down
10 changes: 5 additions & 5 deletions src/posix/poll.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(non_camel_case_types, dead_code)]

use std::io;
use std::os::unix::io::RawFd;
use std::os::fd::AsFd;
use std::slice;
use std::time::Duration;

Expand All @@ -11,18 +11,18 @@ use nix::sys::signal::SigSet;
#[cfg(target_os = "linux")]
use nix::sys::time::{TimeSpec, TimeValLike};

pub fn wait_read_fd(fd: RawFd, timeout: Duration) -> io::Result<()> {
pub fn wait_read_fd<F: AsFd>(fd: F, timeout: Duration) -> io::Result<()> {
wait_fd(fd, PollFlags::POLLIN, timeout)
}

pub fn wait_write_fd(fd: RawFd, timeout: Duration) -> io::Result<()> {
pub fn wait_write_fd<F: AsFd>(fd: F, timeout: Duration) -> io::Result<()> {
wait_fd(fd, PollFlags::POLLOUT, timeout)
}

fn wait_fd(fd: RawFd, events: PollFlags, timeout: Duration) -> io::Result<()> {
fn wait_fd<F: AsFd>(fd: F, events: PollFlags, timeout: Duration) -> io::Result<()> {
use nix::errno::Errno::{EIO, EPIPE};

let mut fd = PollFd::new(fd, events);
let mut fd = PollFd::new(fd.as_fd(), events);

let milliseconds =
timeout.as_secs() as i64 * 1000 + i64::from(timeout.subsec_nanos()) / 1_000_000;
Expand Down
Loading

0 comments on commit 2d859aa

Please sign in to comment.