[Libreoffice-commits] online.git: 3 commits - loleaflet/dist loolwsd/DocumentBroker.cpp loolwsd/IoUtil.cpp loolwsd/LOOLSession.cpp
Pranav Kant
pranavk at collabora.com
Wed Apr 13 06:53:28 UTC 2016
loleaflet/dist/toolbar/toolbar.js | 18 ++++++++++--
loolwsd/DocumentBroker.cpp | 1
loolwsd/IoUtil.cpp | 9 +++++-
loolwsd/LOOLSession.cpp | 53 +++++++++++++++++++++++++++-----------
4 files changed, 60 insertions(+), 21 deletions(-)
New commits:
commit 8f9d81280648bf4d3e9d193fe72d690eb7485ff8
Author: Pranav Kant <pranavk at collabora.com>
Date: Wed Apr 13 11:47:22 2016 +0530
loleaflet: We do not use underscores in identifier names
Change-Id: Ic466bb3067353c9d271ea264a323502a03ed2c2b
diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js
index 2942905..dc5ae16 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -138,7 +138,7 @@ $(function () {
{ type: 'html', id: 'modifiedstatuslabel', html: '<div id="modifiedstatuslabel"></div>' },
{ type: 'break' },
{ type: 'button', id: 'takeedit', img: 'edit', hint: _("Take edit lock (others can only view)")},
- { type: 'html', id: 'takeedit_text', html: '<div id="takeedit_text">VIEWING</div>' },
+ { type: 'html', id: 'takeeditlabel', html: '<div id="takeeditlabel">VIEWING</div>' },
{ type: 'break' },
{ type: 'button', id: 'prev', img: 'prev', hint: _("Previous page") },
{ type: 'button', id: 'next', img: 'next', hint: _("Next page") },
@@ -905,17 +905,17 @@ map.on('editlock', function (e) {
toolbar.disable('takeedit');
toolbar.set('takeedit', {hint: _('You are editing (others can only view)')});
- $('#takeedit_text').html('EDITING');
+ $('#takeeditlabel').html('EDITING');
}
else {
toolbar.uncheck('takeedit');
toolbar.enable('takeedit');
toolbar.set('takeedit', {hint: _('Take edit lock (others can only view)')});
- $('#takeedit_text')
+ $('#takeeditlabel')
.w2tag('You are viewing now')
.html('VIEWING');
setTimeout(function() {
- $('#takeedit_text').w2tag('');
+ $('#takeeditlabel').w2tag('');
}, 3000);
}
});
commit df0315f317f6774990dae5c94c6d2c90a44eebee
Author: Pranav Kant <pranavk at collabora.com>
Date: Wed Apr 13 11:45:56 2016 +0530
loleaflet: Change message on status bar when document is saved
... and empty the status bar when document is modified and not
yet saved on server.
Change-Id: I976405783f744b875b9f6ee7e700006bddf5bc6f
diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js
index b6a5b0e..2942905 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -135,6 +135,7 @@ $(function () {
{ type: 'button', id: 'duplicatepage', img: 'duplicatepage', hint: _("Duplicate Page") },
{ type: 'button', id: 'deletepage', img: 'deletepage', hint: _("Delete Page") },
{ type: 'html', id: 'right' },
+ { type: 'html', id: 'modifiedstatuslabel', html: '<div id="modifiedstatuslabel"></div>' },
{ type: 'break' },
{ type: 'button', id: 'takeedit', img: 'edit', hint: _("Take edit lock (others can only view)")},
{ type: 'html', id: 'takeedit_text', html: '<div id="takeedit_text">VIEWING</div>' },
@@ -693,6 +694,15 @@ map.on('commandstatechanged', function (e) {
var div = L.DomUtil.get('backcolorindicator');
L.DomUtil.setStyle(div, 'background', color);
}
+ else if (commandName === '.uno:ModifiedStatus') {
+ var modifiedStatus = e.state === 'true';
+ if (modifiedStatus) {
+ $('#modifiedstatuslabel').html('');
+ }
+ else {
+ $('#modifiedstatuslabel').html('Document saved');
+ }
+ }
formatButtons.forEach(function (id) {
if ('.uno:' + toolbar.get(id).uno === commandName) {
commit 9ea462483917401ecbe5339caf55437abefdb8da
Author: Pranav Kant <pranavk at collabora.com>
Date: Wed Apr 13 01:43:19 2016 +0530
loolwsd: Handle socket exceptions while trying to send frame
In case of abnormal termination of session from client-side,
we might still have data being processed in the kit process, for
example, during auto-save. Trying to send such data over an
expired socket towards the client would throw exceptions which
need to be handled, otherwise the auto-save process would not be
successful. Further, the unhandled exception can bring the document
broker in an unstable state with dockey still present in the
object.
Also do not send 'editlock: 0' to a websocket session which is
going to be removed because the session might have been
forcefully terminated from the client-side, in which case sending
data would go nowhere.
Change-Id: I10eb9c818bc81d4db26d5a19dc8bd44f6fbdf32c
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index d412b24..7a9fe20 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -279,7 +279,6 @@ void DocumentBroker::removeWSSession(const std::string id)
{
haveEditLock = it->second->isEditLocked();
it->second->setEditLock(false);
- it->second->sendTextFrame("editlock: 0");
_wsSessions.erase(it);
}
diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 0b9caaa..c002230 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -19,6 +19,7 @@
#include <Poco/StringTokenizer.h>
#include <Poco/Net/HTTPServerResponse.h>
+#include <Poco/Net/Socket.h>
#include <Poco/Net/WebSocket.h>
#include <Poco/Net/NetException.h>
#include <Poco/Thread.h>
@@ -30,6 +31,7 @@
#include "Util.hpp"
using Poco::Net::NetException;
+using Poco::Net::Socket;
using Poco::Net::WebSocket;
using Poco::Net::WebSocketException;
@@ -204,7 +206,12 @@ void shutdownWebSocket(std::shared_ptr<Poco::Net::WebSocket> ws)
{
try
{
- if (ws)
+ // Calling WebSocket::shutdown, in case of error, would try to send a 'close' frame
+ // 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)
ws->shutdown();
}
catch (const Poco::Exception& exc)
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index d4062bd..1b744f4 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -24,6 +24,7 @@
#include <set>
#include <Poco/Exception.h>
+#include <Poco/Net/Socket.h>
#include <Poco/Net/WebSocket.h>
#include <Poco/Path.h>
#include <Poco/String.h>
@@ -40,6 +41,7 @@ using namespace LOOLProtocol;
using Poco::Exception;
using Poco::IOException;
+using Poco::Net::Socket;
using Poco::Net::WebSocket;
using Poco::Path;
using Poco::StringTokenizer;
@@ -71,30 +73,41 @@ LOOLSession::~LOOLSession()
void LOOLSession::sendTextFrame(const std::string& text)
{
- if (!_ws)
+ if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR))
{
- Log::error("No socket to send " + getAbbreviatedMessage(text.c_str(), text.size()) + " to.");
+ Log::error("Socket error to send " + getAbbreviatedMessage(text.c_str(), text.size()) + " to.");
return;
}
else
Log::trace(getName() + " Send: " + getAbbreviatedMessage(text.c_str(), text.size()));
std::unique_lock<std::mutex> lock(_mutex);
- const int length = text.size();
- if ( length > SMALL_MESSAGE_SIZE )
+
+ try
{
- const std::string nextmessage = "nextmessage: size=" + std::to_string(length);
- _ws->sendFrame(nextmessage.data(), nextmessage.size());
- }
+ const int length = text.size();
+ if ( length > SMALL_MESSAGE_SIZE )
+ {
+ const std::string nextmessage = "nextmessage: size=" + std::to_string(length);
+ _ws->sendFrame(nextmessage.data(), nextmessage.size());
+ }
- _ws->sendFrame(text.data(), length);
+ _ws->sendFrame(text.data(), length);
+ }
+ catch (const Exception& exc)
+ {
+ Log::warn() << "LOOLSession::sendTextFrame: "
+ << "Exception: " << exc.displayText()
+ << (exc.nested() ? "( " + exc.nested()->displayText() + ")" : "");
+ IoUtil::shutdownWebSocket(_ws);
+ }
}
void LOOLSession::sendBinaryFrame(const char *buffer, int length)
{
- if (!_ws)
+ if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR))
{
- Log::error("No socket to send binary frame of " + std::to_string(length) + " bytes to.");
+ Log::error("Socket error to send binary frame of " + std::to_string(length) + " bytes to.");
return;
}
else
@@ -102,13 +115,23 @@ void LOOLSession::sendBinaryFrame(const char *buffer, int length)
std::unique_lock<std::mutex> lock(_mutex);
- if ( length > SMALL_MESSAGE_SIZE )
+ try
{
- const std::string nextmessage = "nextmessage: size=" + std::to_string(length);
- _ws->sendFrame(nextmessage.data(), nextmessage.size());
- }
+ if ( length > SMALL_MESSAGE_SIZE )
+ {
+ const std::string nextmessage = "nextmessage: size=" + std::to_string(length);
+ _ws->sendFrame(nextmessage.data(), nextmessage.size());
+ }
- _ws->sendFrame(buffer, length, WebSocket::FRAME_BINARY);
+ _ws->sendFrame(buffer, length, WebSocket::FRAME_BINARY);
+ }
+ catch (const Exception& exc)
+ {
+ Log::warn() << "LOOLSession::sendBinaryFrame: "
+ << "Exception: " << exc.displayText()
+ << (exc.nested() ? "( " + exc.nested()->displayText() + ")" : "");
+ IoUtil::shutdownWebSocket(_ws);
+ }
}
void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std::string& timestamp)
More information about the Libreoffice-commits
mailing list