diff options
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/epoll.rs | 2 | ||||
-rw-r--r-- | src/sys/event.rs | 16 | ||||
-rw-r--r-- | src/sys/eventfd.rs | 6 | ||||
-rw-r--r-- | src/sys/memfd.rs | 6 |
4 files changed, 15 insertions, 15 deletions
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 9fdb1495..36f9c17d 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -83,7 +83,7 @@ impl EpollEvent { /// let epoll = Epoll::new(EpollCreateFlags::empty())?; /// /// // Create eventfd & Add event -/// let eventfd = unsafe { OwnedFd::from_raw_fd(eventfd(0, EfdFlags::empty())?) }; +/// let eventfd = eventfd(0, EfdFlags::empty())?; /// epoll.add(&eventfd, EpollEvent::new(EpollFlags::EPOLLIN,DATA))?; /// /// // Arm eventfd & Time wait diff --git a/src/sys/event.rs b/src/sys/event.rs index d8ad628e..f21ba173 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -8,7 +8,7 @@ use libc::{c_int, c_long, intptr_t, time_t, timespec, uintptr_t}; use libc::{c_long, intptr_t, size_t, time_t, timespec, uintptr_t}; use std::convert::TryInto; use std::mem; -use std::os::unix::io::RawFd; +use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd}; use std::ptr; // Redefine kevent in terms of programmer-friendly enums and bitfields. @@ -207,10 +207,10 @@ libc_bitflags!( } ); -pub fn kqueue() -> Result<RawFd> { +pub fn kqueue() -> Result<OwnedFd> { let res = unsafe { libc::kqueue() }; - Errno::result(res) + Errno::result(res).map(|fd| unsafe { OwnedFd::from_raw_fd(fd) }) } // KEvent can't derive Send because on some operating systems, udata is defined @@ -267,8 +267,8 @@ impl KEvent { } } -pub fn kevent( - kq: RawFd, +pub fn kevent<Fd: AsFd>( + kq: Fd, changelist: &[KEvent], eventlist: &mut [KEvent], timeout_ms: usize, @@ -293,15 +293,15 @@ type type_of_nchanges = c_int; #[cfg(target_os = "netbsd")] type type_of_nchanges = size_t; -pub fn kevent_ts( - kq: RawFd, +pub fn kevent_ts<Fd: AsFd>( + kq: Fd, changelist: &[KEvent], eventlist: &mut [KEvent], timeout_opt: Option<timespec>, ) -> Result<usize> { let res = unsafe { libc::kevent( - kq, + kq.as_fd().as_raw_fd(), changelist.as_ptr() as *const libc::kevent, changelist.len() as type_of_nchanges, eventlist.as_mut_ptr() as *mut libc::kevent, diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index cd906720..f1723519 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -1,6 +1,6 @@ use crate::errno::Errno; use crate::Result; -use std::os::unix::io::RawFd; +use std::os::unix::io::{FromRawFd, OwnedFd}; libc_bitflags! { pub struct EfdFlags: libc::c_int { @@ -10,8 +10,8 @@ libc_bitflags! { } } -pub fn eventfd(initval: libc::c_uint, flags: EfdFlags) -> Result<RawFd> { +pub fn eventfd(initval: libc::c_uint, flags: EfdFlags) -> Result<OwnedFd> { let res = unsafe { libc::eventfd(initval, flags.bits()) }; - Errno::result(res).map(|r| r as RawFd) + Errno::result(res).map(|r| unsafe { OwnedFd::from_raw_fd(r) }) } diff --git a/src/sys/memfd.rs b/src/sys/memfd.rs index ad9345e8..f349a743 100644 --- a/src/sys/memfd.rs +++ b/src/sys/memfd.rs @@ -1,7 +1,7 @@ //! Interfaces for managing memory-backed files. use cfg_if::cfg_if; -use std::os::unix::io::RawFd; +use std::os::unix::io::{FromRawFd, OwnedFd, RawFd}; use crate::errno::Errno; use crate::Result; @@ -40,7 +40,7 @@ libc_bitflags!( /// For more information, see [`memfd_create(2)`]. /// /// [`memfd_create(2)`]: https://man7.org/linux/man-pages/man2/memfd_create.2.html -pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<RawFd> { +pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<OwnedFd> { let res = unsafe { cfg_if! { if #[cfg(all( @@ -60,5 +60,5 @@ pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<RawFd> { } }; - Errno::result(res).map(|r| r as RawFd) + Errno::result(res).map(|r| unsafe { OwnedFd::from_raw_fd(r as RawFd) }) } |