Advertisement
fenixD3

Untitled

Sep 11th, 2022 (edited)
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. boost::asio::io_context ctx;
  2.  
  3. class Pipe
  4. {
  5. private:
  6.     boost::process::async_pipe pipe;
  7.     std::string read_buf;
  8. public:
  9.     Pipe() : pipe(ctx, cfg::PipeName)
  10.     {
  11.         fs.open("tester.txt", std::ios_base::out);
  12.     }
  13.  
  14.     void Run()
  15.     {
  16.         fs << "Run launch" << std::endl;
  17.         boost::asio::async_read_until(
  18.             pipe,
  19.             boost::asio::dynamic_buffer(read_buf),
  20.             '\n',
  21.             [this](const boost::system::error_code& error, size_t bytes)
  22.             {
  23.                 fs << "Handler" << std::endl;
  24.                 if (error)
  25.                 {
  26.                     fs << error << std::endl;
  27.                 }
  28.                 if (!read_buf.empty())
  29.                 {
  30.                     fs << "Readed str: " << read_buf << std::endl;
  31.                 }
  32.                 else
  33.                 {
  34.                     fs << "Empty buf!" << std::endl;
  35.                 }
  36.  
  37.                 boost::asio::post(ctx, boost::bind(&Pipe::Run, this));
  38.             });
  39.     }
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement