2016-03-27 14:22:24 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "IoUtil.hpp"
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-03-27 14:22:24 -05:00
|
|
|
#include <sys/poll.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <mutex>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include <Poco/Net/NetException.h>
|
2016-04-12 15:13:19 -05:00
|
|
|
#include <Poco/Net/Socket.h>
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include <Poco/StringTokenizer.h>
|
2016-03-27 14:22:24 -05:00
|
|
|
#include <Poco/Thread.h>
|
2016-04-10 12:13:05 -05:00
|
|
|
#include <Poco/URI.h>
|
2016-03-27 14:22:24 -05:00
|
|
|
|
|
|
|
#include "Common.hpp"
|
2016-03-27 15:06:22 -05:00
|
|
|
#include "LOOLProtocol.hpp"
|
2016-11-10 02:47:25 -06:00
|
|
|
#include <LOOLWebSocket.hpp>
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "Log.hpp"
|
2016-03-27 14:22:24 -05:00
|
|
|
#include "Util.hpp"
|
|
|
|
|
2016-04-12 15:13:19 -05:00
|
|
|
using Poco::Net::Socket;
|
2016-03-27 15:06:22 -05:00
|
|
|
using Poco::Net::WebSocket;
|
|
|
|
|
2016-04-04 06:21:04 -05:00
|
|
|
namespace IoUtil
|
|
|
|
{
|
|
|
|
|
2016-11-10 02:47:25 -06:00
|
|
|
// Synchronously process LOOLWebSocket requests and dispatch to handler.
|
2016-03-27 15:06:22 -05:00
|
|
|
// Handler returns false to end.
|
2016-11-10 02:47:25 -06:00
|
|
|
void SocketProcessor(const std::shared_ptr<LOOLWebSocket>& ws,
|
2016-11-13 21:23:04 -06:00
|
|
|
const std::string& name,
|
2016-04-27 07:58:33 -05:00
|
|
|
const std::function<bool(const std::vector<char>&)>& handler,
|
|
|
|
const std::function<void()>& closeFrame,
|
|
|
|
const std::function<bool()>& stopPredicate)
|
2016-03-27 15:06:22 -05:00
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_INF("SocketProcessor [" << name << "] starting.");
|
2016-03-27 15:06:22 -05:00
|
|
|
|
|
|
|
// Timeout given is in microseconds.
|
2016-05-07 08:45:57 -05:00
|
|
|
static const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
|
2016-11-13 20:52:02 -06:00
|
|
|
const auto bufferSize = READ_BUFFER_SIZE * 100;
|
|
|
|
int flags = 0;
|
|
|
|
int n = -1;
|
|
|
|
bool stop = false;
|
|
|
|
std::vector<char> payload(bufferSize);
|
2016-03-27 15:06:22 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
ws->setReceiveTimeout(0);
|
|
|
|
|
2016-04-09 14:41:32 -05:00
|
|
|
payload.resize(0);
|
2016-03-27 15:06:22 -05:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
stop = stopPredicate();
|
|
|
|
if (stop)
|
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_INF("SocketProcessor [" << name << "]: Stop flagged.");
|
2016-03-27 15:06:22 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-02 18:53:13 -05:00
|
|
|
if (!ws->poll(waitTime, Poco::Net::Socket::SELECT_READ) ||
|
|
|
|
stopPredicate())
|
2016-03-27 15:06:22 -05:00
|
|
|
{
|
|
|
|
// Wait some more.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-01 11:44:51 -05:00
|
|
|
try
|
|
|
|
{
|
2016-11-13 20:52:02 -06:00
|
|
|
payload.resize(payload.capacity());
|
|
|
|
n = -1;
|
2016-11-12 12:12:26 -06:00
|
|
|
n = ws->receiveFrame(payload.data(), payload.capacity(), flags);
|
2016-11-13 20:52:02 -06:00
|
|
|
payload.resize(n > 0 ? n : 0);
|
2016-09-01 11:44:51 -05:00
|
|
|
}
|
2016-09-01 14:11:41 -05:00
|
|
|
catch (const Poco::TimeoutException&)
|
2016-09-01 11:44:51 -05:00
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_DBG("SocketProcessor [" << name << "]: Spurious TimeoutException, ignored");
|
2016-09-01 11:44:51 -05:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-27 15:06:22 -05:00
|
|
|
|
2016-05-03 01:28:57 -05:00
|
|
|
if (n <= 0 || ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE))
|
2016-03-27 15:06:22 -05:00
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_WRN("SocketProcessor [" << name << "]: Connection closed.");
|
2016-11-13 20:52:02 -06:00
|
|
|
closeFrame();
|
2016-03-27 15:06:22 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(n > 0);
|
|
|
|
|
|
|
|
const std::string firstLine = LOOLProtocol::getFirstLine(payload);
|
|
|
|
if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != WebSocket::FrameFlags::FRAME_FLAG_FIN)
|
|
|
|
{
|
|
|
|
// One WS message split into multiple frames.
|
2016-11-13 20:52:02 -06:00
|
|
|
// TODO: Is this even possible with Poco if we never construct such messages outselves?
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_WRN("SocketProcessor [" << name << "]: Receiving multi-parm frame.");
|
2016-03-27 15:06:22 -05:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
char buffer[READ_BUFFER_SIZE * 10];
|
|
|
|
n = ws->receiveFrame(buffer, sizeof(buffer), flags);
|
|
|
|
if (n <= 0 || (flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE)
|
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_WRN("SocketProcessor [" << name << "]: Connection closed while reading multiframe message.");
|
2016-11-13 20:52:02 -06:00
|
|
|
closeFrame();
|
2016-03-27 15:06:22 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.insert(payload.end(), buffer, buffer + n);
|
|
|
|
if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) == WebSocket::FrameFlags::FRAME_FLAG_FIN)
|
|
|
|
{
|
|
|
|
// No more frames.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int size = 0;
|
|
|
|
Poco::StringTokenizer tokens(firstLine, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
2016-11-13 20:52:02 -06:00
|
|
|
// Check if it is a "nextmessage:" and in that case read the large
|
|
|
|
// follow-up message separately, and handle that only.
|
|
|
|
if (tokens.count() == 2 && tokens[0] == "nextmessage:" &&
|
|
|
|
LOOLProtocol::getTokenInteger(tokens[1], "size", size) && size > 0)
|
2016-03-27 15:06:22 -05:00
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_TRC("SocketProcessor [" << name << "]: Getting large message of " << size << " bytes.");
|
2016-11-13 20:52:02 -06:00
|
|
|
if (size > MAX_MESSAGE_SIZE)
|
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_ERR("SocketProcessor [" << name << "]: Large-message size (" << size << ") over limit or invalid.");
|
2016-11-13 20:52:02 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
payload.resize(size);
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-27 15:06:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n <= 0 || (flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE)
|
|
|
|
{
|
2016-04-18 18:12:26 -05:00
|
|
|
closeFrame();
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_WRN("SocketProcessor [" << name << "]: Connection closed.");
|
2016-03-27 15:06:22 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the handler.
|
2016-04-09 14:41:32 -05:00
|
|
|
const auto success = handler(payload);
|
|
|
|
payload.resize(0);
|
|
|
|
|
|
|
|
if (!success)
|
2016-03-27 15:06:22 -05:00
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_INF("SocketProcessor [" << name << "]: Handler flagged to finish.");
|
2016-03-27 15:06:22 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 14:41:32 -05:00
|
|
|
catch (const std::exception& exc)
|
2016-04-04 06:21:04 -05:00
|
|
|
{
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_ERR("SocketProcessor [" << name << "]: Exception: " << exc.what());
|
2016-04-04 06:21:04 -05:00
|
|
|
}
|
2016-03-27 15:06:22 -05:00
|
|
|
|
2016-11-13 20:52:02 -06:00
|
|
|
if ((flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && n > 0 && payload.size() > 0)
|
|
|
|
{
|
|
|
|
std::string msg;
|
|
|
|
Poco::URI::encode(std::string(payload.data(), payload.size()), "", msg);
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_WRN("SocketProcessor [" << name << "]: Last message (" << payload.size() <<
|
2016-11-13 20:52:02 -06:00
|
|
|
" bytes) will not be processed: [" << msg << "].");
|
|
|
|
}
|
|
|
|
|
2016-11-13 21:23:04 -06:00
|
|
|
LOG_INF("SocketProcessor [" << name << "] finished. stop: " << (stop ? "true" : "false") <<
|
2016-11-13 20:52:02 -06:00
|
|
|
", n: " << n << ", payload size: " << payload.size() <<
|
|
|
|
", flags: " << std::hex << flags);
|
2016-03-27 15:06:22 -05:00
|
|
|
}
|
2016-03-27 14:22:24 -05:00
|
|
|
|
2016-11-10 02:47:25 -06:00
|
|
|
void shutdownWebSocket(const std::shared_ptr<LOOLWebSocket>& ws)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-11-10 02:47:25 -06:00
|
|
|
// Calling LOOLWebSocket::shutdown, in case of error, would try to send a 'close' frame
|
2016-04-12 15:13:19 -05:00
|
|
|
// which won't work in case of broken pipe or timeout from peer. Just close the
|
|
|
|
// socket in that case preventing 'close' frame from being sent.
|
|
|
|
if (ws && ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR))
|
|
|
|
ws->close();
|
|
|
|
else if (ws)
|
2016-03-27 14:22:24 -05:00
|
|
|
ws->shutdown();
|
|
|
|
}
|
2016-04-08 06:25:42 -05:00
|
|
|
catch (const Poco::Exception& exc)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_WRN("Util::shutdownWebSocket: Exception: " << exc.displayText() <<
|
|
|
|
(exc.nested() ? " (" + exc.nested()->displayText() + ")" : ""));
|
2016-03-27 14:22:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:07:54 -05:00
|
|
|
ssize_t writeToPipe(int pipe, const char* buffer, ssize_t size)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
|
|
|
ssize_t count = 0;
|
|
|
|
while(true)
|
|
|
|
{
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_TRC("Writing to pipe. Data: [" << Util::formatLinesForLog(std::string(buffer, size)) << "].");
|
2016-03-28 15:07:02 -05:00
|
|
|
const auto bytes = write(pipe, buffer + count, size - count);
|
2016-03-27 14:22:24 -05:00
|
|
|
if (bytes < 0)
|
|
|
|
{
|
|
|
|
if (errno == EINTR || errno == EAGAIN)
|
|
|
|
continue;
|
|
|
|
|
2016-11-13 10:59:34 -06:00
|
|
|
LOG_SYS("Failed to write to pipe. Data: [" << std::string(buffer, size) << "].");
|
2016-03-27 14:22:24 -05:00
|
|
|
count = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (count + bytes < size)
|
|
|
|
{
|
|
|
|
count += bytes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count += bytes;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:07:54 -05:00
|
|
|
ssize_t readFromPipe(int pipe, char* buffer, ssize_t size)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
|
|
|
ssize_t bytes;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
bytes = read(pipe, buffer, size);
|
|
|
|
}
|
|
|
|
while (bytes < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2016-03-28 13:22:18 -05:00
|
|
|
/// Reads a single line from a pipe.
|
|
|
|
/// Returns 0 for timeout, <0 for error, and >0 on success.
|
|
|
|
/// On success, line will contain the read message.
|
|
|
|
int PipeReader::readLine(std::string& line,
|
2016-04-27 07:58:33 -05:00
|
|
|
const std::function<bool()>& stopPredicate)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
const char *endOfLine = static_cast<const char *>(std::memchr(_data.data(), '\n', _data.size()));
|
|
|
|
if (endOfLine != nullptr)
|
|
|
|
{
|
|
|
|
// We have a line cached, return it.
|
|
|
|
line += std::string(_data.data(), endOfLine);
|
|
|
|
_data.erase(0, endOfLine - _data.data() + 1); // Including the '\n'.
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_TRC("Read existing line from pipe: " << _name << ", line: [" <<
|
|
|
|
line << "], data: [" << Util::formatLinesForLog(_data) << "].");
|
2016-03-28 13:22:18 -05:00
|
|
|
return 1;
|
|
|
|
}
|
2016-03-27 14:22:24 -05:00
|
|
|
|
2016-03-28 13:22:18 -05:00
|
|
|
// Poll in short intervals to check for stop condition.
|
|
|
|
const auto pollTimeoutMs = 500;
|
2016-10-14 22:00:33 -05:00
|
|
|
auto maxPollCount = std::max<int>(POLL_TIMEOUT_MS / pollTimeoutMs, 1);
|
2016-03-28 13:22:18 -05:00
|
|
|
while (maxPollCount-- > 0)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
if (stopPredicate())
|
|
|
|
{
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_INF("Stop requested for pipe: " << _name << '.');
|
2016-03-28 13:22:18 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pollfd pipe;
|
|
|
|
pipe.fd = _pipe;
|
|
|
|
pipe.events = POLLIN;
|
|
|
|
pipe.revents = 0;
|
|
|
|
const int ready = poll(&pipe, 1, pollTimeoutMs);
|
|
|
|
if (ready == 0)
|
|
|
|
{
|
|
|
|
// Timeout.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (ready < 0)
|
|
|
|
{
|
|
|
|
// error.
|
|
|
|
return ready;
|
|
|
|
}
|
|
|
|
else if (pipe.revents & (POLLIN | POLLPRI))
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
char buffer[READ_BUFFER_SIZE];
|
2016-10-12 11:07:54 -05:00
|
|
|
const auto bytes = readFromPipe(_pipe, buffer, sizeof(buffer));
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_TRC("readFromPipe for pipe: " << _name << " returned: " << bytes);
|
2016-03-28 13:22:18 -05:00
|
|
|
if (bytes < 0)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
return -1;
|
2016-03-27 14:22:24 -05:00
|
|
|
}
|
2016-03-28 13:22:18 -05:00
|
|
|
|
2016-03-30 02:39:48 -05:00
|
|
|
endOfLine = static_cast<const char *>(std::memchr(buffer, '\n', bytes));
|
2016-03-28 13:22:18 -05:00
|
|
|
if (endOfLine != nullptr)
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
// Got end of line.
|
|
|
|
line = _data;
|
2016-03-28 15:07:02 -05:00
|
|
|
const auto tail = std::string(static_cast<const char*>(buffer), endOfLine);
|
2016-03-28 13:22:18 -05:00
|
|
|
line += tail;
|
2016-03-28 15:07:02 -05:00
|
|
|
_data = std::string(endOfLine + 1, bytes - tail.size() - 1); // Exclude the '\n'.
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_TRC("Read line from pipe: " << _name << ", line: [" << line <<
|
|
|
|
"], data: [" << Util::formatLinesForLog(_data) << "].");
|
2016-03-28 13:22:18 -05:00
|
|
|
return 1;
|
2016-03-27 14:22:24 -05:00
|
|
|
}
|
2016-03-28 13:22:18 -05:00
|
|
|
else
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
// More data, keep going.
|
|
|
|
_data += std::string(buffer, bytes);
|
2016-11-09 22:27:17 -06:00
|
|
|
LOG_TRC("data appended to pipe: " << _name << ", data: " << _data);
|
2016-03-27 14:22:24 -05:00
|
|
|
}
|
|
|
|
}
|
2016-03-28 13:22:18 -05:00
|
|
|
else if (pipe.revents & (POLLERR | POLLHUP | POLLNVAL))
|
2016-03-27 14:22:24 -05:00
|
|
|
{
|
2016-03-28 13:22:18 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2016-03-27 14:22:24 -05:00
|
|
|
|
2016-03-28 13:22:18 -05:00
|
|
|
// Timeout.
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-27 14:22:24 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|