Last active
July 4, 2021 19:01
-
-
Save cfanatic/60cdf1549c4b28a30f8bc546a44a5d58 to your computer and use it in GitHub Desktop.
Non-blocking FIFO process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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