1 | #include <boost/iostreams/device/file_descriptor.hpp>
|
---|
2 | #include <boost/iostreams/get.hpp>
|
---|
3 | #include <iostream>
|
---|
4 | #include <Windows.h>
|
---|
5 |
|
---|
6 | using namespace boost::iostreams;
|
---|
7 |
|
---|
8 | int main()
|
---|
9 | {
|
---|
10 | HANDLE handles[2];
|
---|
11 | SECURITY_ATTRIBUTES sa;
|
---|
12 | ZeroMemory(&sa, sizeof(sa));
|
---|
13 | sa.nLength = sizeof(sa);
|
---|
14 | CreatePipe(&handles[0], &handles[1], &sa, 0);
|
---|
15 |
|
---|
16 | char buffer[2] = { 'a', 'b' };
|
---|
17 | DWORD written;
|
---|
18 | WriteFile(handles[1], buffer, 2, &written, NULL);
|
---|
19 | CloseHandle(handles[1]);
|
---|
20 |
|
---|
21 | file_descriptor_source is(handles[0], close_handle);
|
---|
22 |
|
---|
23 | std::cout << get(is) << std::endl; // 97
|
---|
24 | std::cout << get(is) << std::endl; // 98
|
---|
25 | std::cout << get(is) << std::endl; // should be: -1 (but throws an exception)
|
---|
26 | std::cout << get(is) << std::endl; // should be: -1
|
---|
27 | }
|
---|