bool HTTPWSTest::isDocumentLoaded(Poco::Net::WebSocket& ws) { bool isLoaded = false; try { int flags; int bytes; int retries = 30; const Poco::Timespan waitTime(1000000); ws.setReceiveTimeout(0); std::cout << "==> isDocumentLoaded\n"; do { char buffer[READ_BUFFER_SIZE]; if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ)) { bytes = ws.receiveFrame(buffer, sizeof(buffer), flags); std::cout << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n'; if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << '\n'; const std::string line = LOOLProtocol::getFirstLine(buffer, bytes); const std::string prefixIndicator = "statusindicatorfinish:"; const std::string prefixStatus = "status:"; if (line.find(prefixIndicator) == 0 || line.find(prefixStatus) == 0) { isLoaded = true; break; } } retries = 10; } else { std::cout << "Timeout\n"; --retries; } } while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); } catch (const Poco::Net::WebSocketException& exc) { std::cout << exc.message(); } return isLoaded; }
void HTTPWSTest::getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string& response, const bool isLine) { try { int flags; int bytes; int retries = 20; const Poco::Timespan waitTime(1000000); response.clear(); ws.setReceiveTimeout(0); std::cout << "==> getResponseMessage(" << prefix << ")\n"; do { char buffer[READ_BUFFER_SIZE]; if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ)) { bytes = ws.receiveFrame(buffer, sizeof(buffer), flags); std::cout << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n'; if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << '\n'; const std::string message = isLine ? LOOLProtocol::getFirstLine(buffer, bytes) : std::string(buffer, bytes); if (message.find(prefix) == 0) { response = message.substr(prefix.length()); break; } } retries = 10; } else { std::cout << "Timeout\n"; --retries; } } while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE); } catch (const Poco::Net::WebSocketException& exc) { std::cout << exc.message(); } }