I am using boost::process
to read asynchronously the output of a console application in Windows. I noticed that the reading events is triggered after about 4k of data every-time.
If I set my buffer 'buf' to a small value nothing changes: the event is triggered multiple times ONLY after 4k of data has been transferred.
As per my understanding this could be a safe mechanism used in Windows to avoid dead-lock while reading from the pipe.
Is there any way in boost::process
to change the size of the buffer used by the PIPE to transfer the data?
#include <boost/process.hpp>
#include <boost/asio.hpp>
using namespace boost::process;
boost::asio::io_service ios;
std::vector<char> buf(200);
async_pipe ap(ios);
void read_from_buffer(const boost::system::error_code &ec, std::size_t size)
{
if (ec)
{
std::cout << "error" << std::endl;
return;
}
std::cout << "--read-- " << size << std::endl;
for (size_t i = 0; i < size; i++) std::cout << buf[i];
std::cout << std::endl;
ap.async_read_some(boost::asio::buffer(buf), read_from_buffer);
}
int main()
{
child c("MyApp.exe --args", std_out > ap);
ap.async_read_some(boost::asio::buffer(buf), read_from_buffer);
ios.run();
int result = c.exit_code();
}