Skip to content

Instantly share code, notes, and snippets.

@cfanatic
Last active July 4, 2021 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfanatic/60cdf1549c4b28a30f8bc546a44a5d58 to your computer and use it in GitHub Desktop.
Save cfanatic/60cdf1549c4b28a30f8bc546a44a5d58 to your computer and use it in GitHub Desktop.
Non-blocking FIFO process
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/asio.hpp>
#include <iostream>
void read_pipe()
{
int fifo_d;
boost::asio::io_service io_service;
std::vector<uint8_t> buffer(10);
fifo_d = open("/tmp/test", O_RDONLY | O_NONBLOCK);
boost::asio::posix::stream_descriptor fifo(io_service, fifo_d);
boost::asio::async_read(
fifo,
boost::asio::buffer(buffer),
[&](const boost::system::error_code &ec, std::size_t size)
{
for (auto x : buffer)
{
printf("%d\n", x);
}
std::cout << "Decoded data size: " << size << std::endl;
}
);
io_service.run();
close(fifo_d);
}
int main()
{
read_pipe();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment