loolwsd/LOOLWebSocket.hpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
New commits: commit 3cff7993019d10e7c11a3d9dd67ba760dcc061b8 Author: Ashod Nakashian <[email protected]> Date: Sat Nov 12 13:41:16 2016 -0500 loolwsd: Log error when not sending full frame ... and timeout when receiving frame. Change-Id: I5bb085f494fc146f7fbd75be3f3bb86597029369 Reviewed-on: https://gerrit.libreoffice.org/30818 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/LOOLWebSocket.hpp b/loolwsd/LOOLWebSocket.hpp index 212990a..672b93a 100644 --- a/loolwsd/LOOLWebSocket.hpp +++ b/loolwsd/LOOLWebSocket.hpp @@ -51,9 +51,12 @@ public: // Wrapper for LOOLWebSocket::receiveFrame() that handles PING frames (by replying with a // PONG frame) and PONG frames. PONG frames are ignored. // Should we also factor out the handling of non-final and continuation frames into this? - int receiveFrame(char* buffer, int length, int& flags) + int receiveFrame(char* buffer, const int length, int& flags) { - for (;;) + // Timeout given is in microseconds. + static const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000); + + while (poll(waitTime, Poco::Net::Socket::SELECT_READ)) { const int n = Poco::Net::WebSocket::receiveFrame(buffer, length, flags); if ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_PING) @@ -78,9 +81,9 @@ public: /// It would be a kind of more natural to encapsulate Poco::Net::WebSocket /// instead of inheriting (from that reason), but that would requite much /// larger code changes. - int sendFrame(const void * buffer, int length, int flags = FRAME_TEXT) + int sendFrame(const char* buffer, const int length, const int flags = FRAME_TEXT) { - std::lock_guard<std::mutex> lock(_mutex); + std::unique_lock<std::mutex> lock(_mutex); // Size after which messages will be sent preceded with // 'nextmessage' frame to let the receiver know in advance @@ -95,8 +98,19 @@ public: Log::debug("Message is long, sent " + nextmessage); } - int result = Poco::Net::WebSocket::sendFrame(buffer, length, flags); - Log::debug("Sent frame: " + LOOLProtocol::getAbbreviatedMessage(static_cast<const char*>(buffer), length)); + const int result = Poco::Net::WebSocket::sendFrame(buffer, length, flags); + + lock.unlock(); + + if (result != length) + { + LOG_ERR("Sent incomplete message, expected " << length << " bytes but sent " << result << + " while sending: " << LOOLProtocol::getAbbreviatedMessage(buffer, length)); + } + else + { + LOG_DBG("Sent frame: " << LOOLProtocol::getAbbreviatedMessage(buffer, length)); + } return result; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
