2017-09-06 57 views
0

http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/reference/buffered_stream/buffered_stream.html什么是buffered_stream :: buffered_stream构造函数中的Arg&a?

我正在考虑将它用作tcp流和can总线之间的中间缓冲区。我将缓冲区传递给相关的API,写入can bus,后者使用async_reads获取数据。 TCP端使用async_writes写入缓冲区。

+1

不会是你缓冲流? –

+0

是的,doh。这不是我想要的。在boost :: asio中是否存在与std :: stringstream相当的asnyc? –

回答

2

当然。

boost::asio::streambuf sb; 

// now write: 
{ 
    std::ostream os(&sb); 
    os << "Hello 1 2 3" << std::flush; 
} 

// or read: 
{ std::istream is(&sb); 
    std::string s; 
    int a, b, c; 
    is >> s >> a >> b >> c; 
} 

请注意,您还可以使用连接到插座预配置的流:

#include <boost/asio.hpp> 
#include <iostream> 

using boost::asio::ip::tcp; 

int main() { 
    tcp::iostream s("localhost", "http"); 

    s << "GET/HTTP/1.0\r\n\r\n" << std::flush; 
    std::cout << s.rdbuf(); // print response 
} 
+0

使用预制'tcp'流添加了一个简单的HTTP客户端 – sehe

相关问题