2017-09-06 59 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

相關問題