wip: Inter-process messaging

This commit is contained in:
Michael Carlberg
2016-11-13 19:05:30 +01:00
parent c480f6fd1e
commit 489f3ce480
7 changed files with 164 additions and 30 deletions

View File

@ -37,26 +37,24 @@ namespace io_util {
}
string readline(int read_fd, int& bytes_read) {
std::stringstream buffer;
stringstream buffer;
char char_;
int bytes = 0;
bytes_read = 0;
while ((bytes_read += ::read(read_fd, &char_, 1)) > 0) {
buffer << char_;
while ((bytes = ::read(read_fd, &char_, 1)) > 0) {
if (bytes <= 0)
break;
if (char_ == '\n' || char_ == '\x00')
break;
bytes_read += bytes;
buffer << char_;
}
if (bytes_read == 0) {
// Reached EOF
} else if (bytes_read == -1) {
// Read failed
} else {
return string_util::strip_trailing_newline(buffer.str());
}
if (bytes_read <= 0)
return "";
return "";
return string_util::strip_trailing_newline(buffer.str());
}
string readline(int read_fd) {