[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - net/Socket.hpp
Michael Meeks
michael.meeks at collabora.com
Mon Mar 6 16:21:48 UTC 2017
net/Socket.hpp | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
New commits:
commit ef71c66b658538bdd7f1980bb0425f7b92ba49fc
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Mar 6 16:20:03 2017 +0000
Socket API to allow asynchronous writing.
diff --git a/net/Socket.hpp b/net/Socket.hpp
index ba55503..3090297 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -353,6 +353,12 @@ public:
/// Called after successful socket reads.
virtual void handleIncomingMessage() = 0;
+ /// Is there queued up data that we want to write ?
+ virtual bool hasQueuedWrites() const { return false; }
+
+ /// Do some of the queued writing.
+ virtual void performWrites() {}
+
/// Called when the is disconnected and will be destroyed.
/// Will be called exactly once.
virtual void onDisconnect()
@@ -387,8 +393,11 @@ public:
int getPollEvents() override
{
- // Only poll for read if we have nothing to write.
- return (_outBuffer.empty() ? POLLIN : POLLIN | POLLOUT);
+ std::cerr << "empty ? " << _outBuffer.empty() << " has queued write " << _socketHandler->hasQueuedWrites() << "\n";
+ if (!_outBuffer.empty() || _socketHandler->hasQueuedWrites())
+ return POLLIN | POLLOUT;
+ else
+ return POLLIN;
}
/// Send data to the socket peer.
@@ -488,6 +497,10 @@ protected:
_socketHandler->handleIncomingMessage();
}
+ // If we have space for writing and that was requested
+ if ((events & POLLOUT) && _outBuffer.empty())
+ _socketHandler->performWrites();
+
// SSL might want to do handshake,
// even if we have no data to write.
if ((events & POLLOUT) || !_outBuffer.empty())
More information about the Libreoffice-commits
mailing list