stdin pipe not closing when read with Boost.ASIO
<p>I'm reading stdin using Boost.ASIO, but when I pipe into it I would expect that the pipe would close when the input has been fully consumed. I.e. I'm doing this at the commmand line:</p>

<pre><code>cat somefile.txt | myprog
</code></pre>

<p>And I'd expect that <code>myprog</code> will see the file close. Instead it waits forever.</p>

<p>The code looks like this:</p>

<pre><code>boost::asio::posix::stream_descriptor as_stdin(ios);
{
    boost::system::error_code error;
    as_stdin.assign(dup(STDIN_FILENO), error);
    if ( error ) {
        exit(2);
    }
}
auto proc = [&amp;as_stdinr](auto yield) {
        boost::asio::streambuf buffer;
        while ( as_stdin.is_open() ) {
            auto bytes = boost::asio::async_read_until(as_stdin, buffer, '\n', yield);
            if ( bytes ) {
                buffer.commit(bytes);
                std::istream in(&amp;buffer);
                std::string line;
                std::getline(in, line);
                std::cerr &lt;&lt; line &lt;&lt; std::endl;
            } else {
                std::cerr &lt;&lt; "No bytes read" &lt;&lt; std::endl;
            }
        }
        std::cerr &lt;&lt; "Done" &lt;&lt; std::endl;
    };
boost::asio::spawn(ios, proc);
</code></pre>

<p>All of the file content is properly echoed, so reading from the pipe works fine, but neither of the "No bytes read" or "Done" messages are ever printed. I've tried both with and without the <code>dup</code> system call.</p>

<p>Am I misunderstanding how the pipe works, or am I doing something wrong or missing something else?</p>

<p>I think this comes down to "How do I detect EOF when using coroutines?"</p>