child.cpp 1.09 KB
Newer Older
Tijana Vukovic's avatar
Tijana Vukovic committed
1
#include <iostream>
2
#include <array>
Tijana Vukovic's avatar
Tijana Vukovic committed
3
4
5
6
#include <string>
#include <vector>
#include <Windows.h>

7
#include <migraphx/ranges.hpp>
Tijana Vukovic's avatar
Tijana Vukovic committed
8
#include <migraphx/errors.hpp>
9
10
#include <migraphx/file_buffer.hpp>
#include <migraphx/msgpack.hpp>
Tijana Vukovic's avatar
Tijana Vukovic committed
11

12
void read_stdin()
Tijana Vukovic's avatar
Tijana Vukovic committed
13
14
{
    std::vector<char> result;
15
16
17
18
    constexpr std::size_t BUFFER_SIZE = 1024;
    DWORD bytes_read;
    TCHAR buffer[BUFFER_SIZE];

Tijana Vukovic's avatar
Tijana Vukovic committed
19
20
21
22
23
    HANDLE std_in  = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE);

    if(std_in == INVALID_HANDLE_VALUE)
        MIGRAPHX_THROW("STDIN invalid handle (" + std::to_string(GetLastError()) + ")");
24
25
26
    if(std_out == INVALID_HANDLE_VALUE)
        MIGRAPHX_THROW("STDOUT invalid handle (" + std::to_string(GetLastError()) + ")");
    
Tijana Vukovic's avatar
Tijana Vukovic committed
27
28
29
30
31
32
33
34
    for(;;)
    {
        BOOL status = ReadFile(std_in, buffer, BUFFER_SIZE, &bytes_read, nullptr);
        if(status == FALSE or bytes_read == 0)
            break;
        DWORD written;
        if(WriteFile(std_out, buffer, bytes_read, &written, nullptr) == FALSE)
            break;
35
36
37
38
39
40
    }        
}

int main(int argc, char const* argv[]) {    
    read_stdin(); 
}