[Libreoffice-commits] online.git: 3 commits - Mobile/Mobile net/FakeSocket.cpp net/Socket.hpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Sep 19 17:04:10 UTC 2018


 Mobile/Mobile/DocumentViewController.mm |    6 +++---
 net/FakeSocket.cpp                      |   31 ++++++++++++++++++++++++++-----
 net/Socket.hpp                          |    4 ++--
 3 files changed, 31 insertions(+), 10 deletions(-)

New commits:
commit f4ce5df7e1277ce9ffe4a58e6a2fcbf83141ff07
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Sep 19 20:01:13 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Sep 19 20:03:24 2018 +0300

    Implement the timeout parameter to fakeSocketPoll()
    
    Adapt callers that mistakenly passed 0 assuming it meant "forever".
    
    This also seems to help with the occasional hangs.

diff --git a/Mobile/Mobile/DocumentViewController.mm b/Mobile/Mobile/DocumentViewController.mm
index c3da9f6d6..5f203fdef 100644
--- a/Mobile/Mobile/DocumentViewController.mm
+++ b/Mobile/Mobile/DocumentViewController.mm
@@ -164,7 +164,7 @@
                                    struct pollfd p;
                                    p.fd = self.document->fakeClientFd;
                                    p.events = POLLIN;
-                                   if (fakeSocketPoll(&p, 1, 0) == 1) {
+                                   if (fakeSocketPoll(&p, 1, -1) == 1) {
                                        int n = fakeSocketAvailableDataLength(self.document->fakeClientFd);
                                        if (n == 0)
                                            return;
@@ -183,7 +183,7 @@
             std::string url([[[self.document fileURL] absoluteString] UTF8String]);
             p.fd = self.document->fakeClientFd;
             p.events = POLLOUT;
-            fakeSocketPoll(&p, 1, 0);
+            fakeSocketPoll(&p, 1, -1);
             fakeSocketWrite(self.document->fakeClientFd, url.c_str(), url.size());
 
             return;
@@ -192,7 +192,7 @@
         const char *buf = [message.body UTF8String];
         p.fd = self.document->fakeClientFd;
         p.events = POLLOUT;
-        fakeSocketPoll(&p, 1, 0);
+        fakeSocketPoll(&p, 1, -1);
         fakeSocketWrite(self.document->fakeClientFd, buf, strlen(buf));
     } else {
         NSLog(@"Unrecognized kind of message received from WebView: %@: %@", message.name, message.body);
diff --git a/net/FakeSocket.cpp b/net/FakeSocket.cpp
index a80c6ba84..75c85fd71 100644
--- a/net/FakeSocket.cpp
+++ b/net/FakeSocket.cpp
@@ -245,15 +245,34 @@ int fakeSocketPoll(struct pollfd *pollfds, int nfds, int timeout)
             loggingBuffer << ",";
         loggingBuffer << "#" << pollfds[i].fd << ":" << pollBits(pollfds[i].events);
     }
-    loggingBuffer << flush();
+    loggingBuffer << ", timeout:" << timeout << flush();
 
     std::vector<FakeSocketPair>& fds = getFds();
     std::unique_lock<std::mutex> fdsLock(fdsMutex);
     std::unique_lock<std::mutex> cvLock(cvMutex);
     fdsLock.unlock();
 
-    while (!checkForPoll(fds, pollfds, nfds))
-        cv.wait(cvLock);
+    if (timeout > 0)
+    {
+        auto const now = std::chrono::steady_clock::now();
+        auto const end = now + std::chrono::milliseconds(timeout);
+
+        while (!checkForPoll(fds, pollfds, nfds))
+            if (cv.wait_until(cvLock, end) == std::cv_status::timeout)
+            {
+                loggingBuffer << "FakeSocket Poll timeout: 0" << flush();
+                return 0;
+            }
+    }
+    else if (timeout == 0)
+    {
+        checkForPoll(fds, pollfds, nfds);
+    }
+    else // timeout < 0
+    {
+        while (!checkForPoll(fds, pollfds, nfds))
+            cv.wait(cvLock);
+    }
 
     int result = 0;
     for (int i = 0; i < nfds; i++)
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 7bb442b41..671f345ba 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -582,7 +582,7 @@ public:
             struct pollfd p;
             p.fd = fd;
             p.events = POLLOUT;
-            fakeSocketPoll(&p, 1, 0);
+            fakeSocketPoll(&p, 1, -1);
 #endif
             rc = fakeSocketWrite(fd, "w", 1);
 #endif
@@ -1049,7 +1049,7 @@ protected:
         struct pollfd p;
         p.fd = getFD();
         p.events = POLLOUT;
-        fakeSocketPoll(&p, 1, 0);
+        fakeSocketPoll(&p, 1, -1);
         return fakeSocketWrite(getFD(), buf, len);
 #endif
     }
commit 5ee96e02719070f5798ca7333ee0926c7a30e84b
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Sep 19 17:18:29 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Sep 19 20:03:24 2018 +0300

    Small correction to poll semantics

diff --git a/net/FakeSocket.cpp b/net/FakeSocket.cpp
index 4fe114777..a80c6ba84 100644
--- a/net/FakeSocket.cpp
+++ b/net/FakeSocket.cpp
@@ -196,12 +196,16 @@ static bool checkForPoll(std::vector<FakeSocketPair>& fds, struct pollfd *pollfd
         if (pollfds[i].fd < 0 || pollfds[i].fd/2 >= fds.size())
         {
             pollfds[i].revents = POLLNVAL;
+            retval = true;
         }
         else
         {
             const int K = ((pollfds[i].fd)&1);
             if (fds[pollfds[i].fd/2].fd[K] == -1)
+            {
                 pollfds[i].revents = POLLNVAL;
+                retval = true;
+            }
             else
                 pollfds[i].revents = 0;
         }
commit 8b5246b0389bfe86e4ae3894de3777abbd7cbaa7
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Sep 19 17:06:08 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Sep 19 20:03:24 2018 +0300

    Bin one presumably pointless lock and unlock

diff --git a/net/FakeSocket.cpp b/net/FakeSocket.cpp
index 384c0ab3d..4fe114777 100644
--- a/net/FakeSocket.cpp
+++ b/net/FakeSocket.cpp
@@ -389,11 +389,9 @@ int fakeSocketAccept4(int fd, int flags)
         return -1;
     }
 
-    std::unique_lock<std::mutex> fdLock(pair.mutex[0]);
     fdsLock.unlock();
 
     std::unique_lock<std::mutex> cvLock(cvMutex);
-    fdLock.unlock();
 
     while (pair.connectingFd == -1)
         cv.wait(cvLock);


More information about the Libreoffice-commits mailing list