loolwsd: cleanup of unittests and helpers
Change-Id: I03a5cb29b51409f3b8cc51981b522248a29a6ba3 Reviewed-on: https://gerrit.libreoffice.org/28955 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
parent
67c05ec319
commit
d2872846d8
1 changed files with 9 additions and 49 deletions
|
@ -238,8 +238,9 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
|
|||
}
|
||||
|
||||
inline
|
||||
std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, const std::string& name = "")
|
||||
std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string name = "")
|
||||
{
|
||||
name = name + '[' + prefix + "] ";
|
||||
try
|
||||
{
|
||||
int flags = 0;
|
||||
|
@ -256,15 +257,16 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
|
|||
int bytes = ws.receiveFrame(response.data(), response.size(), flags);
|
||||
response.resize(bytes >= 0 ? bytes : 0);
|
||||
auto message = LOOLProtocol::getAbbreviatedMessage(response);
|
||||
std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
|
||||
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
||||
{
|
||||
if (message.find(prefix) == 0)
|
||||
{
|
||||
std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
|
||||
return response;
|
||||
}
|
||||
else if (message.find("nextmessage") == 0)
|
||||
{
|
||||
std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
|
||||
Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
||||
int size = 0;
|
||||
if (tokens.count() == 2 &&
|
||||
|
@ -274,9 +276,9 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
|
|||
bytes = ws.receiveFrame(response.data(), response.size(), flags);
|
||||
response.resize(bytes >= 0 ? bytes : 0);
|
||||
message = LOOLProtocol::getAbbreviatedMessage(response);
|
||||
std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
|
||||
if (bytes > 0 && message.find(prefix) == 0)
|
||||
{
|
||||
std::cerr << name << "Got " << bytes << " bytes: " << message << std::endl;
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -293,11 +295,13 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
|
|||
{
|
||||
break;
|
||||
}
|
||||
|
||||
std::cerr << name << "Ignored: " << message << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << name << "Timeout waiting for " << prefix << "\n";
|
||||
--retries;
|
||||
std::cerr << name << "Timeout " << retries << std::endl;
|
||||
}
|
||||
}
|
||||
while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
||||
|
@ -467,51 +471,7 @@ void parseDocSize(const std::string& message, const std::string& type,
|
|||
inline
|
||||
std::vector<char> getTileMessage(Poco::Net::WebSocket& ws, const std::string& name = "")
|
||||
{
|
||||
int flags = 0;
|
||||
int retries = 20;
|
||||
static const Poco::Timespan waitTime(1000000);
|
||||
std::vector<char> response(READ_BUFFER_SIZE);
|
||||
|
||||
// 5 seconds timeout
|
||||
ws.setReceiveTimeout(5000000);
|
||||
do
|
||||
{
|
||||
if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
|
||||
{
|
||||
response.resize(READ_BUFFER_SIZE);
|
||||
int bytes = ws.receiveFrame(response.data(), response.size(), flags);
|
||||
response.resize(bytes >= 0 ? bytes : 0);
|
||||
auto message = LOOLProtocol::getAbbreviatedMessage(response);
|
||||
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
|
||||
{
|
||||
if (message.find("nextmessage") == 0)
|
||||
{
|
||||
Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
|
||||
int size = 0;
|
||||
if (tokens.count() == 2 &&
|
||||
tokens[0] == "nextmessage:" && LOOLProtocol::getTokenInteger(tokens[1], "size", size) && size > 0)
|
||||
{
|
||||
std::cerr << name << " Got " << message << std::endl;
|
||||
response.resize(size);
|
||||
bytes = ws.receiveFrame(response.data(), response.size(), flags);
|
||||
response.resize(bytes >= 0 ? bytes : 0);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << name << "ignored " << message << std::endl;
|
||||
retries = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << name << "Timeout waiting for nextmessage:\n";
|
||||
--retries;
|
||||
}
|
||||
}
|
||||
while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
|
||||
|
||||
return std::vector<char>();
|
||||
return getResponseMessage(ws, "tile", name);
|
||||
}
|
||||
|
||||
inline
|
||||
|
|
Loading…
Reference in a new issue