[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp
Michael Meeks
michael.meeks at collabora.com
Fri Mar 31 14:04:11 UTC 2017
net/Socket.hpp | 23 +++++------------------
net/WebSocketHandler.hpp | 6 ++----
2 files changed, 7 insertions(+), 22 deletions(-)
New commits:
commit 194c169f6811d0a00e04108ef2f3e4061ca4fac8
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Mar 31 12:25:21 2017 +0100
Remove obsolete write-lock.
The lock was used incompletely & inconsistently, and we should
always and only ever write in the associated SocketPoll's thread.
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 0b765731..c45caf77 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -617,10 +617,9 @@ public:
/// Send data to the socket peer.
void send(const char* data, const int len, const bool flush = true)
{
- assert(isCorrectThread());
+ assert(isCorrectThread(true));
if (data != nullptr && len > 0)
{
- auto lock = getWriteLock();
_outBuffer.insert(_outBuffer.end(), data, data + len);
if (flush)
writeOutgoingData();
@@ -700,7 +699,7 @@ protected:
HandleResult handlePoll(std::chrono::steady_clock::time_point now,
const int events) override
{
- assert(isCorrectThread());
+ assert(isCorrectThread(true));
_socketHandler->checkTimeout(now);
@@ -746,14 +745,9 @@ protected:
oldSize = _outBuffer.size();
// Write if we can and have data to write.
- if ((events & POLLOUT) || !_outBuffer.empty())
+ if ((events & POLLOUT) && !_outBuffer.empty())
{
- std::unique_lock<std::mutex> lock(_writeMutex, std::defer_lock);
-
- // The buffer could have been flushed while we waited for the lock.
- if (lock.try_lock() && !_outBuffer.empty())
- writeOutgoingData();
-
+ writeOutgoingData();
closed = closed || (errno == EPIPE);
}
}
@@ -773,9 +767,7 @@ protected:
/// Override to write data out to socket.
virtual void writeOutgoingData()
{
- assert(isCorrectThread());
-
- Util::assertIsLocked(_writeMutex);
+ assert(isCorrectThread(true));
assert(!_outBuffer.empty());
do
{
@@ -826,9 +818,6 @@ protected:
void dumpState(std::ostream& os) override;
- /// Get the Write Lock.
- std::unique_lock<std::mutex> getWriteLock() { return std::unique_lock<std::mutex>(_writeMutex); }
-
protected:
/// Client handling the actual data.
std::shared_ptr<SocketHandlerInterface> _socketHandler;
@@ -842,8 +831,6 @@ protected:
std::vector< char > _inBuffer;
std::vector< char > _outBuffer;
- std::mutex _writeMutex;
-
// To be able to access _inBuffer and _outBuffer.
// TODO we probably need accessors to the _inBuffer & _outBuffer
// instead of this many friends...
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index ac04da53..a7cae8f4 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -123,7 +123,6 @@ public:
const unsigned char flags = static_cast<unsigned char>(WSFrameMask::Fin)
| static_cast<char>(WSOpCode::Close);
- auto lock = socket->getWriteLock();
sendFrame(socket, buf.data(), buf.size(), flags);
}
@@ -316,8 +315,7 @@ public:
if (socket == nullptr)
return -1; // no socket == error.
- assert(socket->isCorrectThread());
- auto lock = socket->getWriteLock();
+ assert(socket->isCorrectThread(true));
std::vector<char>& out = socket->_outBuffer;
//TODO: Support fragmented messages.
@@ -349,7 +347,7 @@ protected:
if (!socket || data == nullptr || len == 0)
return -1;
- assert(socket->isCorrectThread());
+ assert(socket->isCorrectThread(true));
std::vector<char>& out = socket->_outBuffer;
out.push_back(flags);
More information about the Libreoffice-commits
mailing list