最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Does the `boost::asio::readable_pipe::read()` member function exist? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Jan 18 at 17:11 PietroPietro 13.2k31 gold badges111 silver badges204 bronze badges 3
  • This is Boost 1.87.0 example. Which Boost version do you use? – 3CxEZiVlQ Commented Jan 18 at 17:23
  • 1 As far as I can see readable_pipe has never had a member named read so it could be the example's incorrect (I may regret saying that, but...). Perhaps try asio::read(rp, asio::dynamic_buffer(output), ec);? – G.M. Commented Jan 18 at 17:59
  • @3CxEZiVlQ - On my system I have 1.83.0, but the situation does not change with the latest 1.87.0. – Pietro Commented Jan 19 at 12:22
Add a comment  | 

1 Answer 1

Reset to default 3

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.

发布评论

评论列表(0)

  1. 暂无评论