Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokio::io::Stdin implements AsyncRead but is not Async #633

Closed
aep opened this issue Sep 14, 2018 · 1 comment
Closed

tokio::io::Stdin implements AsyncRead but is not Async #633

aep opened this issue Sep 14, 2018 · 1 comment

Comments

@aep
Copy link
Contributor

aep commented Sep 14, 2018

Version

tokio 0.1.8
futures 0.1.21

Platform

Linux sdzx 4.18.5-arch1-1-ARCH #1 SMP PREEMPT Fri Aug 24 12:48:58 UTC 2018 x86_64 GNU/Linux

Description

poll_read on tokio::io::Stdin is blocking. that is unexpected and confusing.

extern crate tokio;
#[macro_use]
extern crate futures;

use tokio::io::{AsyncRead,stdin};
use std::io::{Write, stdout};
use futures::{Future, Async};

struct IoBridge<R,W>
where R: AsyncRead,
      W: Write,
{
    r: R,
    w: W,
}


impl<R,W> Future for IoBridge<R,W>
where R: AsyncRead,
      W: Write,
{
    type Item  = ();
    type Error = tokio::io::Error;
    fn poll(&mut self) -> Result<Async<Self::Item>, Self::Error> {
        println!(".");
        let mut buf = [0;1024];
        loop {
            let len = try_ready!(self.r.poll_read(&mut buf));
            println!("<< {}", len);
            if len == 0 {
                return Ok(Async::Ready(()));
            }
            self.w.write(&buf[..len])?;
            self.w.flush()?;
        }
    }
}


fn main() {
    let f = IoBridge{
        r: stdin(),
        w: stdout()
    }.map_err(|e|panic!(e));

    tokio::run(f);
}

note that . is only printed once. the loop will never exit.

@carllerche
Copy link
Member

Thanks for the report. Dup of #589.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants