File: autopipe.h

package info (click to toggle)
rsyncrypto 1.12-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 1,312 kB
  • ctags: 576
  • sloc: sh: 3,958; cpp: 3,253; makefile: 70
file content (62 lines) | stat: -rw-r--r-- 1,206 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)
#include "win32/autopipe.h"
#else
#ifndef _AUTOPIPE_H
#define _AUTOPIPE_H

class autopipe {
    autofd input, output;
public:
    explicit autopipe(size_t pipe_size=4096) : input(-1), output(-1)
    {
        int fd[2];

        if( pipe(fd)==0 ) {
            input=autofd(fd[0]);
            output=autofd(fd[1]);
        } else {
#if defined(EXCEPT_CLASS)
            throw EXCEPT_CLASS("Couldn't create pipe", errno );
#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
#endif // _WIN32