[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - net/loolnb.cpp net/socket.hpp
Michael Meeks
michael.meeks at collabora.com
Wed Feb 15 00:00:10 UTC 2017
net/loolnb.cpp | 15 ++++++++++-----
net/socket.hpp | 6 ++++--
2 files changed, 14 insertions(+), 7 deletions(-)
New commits:
commit cd79e8cb3aabf0fad1f1a065e0529d08517eb94e
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Tue Feb 14 23:59:28 2017 +0000
Handle EOF - ie. zero length reads on sockets.
Close and cleanup sockets nicely.
diff --git a/net/loolnb.cpp b/net/loolnb.cpp
index d457471..da7b17a 100644
--- a/net/loolnb.cpp
+++ b/net/loolnb.cpp
@@ -156,6 +156,11 @@ private:
_newSockets.clear();
}
+ void removeSocketFromPoll(const std::shared_ptr<T>& socket)
+ {
+ _pollSockets.erase(_pollSockets.find(socket));
+ }
+
/// Initialize the poll fds array with the right events
void setupPollFds()
{
@@ -265,18 +270,18 @@ void pollAndComm(SocketPoll<SimpleResponseClient>& poller, std::atomic<bool>& st
{
poller.poll(5000, [](const std::shared_ptr<SimpleResponseClient>& socket, const int events)
{
+ bool closeSocket = false;
+
if (events & POLLIN)
- socket->readIncomingData();
+ closeSocket = !socket->readIncomingData();
if (events & POLLOUT)
socket->writeOutgoingData();
if (events & (POLLHUP | POLLERR | POLLNVAL))
- {
- // FIXME - close and remove the socket ...
- }
+ closeSocket = true;
- return true;
+ return !closeSocket;
});
}
}
diff --git a/net/socket.hpp b/net/socket.hpp
index 55ca6b7..17a3d9d 100644
--- a/net/socket.hpp
+++ b/net/socket.hpp
@@ -227,7 +227,7 @@ public:
std::vector< unsigned char > _inBuffer;
std::vector< unsigned char > _outBuffer;
public:
- void readIncomingData()
+ bool readIncomingData()
{
ssize_t len;
unsigned char buf[4096];
@@ -241,6 +241,8 @@ public:
handleIncomingMessage();
}
// else poll will handle errors.
+
+ return len != 0; // zero is eof / clean socket close.
}
void writeOutgoingData()
@@ -260,7 +262,7 @@ public:
int getPollEvents()
{
- int pollFor = POLLIN | POLLPRI;
+ int pollFor = POLLIN;
if (_outBuffer.size() > 0)
pollFor |= POLLOUT;
return pollFor;
More information about the Libreoffice-commits
mailing list