Is there an elegant way to connect two devices / streams in Asio?

Given the two stream-oriented I / O objects in Asio , what is the easiest way to transfer data from one device to another in both directions? Could this be done with a boost :: iostreams :: combination or a boost :: iostreams: copy is possible? Or is a manual approach better - waiting for data at each end and then writing it to another stream? In other words, how does one Boost and Asio leverage to create a minimal amount of code?

An example application would be streaming between a serial port and a TCP socket as requested in this question .

+3
source share
1 answer

With standard C ++ streams, you can do the following: can you do something similar with Asio?

// Read all data from in and write to out.
void forward_data( std::istream& in, std::ostream& out )
{
  out << in.rdbuf();
}
+4
source

Source: https://habr.com/ru/post/1714678/