Pipe example
#include <iostream>
#include <string>
#include <thread>
int main(int argc, char** argv)
{
std::cout << "Please enter some integer numbers. Enter '0' to exit..." << std::endl;
auto consumer = std::thread([&pipe]()
{
int item;
do
{
if (pipe.
Read(&item,
sizeof(item)) !=
sizeof(item))
break;
std::cout << "Your entered number: " << item << std::endl;
} while (item != 0);
});
std::string line;
while (getline(std::cin, line))
{
int item = std::stoi(line);
if (pipe.
Write(&item,
sizeof(item)) !=
sizeof(item))
break;
if (item == 0)
break;
}
consumer.join();
return 0;
}
size_t Read(void *buffer, size_t size) override
Read a bytes buffer from the pipe.
size_t Write(const void *buffer, size_t size) override
Write a byte buffer into the pipe.