Skip to content

Commit

Permalink
io: impl as RawFd / AsRawHandle for stdio (#2335)
Browse files Browse the repository at this point in the history
Fixes: #2311
  • Loading branch information
MarinPostma authored Mar 23, 2020
1 parent dd27f1a commit 2258de5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tokio/src/io/stderr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ cfg_io_std! {
}
}

#[cfg(unix)]
impl std::os::unix::io::AsRawFd for Stderr {
fn as_raw_fd(&self) -> std::os::unix::io::RawFd {
std::io::stderr().as_raw_fd()
}
}

#[cfg(windows)]
impl std::os::windows::io::AsRawHandle for Stderr {
fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
std::io::stderr().as_raw_handle()
}
}

impl AsyncWrite for Stderr {
fn poll_write(
mut self: Pin<&mut Self>,
Expand Down
14 changes: 14 additions & 0 deletions tokio/src/io/stdin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ cfg_io_std! {
}
}

#[cfg(unix)]
impl std::os::unix::io::AsRawFd for Stdin {
fn as_raw_fd(&self) -> std::os::unix::io::RawFd {
std::io::stdin().as_raw_fd()
}
}

#[cfg(windows)]
impl std::os::windows::io::AsRawHandle for Stdin {
fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
std::io::stdin().as_raw_handle()
}
}

impl AsyncRead for Stdin {
fn poll_read(
mut self: Pin<&mut Self>,
Expand Down
14 changes: 14 additions & 0 deletions tokio/src/io/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ cfg_io_std! {
}
}

#[cfg(unix)]
impl std::os::unix::io::AsRawFd for Stdout {
fn as_raw_fd(&self) -> std::os::unix::io::RawFd {
std::io::stdout().as_raw_fd()
}
}

#[cfg(windows)]
impl std::os::windows::io::AsRawHandle for Stdout {
fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
std::io::stdout().as_raw_handle()
}
}

impl AsyncWrite for Stdout {
fn poll_write(
mut self: Pin<&mut Self>,
Expand Down

0 comments on commit 2258de5

Please sign in to comment.