[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sat May 21 03:28:34 UTC 2016
loolwsd/LOOLSession.cpp | 36 ++++++++++++++++++++----------------
loolwsd/LOOLSession.hpp | 4 ++--
2 files changed, 22 insertions(+), 18 deletions(-)
New commits:
commit 32ee3d0650faf615acd901dae66980e9a29c9f02
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri May 20 18:52:12 2016 -0400
loolwsd: socket sending returns success or failure
Change-Id: I3f486b236e5b6a83292a9d7f3e4931e5235f3a33
Reviewed-on: https://gerrit.libreoffice.org/25239
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 55f84b2..7d4a889 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -71,20 +71,19 @@ LOOLSession::~LOOLSession()
{
}
-void LOOLSession::sendTextFrame(const std::string& text)
+bool LOOLSession::sendTextFrame(const std::string& text)
{
if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR))
{
Log::error(getName() + ": Bad socket while sending [" + getAbbreviatedMessage(text.c_str(), text.size()) + "].");
- return;
+ return false;
}
Log::trace(getName() + " Send: " + getAbbreviatedMessage(text.c_str(), text.size()));
-
- std::unique_lock<std::mutex> lock(_mutex);
-
try
{
+ std::unique_lock<std::mutex> lock(_mutex);
+
const int length = text.size();
if ( length > SMALL_MESSAGE_SIZE )
{
@@ -93,29 +92,31 @@ void LOOLSession::sendTextFrame(const std::string& text)
}
_ws->sendFrame(text.data(), length);
+ return true;
}
catch (const Exception& exc)
{
- Log::warn() << "LOOLSession::sendTextFrame: "
- << "Exception: " << exc.displayText()
- << (exc.nested() ? "( " + exc.nested()->displayText() + ")" : "");
+ Log::error() << "LOOLSession::sendTextFrame: "
+ << "Exception: " << exc.displayText()
+ << (exc.nested() ? "( " + exc.nested()->displayText() + ")" : "");
}
+
+ return false;
}
-void LOOLSession::sendBinaryFrame(const char *buffer, int length)
+bool LOOLSession::sendBinaryFrame(const char *buffer, int length)
{
if (!_ws || _ws->poll(Poco::Timespan(0), Socket::SelectMode::SELECT_ERROR))
{
Log::error(getName() + ": Bad socket while sending binary frame of " + std::to_string(length) + " bytes.");
- return;
+ return false;
}
Log::trace(getName() + " Send: " + std::to_string(length) + " bytes");
-
- std::unique_lock<std::mutex> lock(_mutex);
-
try
{
+ std::unique_lock<std::mutex> lock(_mutex);
+
if ( length > SMALL_MESSAGE_SIZE )
{
const std::string nextmessage = "nextmessage: size=" + std::to_string(length);
@@ -123,13 +124,16 @@ void LOOLSession::sendBinaryFrame(const char *buffer, int length)
}
_ws->sendFrame(buffer, length, WebSocket::FRAME_BINARY);
+ return true;
}
catch (const Exception& exc)
{
- Log::warn() << "LOOLSession::sendBinaryFrame: "
- << "Exception: " << exc.displayText()
- << (exc.nested() ? "( " + exc.nested()->displayText() + ")" : "");
+ Log::error() << "LOOLSession::sendBinaryFrame: "
+ << "Exception: " << exc.displayText()
+ << (exc.nested() ? "( " + exc.nested()->displayText() + ")" : "");
}
+
+ return false;
}
void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std::string& timestamp)
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index cf75433..915fb53 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -41,8 +41,8 @@ public:
const std::string& getName() const { return _name; }
bool isDisconnected() const { return _disconnected; }
- void sendTextFrame(const std::string& text);
- void sendBinaryFrame(const char *buffer, int length);
+ bool sendTextFrame(const std::string& text);
+ bool sendBinaryFrame(const char *buffer, int length);
bool handleInput(const char *buffer, int length);
More information about the Libreoffice-commits
mailing list