Merge pull request #10 from wusyong/as_fd

Add AsRawFd/RawSocket on types with trait bound of them
This commit is contained in:
Stjepan Glavina 2020-04-21 08:29:22 -07:00 committed by GitHub
commit bc0acdd308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -9,7 +9,7 @@ use std::task::{Context, Poll};
#[cfg(unix)]
use std::{
os::unix::io::AsRawFd,
os::unix::io::{AsRawFd, RawFd},
os::unix::net::{SocketAddr as UnixSocketAddr, UnixDatagram, UnixListener, UnixStream},
path::Path,
};
@ -54,6 +54,13 @@ impl<T: AsRawFd> Async<T> {
}
}
#[cfg(unix)]
impl<T: AsRawFd> AsRawFd for Async<T> {
fn as_raw_fd(&self) -> RawFd {
self.source.raw
}
}
#[cfg(windows)]
impl<T: AsRawSocket> Async<T> {
/// Converts a non-blocking I/O handle into an async I/O handle.
@ -67,6 +74,13 @@ impl<T: AsRawSocket> Async<T> {
}
}
#[cfg(windows)]
impl<T: AsRawSocket> AsRawSocket for Async<T> {
fn as_raw_socket(&self) -> RawSocket {
self.source.raw
}
}
impl<T> Async<T> {
/// Gets a reference to the inner I/O handle.
///

View File

@ -245,11 +245,11 @@ impl ReactorLock<'_> {
pub(crate) struct Source {
/// Raw file descriptor on Unix platforms.
#[cfg(unix)]
raw: RawFd,
pub(crate) raw: RawFd,
/// Raw socket handle on Windows.
#[cfg(windows)]
raw: RawSocket,
pub(crate) raw: RawSocket,
/// The ID of this source obtain during registration.
key: usize,