mirror of https://github.com/smol-rs/smol
Merge pull request #10 from wusyong/as_fd
Add AsRawFd/RawSocket on types with trait bound of them
This commit is contained in:
commit
bc0acdd308
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue