-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.cpp
More file actions
64 lines (58 loc) · 1.5 KB
/
Copy pathpipe.cpp
File metadata and controls
64 lines (58 loc) · 1.5 KB
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
64
#include "pipe.hpp"
namespace pipes
{
pipe::pipe()
{
mPipefd = 0;
}
pipe::pipe(int pPipefd)
{
mPipefd = pPipefd;
}
pipe::~pipe()
{
}
int pipe::fd()
{
return mPipefd;
}
std::string pipe::read()
{
char buffer[4096];
ssize_t len = ::read(mPipefd, buffer, 4096);
if (len < 0)
{
logs::fatal << LOC() << "(" << mPipefd << ") Error reading from pipe [" << std::strerror(errno) << "]" << logs::done;
exit(-1);
}
else
{
std::string data(buffer, len);
if (data.length() > 0 && data[0] == '+')
{
switch(data[1])
{
case '0':
logs::fatal << data.substr(4) << logs::done;
case '1':
logs::error << data.substr(4) << logs::done;
case '2':
logs::warn << data.substr(4) << logs::done;
case '3':
logs::info << data.substr(4) << logs::done;
case '4':
logs::debug << data.substr(4) << logs::done;
}
return std::string();
}
else
{
return data;
}
}
}
void pipe::write(std::string pData)
{
::write(mPipefd, pData.c_str(), pData.length());
}
}