File: autopipe.h

package info (click to toggle)
rsyncrypto 1.14-1.2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,552 kB
  • sloc: cpp: 3,459; sh: 1,221; makefile: 29
file content (62 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This is the Win32 version of this struct
#if !defined(_WIN32)
#error Win32 only header included from non-Win32 build environment
#endif

#ifndef _AUTOPIPE_H
#define _AUTOPIPE_H

class autopipe {
    autofd input, output;
public:
    explicit autopipe(DWORD pipe_size=4096) : input(INVALID_HANDLE_VALUE),
        output(INVALID_HANDLE_VALUE)
    {
        HANDLE hReadPipe, hWritePipe;

        if( CreatePipe(&hReadPipe, &hWritePipe, NULL, pipe_size ) ) {
            input=autofd(hReadPipe);
            output=autofd(hWritePipe);
        } else {
#if defined(EXCEPT_CLASS)
            throw EXCEPT_CLASS("Couldn't create pipe", GetLastError() );
#endif
        }
    }
    // Default copy constructor and operator= do exactly what we want.
    //autopipe( const autopipe &that )
    //autopipe &operator=( const autopipe &that )
    // As does default dtor
    //~autopipe()
    autofd &get_read()
    {
        return input;
    }
    const autofd &get_read() const
    {
        return input;
    }
    autofd &get_write()
    {
        return output;
    }
    const autofd &get_write() const
    {
        return output;
    }
    void clear_read()
    {
        input.clear();
    }
    void clear_write()
    {
        output.clear();
    }
    void clear()
    {
        clear_read();
        clear_write();
    }
};

#endif // _AUTOPIPE_H