c++boostpipeboost-asio

Does the `boost::asio::readable_pipe::read()` member function exist?


I am trying to build some example code shown on Boost web site, but a member function is used which does not seem to be part of Boost:

#include <string>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/readable_pipe.hpp>
#include <boost/process/v2/process.hpp>
#include <boost/process/v2/stdio.hpp>
#include <boost/version.hpp>

int main()
{
    using namespace boost;
    using namespace boost::process::v2;

    asio::io_context ctx;
    asio::readable_pipe rp{ctx};

    boost::process::v2::process proc(ctx, "/usr/bin/g++", {"--version"}, process_stdio{{ /* in to default */}, rp, { /* err to default */ }});
    std::string output;

    system::error_code ec;
    rp.read(asio::dynamic_buffer(output), ec);   // <-- error, line 44
    assert(ec == asio::error::eof);
    proc.wait();
}

This is the error message:

error: ‘boost::asio::readable_pipe’ {aka ‘class boost::asio::basic_readable_pipe<>’} has no member named ‘read’
   44 |     rp.read(asio::dynamic_buffer(output), ec);

On the documentation I noticed similar member functions read_some() and async_read_some(), but no read().

Could this be an error in the example, or am I missing something?


Solution

  • The documentation example comes from here: https://github.com/boostorg/process/blob/develop/example/stdio.cpp#L19-L30

    asio::io_context ctx;
    asio::readable_pipe rp{ctx};
    
    process proc(ctx, "/usr/bin/g++", {"--version"}, process_stdio{{ /* in to default */}, rp, { /* err to default */ }});
    std::string output;
    
    boost::system::error_code ec;
    asio::read(rp, asio::dynamic_buffer(output), ec);
    assert(!ec || (ec == asio::error::eof));
    proc.wait();
    //end::readable_pipe[]
    

    It is linked into that documentation page automatically via https://github.com/boostorg/process/blob/develop/doc/stdio.adoc?plain=1#L10-L17

    I imagine some copy-paste error crept in.

    Since asio::readable_pipe models SyncReadStream the composed operations like asio::read indeed support it.

    UPDATE

    The documentation has been fixed fairly recently: https://github.com/boostorg/process/commit/3fd8b2608cca3cd7a6359110f9fc29075df42519

    Before that date, the examples were hardcoded into the docs, meaning they didn't necessary stay up to date.