-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpipefile.hpp
More file actions
63 lines (49 loc) · 830 Bytes
/
pipefile.hpp
File metadata and controls
63 lines (49 loc) · 830 Bytes
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
63
/*
pipefile.hpp
sdragonx 2018-11-24 13:34:18
*/
#ifndef PIPEFILE_HPP_20181124133418
#define PIPEFILE_HPP_20181124133418
#include <cgl/public.h>
#include <unistd.h>
namespace cgl{
namespace io{
class pipefile
{
private:
int _pipe_io[2];
public:
pipefile()
{
_pipe_io[0] = _pipe_io[1] = 0;
}
int create()
{
return pipe(_pipe_io);
}
int in()const
{
return _pipe_io[0];
}
int out()const
{
return _pipe_io[1];
}
void close()
{
if(_pipe_io[0])::close(_pipe_io[0]);
if(_pipe_io[1])::close(_pipe_io[1]);
_pipe_io[0] = _pipe_io[1] = 0;
}
int read(void* data, size_t size)
{
return ::read(_pipe_io[0], data, size);
}
int write(const void* data, size_t size)
{
return ::write(_pipe_io[1], data, size);
}
};
}//end namespace io
}//end namespace cgl
#endif //PIPEFILE_HPP_20181124133418