[Libreoffice-commits] online.git: net/Socket.hpp

2020-09-10 Thread Miklos Vajna (via logerrit)
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 330cfb1f0d9ec8455f59785b69b0c2b6c2862495
Author: Miklos Vajna 
AuthorDate: Thu Sep 10 09:17:44 2020 +0200
Commit: Miklos Vajna 
CommitDate: Thu Sep 10 14:23:22 2020 +0200

net: mark SocketPoll dtor as virtual

Because Admin derives from it, and UnitPHPProxy holds a
shared_ptr, so the non-virtual dtor was invoked for a class
whcih is not (and can't be) final.

Found by clang's -Werror,-Wdelete-non-abstract-non-virtual-dtor.

Change-Id: I9b31bb58e79b2da3a3896789c52258f315fdd3d6
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/102355
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index ce80d2253..7ec78f00a 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -513,7 +513,7 @@ class SocketPoll
 public:
 /// Create a socket poll, called rather infrequently.
 SocketPoll(const std::string& threadName);
-~SocketPoll();
+virtual ~SocketPoll();
 
 /// Default poll time - useful to increase for debugging.
 static int DefaultPollTimeoutMicroS;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2020-04-29 Thread Gabriel Masei (via logerrit)
 net/Socket.hpp |   19 ++-
 1 file changed, 6 insertions(+), 13 deletions(-)

New commits:
commit 753b0a8e91c65abc4ffbc8e0d3fd484e68b5b6de
Author: Gabriel Masei 
AuthorDate: Tue Apr 28 23:45:26 2020 +0300
Commit: Michael Meeks 
CommitDate: Wed Apr 29 14:45:19 2020 +0200

let the higher levels to process the recvmsg return value

Change-Id: I41c089229095739f38f40dbd0fb7c1d4c82efd41
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93110
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 34da98aab..37e289a63 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -1178,25 +1178,18 @@ protected:
 msg.msg_flags = 0;
 
 int ret = recvmsg(getFD(), , 0);
-if (ret >= 0)
+if (ret > 0 && msg.msg_controllen)
 {
-if (msg.msg_controllen)
+cmsghdr *cmsg = CMSG_FIRSTHDR();
+if (cmsg && cmsg->cmsg_type == SCM_RIGHTS && cmsg->cmsg_len == 
CMSG_LEN(sizeof(int)))
 {
-cmsghdr *cmsg = CMSG_FIRSTHDR();
-if (cmsg && cmsg->cmsg_type == SCM_RIGHTS && cmsg->cmsg_len == 
CMSG_LEN(sizeof(int)))
+fd = *(int*)CMSG_DATA(cmsg);
+if (_readType == UseRecvmsgExpectFD)
 {
-fd = *(int*)CMSG_DATA(cmsg);
-if (_readType == UseRecvmsgExpectFD)
-{
-_readType = NormalRead;
-}
+_readType = NormalRead;
 }
 }
 }
-else
-{
-LOG_ERR("recvmsg call ended with error: " << errno);
-}
 
 return ret;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2020-04-24 Thread Tor Lillqvist (via logerrit)
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit d83ced86c3ce8c1accde9f9e9bff7d9f3e8fe5a9
Author: Tor Lillqvist 
AuthorDate: Fri Apr 24 23:53:25 2020 +0300
Commit: Tor Lillqvist 
CommitDate: Fri Apr 24 23:47:25 2020 +0200

I think "us" is supposed to be the current thread id

The current thread's id is returned by std::this_thread::get_id().
std::thread::id() (the result of the std::thead::id constructor), on
the other hand, does not represent any thread.

Change-Id: I13f2831810282109d7bce984f1d040595c466712
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92881
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tor Lillqvist 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 2c94601ee..5966b1047 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -571,7 +571,7 @@ public:
 {
 if (InhibitThreadChecks)
 return;
-std::thread::id us = std::thread::id();
+std::thread::id us = std::this_thread::get_id();
 if (_owner == us)
 return; // all well
 LOG_DBG("Ununusual - SocketPoll used from a new thread");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp

2020-04-19 Thread Tor Lillqvist (via logerrit)
 net/Socket.hpp|4 ++--
 net/SslSocket.hpp |2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit e835bbf413dce4c1ea3c8a6f3257881fbbe91409
Author: Tor Lillqvist 
AuthorDate: Sun Apr 19 22:44:12 2020 +0300
Commit: Tor Lillqvist 
CommitDate: Sun Apr 19 22:05:29 2020 +0200

YAGNI: Bin bool parameter that is passed as true at the one single call site

Change-Id: I13b0ff612f8ca0970b3ab7fac3e92761c3c332d4
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92509
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tor Lillqvist 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 5155a7bc8..bc44f208b 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -1106,9 +1106,9 @@ protected:
 
 void dumpState(std::ostream& os) override;
 
-void setShutdownSignalled(bool shutdownSignalled)
+void setShutdownSignalled()
 {
-_shutdownSignalled = shutdownSignalled;
+_shutdownSignalled = true;
 }
 
 bool isShutdownSignalled() const
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index 4d5745485..508cecece 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -63,7 +63,7 @@ public:
 
 if (!isShutdownSignalled())
 {
-setShutdownSignalled(true);
+setShutdownSignalled();
 SslStreamSocket::closeConnection();
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2020-03-12 Thread Tor Lillqvist (via logerrit)
 net/Socket.hpp |   15 ---
 1 file changed, 15 deletions(-)

New commits:
commit 188d00ce4a4b635fc43f653d12e92bd250d7c8a7
Author: Tor Lillqvist 
AuthorDate: Thu Mar 12 20:58:03 2020 +0200
Commit: Tor Lillqvist 
CommitDate: Thu Mar 12 20:01:59 2020 +0100

Bin code that has always been inside #if 0

Also, the comment in it was misleading. We don't have just a single
buffer for a FakeSocket any longer.

Change-Id: I8f45fba2342ef42040e467b631739a56664ce6e8
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90440
Tested-by: Tor Lillqvist 
Reviewed-by: Tor Lillqvist 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index b15aeb21b..5427b99fa 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -697,21 +697,6 @@ public:
 #if !MOBILEAPP
 rc = ::write(fd, "w", 1);
 #else
-#if 0
-// Our fake sockets are record-oriented with a single record 
buffer, so as we write one
-// byte at a time to the wakeup pipe, we can't write another one 
before the previous one
-// has been read.
-//
-// FIXME: Still, explicitly waiting here with fakeSocketPoll() for 
it to be writable
-// doesn't seem to be any improvement. On the contrary, with this 
fakeSocketPoll(), we
-// hang every time we run the app. Without it, we only hang 
occasionally.
-
-LOG_TRC("Wakeup pipe write");
-struct pollfd p;
-p.fd = fd;
-p.events = POLLOUT;
-fakeSocketPoll(, 1, -1);
-#endif
 rc = fakeSocketWrite(fd, "w", 1);
 #endif
 } while (rc == -1 && errno == EINTR);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2020-02-04 Thread Gabriele Ponzo (via logerrit)
 net/Socket.hpp |   16 
 1 file changed, 16 deletions(-)

New commits:
commit 9586b4137885075b68eb2bdfb3c86e9913d93e22
Author: Gabriele Ponzo 
AuthorDate: Tue Feb 4 11:29:57 2020 +0100
Commit: Michael Meeks 
CommitDate: Tue Feb 4 12:09:51 2020 +0100

Remove unused method.

Change-Id: I18276c1ee074361ab70c3c27fc09bb5ba2429738
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/87963
Reviewed-by: Michael Meeks 
Tested-by: Jenkins CollaboraOffice 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 98479841b..c95b93dd7 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -696,22 +696,6 @@ public:
 
 virtual void dumpState(std::ostream& os);
 
-/// Removes a socket from this poller.
-/// NB. this must be called from the socket poll that
-/// owns the socket.
-void releaseSocket(const std::shared_ptr& socket)
-{
-assert(socket);
-assertCorrectThread();
-socket->assertCorrectThread();
-auto it = std::find(_pollSockets.begin(), _pollSockets.end(), socket);
-assert(it != _pollSockets.end());
-
-_pollSockets.erase(it);
-LOG_DBG("Removing socket #" << socket->getFD() << " (of " <<
-_pollSockets.size() << ") from " << _name);
-}
-
 size_t getSocketCount() const
 {
 assertCorrectThread();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp

2019-12-10 Thread Michael Meeks (via logerrit)
 net/Socket.hpp|3 ++-
 net/SslSocket.hpp |   21 -
 2 files changed, 18 insertions(+), 6 deletions(-)

New commits:
commit 1ff820de95b639895e5603a75553d61c79bedc3f
Author: Michael Meeks 
AuthorDate: Tue Dec 10 11:11:20 2019 +
Commit: Michael Meeks 
CommitDate: Tue Dec 10 11:45:13 2019 +

tdf#129306 SslSocket: handle EAGAIN properly.

Change-Id: I9fb3323b8d071fdc50399a67eb6b0aaeed9342b0

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 730f7194b..98479841b 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -831,7 +831,8 @@ public:
 
 ~StreamSocket()
 {
-LOG_DBG("StreamSocket dtor #" << getFD());
+LOG_DBG("StreamSocket dtor #" << getFD() << " with pending "
+"write: " << _outBuffer.size() << ", read: " << 
_inBuffer.size());
 
 if (!_closed)
 {
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index de16fdf1d..ba9954f56 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -22,28 +22,30 @@ public:
 SslStreamSocket(const int fd, bool isClient,
 std::shared_ptr responseClient) :
 StreamSocket(fd, isClient, std::move(responseClient)),
+_bio(nullptr),
 _ssl(nullptr),
 _sslWantsTo(SslWantsTo::Neither),
 _doHandshake(true)
 {
 LOG_DBG("SslStreamSocket ctor #" << fd);
 
-BIO* bio = BIO_new(BIO_s_socket());
-if (bio == nullptr)
+_bio = BIO_new(BIO_s_socket());
+if (_bio == nullptr)
 {
 throw std::runtime_error("Failed to create SSL BIO.");
 }
 
-BIO_set_fd(bio, fd, BIO_NOCLOSE);
+BIO_set_fd(_bio, fd, BIO_NOCLOSE);
 
 _ssl = SslContext::newSsl();
 if (!_ssl)
 {
-BIO_free(bio);
+BIO_free(_bio);
+_bio = nullptr;
 throw std::runtime_error("Failed to create SSL.");
 }
 
-SSL_set_bio(_ssl, bio, bio);
+SSL_set_bio(_ssl, _bio, _bio);
 
 if (isClient)
 {
@@ -240,6 +242,14 @@ private:
 // Fallthrough...
 default:
 {
+// Effectively an EAGAIN error at the BIO layer
+if (BIO_should_retry(_bio))
+{
+LOG_TRC("Socket #" << getFD() << " BIO asks for retry - 
underlying EAGAIN? " <<
+SSL_get_error(_ssl, rc));
+return -1; // poll is used to detect real errors.
+}
+
 if (sslError == SSL_ERROR_SSL)
 LOG_TRC("Socket #" << getFD() << " SSL error: SSL (" << 
sslError << ").");
 else if (sslError == SSL_ERROR_SYSCALL)
@@ -289,6 +299,7 @@ private:
 }
 
 private:
+BIO* _bio;
 SSL* _ssl;
 /// During handshake SSL might want to read
 /// on write, or write on read.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2019-06-12 Thread Miklos Vajna (via logerrit)
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 58d9b0ebbf9bc904ecde87efe353a7853a7b63dc
Author: Miklos Vajna 
AuthorDate: Wed Jun 12 08:58:22 2019 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jun 12 08:58:22 2019 +0200

net: avoid unnecessary copy in checkAndReThread()

Change-Id: I7a31ded80de128c46f59db3f0cba497de2f9f96c

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 5ebdc5560..9992b2607 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -483,7 +483,7 @@ public:
 return; // all well
 LOG_DBG("Ununusual - SocketPoll used from a new thread");
 _owner = us;
-for (auto it : _pollSockets)
+for (const auto& it : _pollSockets)
 it->setThreadOwner(us);
 // _newSockets are adapted as they are inserted.
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: net/Socket.hpp

2019-06-10 Thread Michael Meeks (via logerrit)
 net/Socket.hpp |   20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

New commits:
commit 579c827363ce35cb7912de34a77d89b8d83b0065
Author: Michael Meeks 
AuthorDate: Mon Jun 10 11:17:02 2019 +0100
Commit: Michael Meeks 
CommitDate: Mon Jun 10 12:24:17 2019 +0200

unipoll: allow LOK's Yield callback to be called from any thread.

Change-Id: I1ab46135919a1f06f814cc8702991592c84d28a7
Reviewed-on: https://gerrit.libreoffice.org/73752
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 2d96d1981..5ebdc5560 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -473,12 +473,30 @@ public:
 assert(_stop || sameThread);
 }
 
+/// Kit poll can be called from LOK's Yield in any thread, adapt to that.
+void checkAndReThread()
+{
+if (InhibitThreadChecks)
+return;
+std::thread::id us = std::thread::id();
+if (_owner == us)
+return; // all well
+LOG_DBG("Ununusual - SocketPoll used from a new thread");
+_owner = us;
+for (auto it : _pollSockets)
+it->setThreadOwner(us);
+// _newSockets are adapted as they are inserted.
+}
+
 /// Poll the sockets for available data to read or buffer to write.
 /// Returns the return-value of poll(2): 0 on timeout,
 /// -1 for error, and otherwise the number of events signalled.
 int poll(int timeoutMaxMs)
 {
-assertCorrectThread();
+if (_runOnClientThread)
+checkAndReThread();
+else
+assertCorrectThread();
 
 std::chrono::steady_clock::time_point now =
 std::chrono::steady_clock::now();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2019-05-20 Thread Libreoffice Gerrit user
 net/Socket.hpp |4 
 wsd/DocumentBroker.cpp |   13 +
 wsd/DocumentBroker.hpp |7 ---
 3 files changed, 13 insertions(+), 11 deletions(-)

New commits:
commit b5154eaf691e3a32f100bbf435e98ac5c9c56035
Author: Tor Lillqvist 
AuthorDate: Tue May 21 01:28:12 2019 +0300
Commit: Tor Lillqvist 
CommitDate: Tue May 21 02:40:28 2019 +0300

Make the document-specific threads in the iOS app go away more reliably

After a document is closed, the prisoner_poll, accept_poll,
websrv_poll, docbroker_nnn, and lokit_main threads that served that
document are supposed to go away as quickly and reliably as possible.
This change improves that significantly.

Change-Id: If658bea74f70a77d2d537f0ec6455a6b36f2667e

diff --git a/net/Socket.hpp b/net/Socket.hpp
index c7712339e..0764df159 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -1118,10 +1118,6 @@ protected:
 #if !MOBILEAPP
 return ::write(getFD(), buf, len);
 #else
-struct pollfd p;
-p.fd = getFD();
-p.events = POLLOUT;
-fakeSocketPoll(, 1, -1);
 return fakeSocketWrite(getFD(), buf, len);
 #endif
 }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index be53dcfd7..a2fb6f2ab 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -146,6 +146,19 @@ public:
 {
 }
 
+bool continuePolling() override
+{
+#if MOBILEAPP
+if (MobileTerminationFlag)
+{
+LOG_TRC("Noticed MobileTerminationFlag.");
+MobileTerminationFlag = false;
+return false;
+}
+#endif
+return TerminatingPoll::continuePolling();
+}
+
 virtual void pollingThread()
 {
 // Delegate to the docBroker.
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 2846af92a..0642599c2 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -48,13 +48,6 @@ public:
 
 bool continuePolling() override
 {
-#if MOBILEAPP
-if (MobileTerminationFlag)
-{
-MobileTerminationFlag = false;
-return false;
-}
-#endif
 return SocketPoll::continuePolling() && !TerminationFlag;
 }
 };
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: net/Socket.hpp scripts/perftrace.pl

2019-04-04 Thread Libreoffice Gerrit user
 net/Socket.hpp   |1 
 scripts/perftrace.pl |  133 +++
 2 files changed, 83 insertions(+), 51 deletions(-)

New commits:
commit cacaefc2871b26372ff9aaf3135970dcf2dc2053
Author: Michael Meeks 
AuthorDate: Thu Apr 4 18:55:07 2019 +0100
Commit: Michael Meeks 
CommitDate: Thu Apr 4 19:18:45 2019 +0100

perftrace: Annotate idleness and render it better as gaps.

Change-Id: If4d7853d02ca736f8cab12bd9dcc7c4b60ec7d27

diff --git a/net/Socket.hpp b/net/Socket.hpp
index c2355b7b7..c1c17b2be 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -488,6 +488,7 @@ public:
 int rc;
 do
 {
+LOG_TRC("Poll start");
 #if !MOBILEAPP
 rc = ::poll(&_pollFds[0], size + 1, std::max(timeoutMaxMs,0));
 #else
diff --git a/scripts/perftrace.pl b/scripts/perftrace.pl
index 32c0f0a71..a5b1a01d4 100755
--- a/scripts/perftrace.pl
+++ b/scripts/perftrace.pl
@@ -70,21 +70,42 @@ sub offset_microsecs($)
 return $usec;
 }
 
-# Delimit spans of time:
-my @pairs = (
+# Important things that happen in pairs
+my @event_pairs = (
+ { type => 'INF',
+   emitter => '^loolwsd$',
+   start => 'Initializing wsd.\.*',
+   end => 'Listening to prisoner connections.*' },
+ { type => 'INF',
+   emitter => '^forkit$',
+   start => 'Initializing frk.\.*',
+   end => 'ForKit process is ready.*' },
 { type => 'INF',
-  emitter => 'loolwsd',
-  start => 'Initializing wsd.\.*',
-  end => 'Listening to prisoner connections.*' },
-{ type => 'INF',
-  emitter => 'forkit',
-  start => 'Initializing frk.\.*',
-  end => 'ForKit process is ready.*'
-}
-);
+  emitter => "^lokit_.*",
+  start => 'Loading url .*',
+  end => '^Document loaded in .*ms$' },
+# FIXME: add save too ...
+);
+
+# Idle events
+my @idle_types = (
+'^Poll completed'
+);
+
 my %pair_starts;
 my %proc_names;
 
+sub get_event_type($$$)
+{
+my ($type, $emitter, $message) = @_;
+foreach my $match (@idle_types) {
+   if ($message =~ m/$match/) {
+   return 'idle';
+   }
+}
+return '';
+}
+
 sub consume()
 {
 my ($proc, $pid, $tid, $time, $emitter, $type, $message, $line) = @_;
@@ -108,57 +129,66 @@ sub consume()
 }
 
 my $handled = 0;
-foreach my $match (@pairs) {
-   next if ($type ne $match->{type});
-   next if (!($emitter =~ m/$match->{emitter}/));
-
-   my $start = $match->{start};
-   my $end = $match->{end};
-   my $key = $type.$emitter.$start;
-   if ($message =~ m/$start/) {
-   defined $pair_starts{$key} && die "event $start ($end) starts and 
fails to finish";
-   $pair_starts{$key} = $time;
-   last;
-   } elsif ($message =~ m/$end/) {
-   defined $pair_starts{$key} || die "event $start ($end) ends but 
failed to start";
-
-   my $content_e = escape($start);
-   my $title_e = escape($line);
-   my $start_time = $pair_starts{$key};
-   my $end_time = $time;
-
-   if ($json)
-   {
-   my $dur = $end_time - $start_time;
-   my $ms = int ($dur / 1000.0);
-   push @events, "{\"pid\":$pid, \"tid\":$tid, \"ts\":$start_time, 
\"dur\":$dur, \"ph\":\"X\", \"name\":\"$title_e\", \"args\":{ \"ms\":$ms } }";
-   }
-   else
-   {
-   my $id = (scalar @events) + 1;
-   push @events, "{id: $id, group: $emitters{$emitter}, ".
-   "start: new Date('$log_start_date $start_time'), ".
-   "end: new Date('$log_start_date $end_time'), ".
-   "content: '$content_e', title: '$title_e'}";
-   }
-   last;
-   }
+foreach my $match (@event_pairs) {
+   next if ($type ne $match->{type});
+   next if (defined $match->{emitter} && !($emitter =~ 
m/$match->{emitter}/));
+
+   my $start = $match->{start};
+   my $end = $match->{end};
+   my $key = $type.$emitter.$start;
+   if ($message =~ m/$start/) {
+   defined $pair_starts{$key} && die "event $start ($end) starts and 
fails to finish";
+   $pair_starts{$key} = $time;
+   last;
+   } elsif ($message =~ m/$end/) {
+   defined $pair_starts{$key} || die "event $start ($end) ends but 
failed to start";
+
+   my $content_e = escape($start);
+   my $title_e = escape($line);
+   my $start_time = $pair_starts{$key};
+   my $end_time = $time;
+
+   if ($json)
+   {
+   my $dur = $end_time - $start_time;
+   my $ms = int ($dur / 1000.0);
+   push @events, "{\"pid\":$pid, \"tid\":$tid, \"ts\":$start_time, 
\"dur\":$dur, \"ph\":\"X\", \"name\":\"$title_e\", \"args\":{ \"ms\":$ms } }";
+   }
+   else
+   {
+   my $id = (scalar @events) + 1;
+   push 

[Libreoffice-commits] online.git: net/Socket.hpp

2019-03-30 Thread Libreoffice Gerrit user
 net/Socket.hpp |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit d832fb3c9d1a89287daaf5cd082a594061a3283b
Author: Michael Meeks 
AuthorDate: Sat Mar 30 11:30:39 2019 +
Commit: Michael Meeks 
CommitDate: Sat Mar 30 17:50:59 2019 +0100

Crop socket buffer removal to socket buffer size & warn.

Change-Id: I734b4682941d71eee02a25aab61c8e4353a11718
Reviewed-on: https://gerrit.libreoffice.org/69948
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index e27dc6df0..1a074ce2d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -932,7 +932,11 @@ public:
 /// Remove the first @count bytes from input buffer
 void eraseFirstInputBytes(size_t count)
 {
-_inBuffer.erase(_inBuffer.begin(), _inBuffer.begin() + count);
+size_t toErase = std::min(count, _inBuffer.size());
+if (toErase < count)
+LOG_ERR("#" << getFD() << ": attempted to remove: " << count << " 
which is > size: " << _inBuffer.size() << " clamped to " << toErase);
+if (toErase > 0)
+_inBuffer.erase(_inBuffer.begin(), _inBuffer.begin() + count);
 }
 
 /// Detects if we have an HTTP header in the provided message and
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp

2018-10-26 Thread Libreoffice Gerrit user
 net/Socket.hpp|   17 -
 net/SslSocket.hpp |8 
 2 files changed, 20 insertions(+), 5 deletions(-)

New commits:
commit 5167cf9f58196c6d8289ea025894f122c439531e
Author: Miklos Vajna 
AuthorDate: Fri Oct 26 09:07:07 2018 +0200
Commit: Miklos Vajna 
CommitDate: Fri Oct 26 09:07:30 2018 +0200

StreamSocket: make members private

Only a single member needed a setter, otherwise getters were enough.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 698edd328..0c58d20aa 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -1091,7 +1091,22 @@ protected:
 
 void dumpState(std::ostream& os) override;
 
-protected:
+void setShutdownSignalled(bool shutdownSignalled)
+{
+_shutdownSignalled = shutdownSignalled;
+}
+
+bool isShutdownSignalled() const
+{
+return _shutdownSignalled;
+}
+
+const std::shared_ptr& getSocketHandler() const
+{
+return _socketHandler;
+}
+
+  private:
 /// Client handling the actual data.
 std::shared_ptr _socketHandler;
 
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index 44a2fa382..de16fdf1d 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -60,9 +60,9 @@ public:
 {
 LOG_DBG("SslStreamSocket dtor #" << getFD());
 
-if (!_shutdownSignalled)
+if (!isShutdownSignalled())
 {
-_shutdownSignalled = true;
+setShutdownSignalled(true);
 SslStreamSocket::closeConnection();
 }
 
@@ -128,7 +128,7 @@ public:
   int & timeoutMaxMs) override
 {
 assertCorrectThread();
-int events = _socketHandler->getPollEvents(now, timeoutMaxMs);
+int events = getSocketHandler()->getPollEvents(now, timeoutMaxMs);
 
 if (_sslWantsTo == SslWantsTo::Read)
 {
@@ -141,7 +141,7 @@ public:
 return POLLOUT;
 }
 
-if (!_outBuffer.empty() || _shutdownSignalled)
+if (!getOutBuffer().empty() || isShutdownSignalled())
 events |= POLLOUT;
 
 return events;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp tools/WebSocketDump.cpp wsd/LOOLWSD.cpp

2018-10-25 Thread Libreoffice Gerrit user
 net/Socket.hpp   |   20 
 net/WebSocketHandler.hpp |   24 
 tools/WebSocketDump.cpp  |2 +-
 wsd/LOOLWSD.cpp  |   12 ++--
 4 files changed, 31 insertions(+), 27 deletions(-)

New commits:
commit 4724aa0cf78f3aedf7f7f4222d251ef8395d5523
Author: Miklos Vajna 
AuthorDate: Thu Oct 25 16:38:54 2018 +0200
Commit: Miklos Vajna 
CommitDate: Thu Oct 25 16:39:02 2018 +0200

Socket: do what the TODO says

Drop the list of friends and just add getters for the relevant
members.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 2d8a2f26a..698edd328 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -938,6 +938,16 @@ public:
 return _clientAddress;
 }
 
+std::vector& getInBuffer()
+{
+return _inBuffer;
+}
+
+std::vector& getOutBuffer()
+{
+return _outBuffer;
+}
+
 protected:
 
 /// Called when a polling event is received.
@@ -1012,6 +1022,7 @@ protected:
 disposition.setClosed();
 }
 
+public:
 /// Override to write data out to socket.
 virtual void writeOutgoingData()
 {
@@ -1051,6 +1062,7 @@ protected:
 while (!_outBuffer.empty());
 }
 
+protected:
 /// Override to handle reading of socket data differently.
 virtual int readData(char* buf, int len)
 {
@@ -1096,14 +1108,6 @@ protected:
 
 /// True when shutdown was requested via shutdown().
 bool _shutdownSignalled;
-
-// To be able to access _inBuffer and _outBuffer.
-// TODO we probably need accessors to the _inBuffer & _outBuffer
-// instead of this many friends...
-friend class WebSocketHandler;
-friend class ClientRequestDispatcher;
-friend class PrisonerRequestDispatcher;
-friend class SimpleResponseClient;
 };
 
 enum class WSOpCode : unsigned char {
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index fcb9d3660..3b60fe9b8 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -131,7 +131,7 @@ public:
 assert(socket && "Expected a valid socket instance.");
 
 // websocket fun !
-const size_t len = socket->_inBuffer.size();
+const size_t len = socket->getInBuffer().size();
 
 if (len == 0)
 return false; // avoid logging.
@@ -143,7 +143,7 @@ public:
 return false;
 }
 
-unsigned char *p = reinterpret_cast(>_inBuffer[0]);
+unsigned char *p = reinterpret_cast(>getInBuffer()[0]);
 const bool fin = p[0] & 0x80;
 const WSOpCode code = static_cast(p[0] & 0x0f);
 const bool hasMask = p[1] & 0x80;
@@ -191,7 +191,7 @@ public:
 return false;
 }
 
-LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket data of " << 
len << " bytes: " << Util::stringifyHexLine(socket->_inBuffer, 0, 
std::min((size_t)32, len)));
+LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket data of " << 
len << " bytes: " << Util::stringifyHexLine(socket->getInBuffer(), 0, 
std::min((size_t)32, len)));
 
 data = p + headerLen;
 
@@ -214,14 +214,14 @@ public:
 
 assert(_wsPayload.size() >= payloadLen);
 
-socket->_inBuffer.erase(socket->_inBuffer.begin(), 
socket->_inBuffer.begin() + headerLen + payloadLen);
+socket->getInBuffer().erase(socket->getInBuffer().begin(), 
socket->getInBuffer().begin() + headerLen + payloadLen);
 
 #ifndef MOBILEAPP
 
 // FIXME: fin, aggregating payloads into _wsPayload etc.
 LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " 
<< static_cast(code) <<
 ", fin? " << fin << ", mask? " << hasMask << ", payload 
length: " << _wsPayload.size() <<
-", residual socket data: " << socket->_inBuffer.size() << " 
bytes.");
+", residual socket data: " << socket->getInBuffer().size() << 
" bytes.");
 
 bool doClose = false;
 
@@ -444,7 +444,7 @@ private:
 return 0;
 
 socket->assertCorrectThread();
-std::vector& out = socket->_outBuffer;
+std::vector& out = socket->getOutBuffer();
 const size_t oldSize = out.size();
 
 #ifndef MOBILEAPP
@@ -586,26 +586,26 @@ protected:
 {
 std::shared_ptr socket = _socket.lock();
 
-LOG_TRC("Incoming client websocket upgrade response: " << 
std::string(>_inBuffer[0], socket->_inBuffer.size()));
+LOG_TRC("Incoming client websocket upgrade response: " << 
std::string(>getInBuffer()[0], socket->getInBuffer().size()));
 
 bool bOk = false;
 size_t responseSize = 0;
 
 try
 {
-Poco::MemoryInputStream message(>_inBuffer[0], 
socket->_inBuffer.size());;
+Poco::MemoryInputStream message(>getInBuffer()[0], 
socket->getInBuffer().size());;
 Poco::Net::HTTPResponse response;
 
 response.read(message);
 
 {
 static const std::string 

[Libreoffice-commits] online.git: net/Socket.hpp

2018-10-19 Thread Libreoffice Gerrit user
 net/Socket.hpp |   13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

New commits:
commit d6d0c3e8a32671f57bbff852ac45796cd4613d35
Author: Tor Lillqvist 
AuthorDate: Fri Oct 19 12:40:09 2018 +0300
Commit: Tor Lillqvist 
CommitDate: Fri Oct 19 13:41:18 2018 +0200

As far as I see, no getPollEvents() implementation will ever return negative

In 1c7f94045a433625f9ec55b137bbd0322f27d532 that introduced
DelaySocket, its getPollEvents() could indeed return -1, but that was
removed later.

Change-Id: Ie3a7e01b7b9a7517d97f6ed3cc6d96bdb3313969
Reviewed-on: https://gerrit.libreoffice.org/61990
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 734d3696a..2d8a2f26a 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -713,16 +713,9 @@ private:
 for (size_t i = 0; i < size; ++i)
 {
 int events = _pollSockets[i]->getPollEvents(now, timeoutMaxMs);
-if (events < 0) // timeout on dead socket
-{
-_pollFds[i].fd = _wakeup[0];
-_pollFds[i].events = 0;
-}
-else
-{
-_pollFds[i].fd = _pollSockets[i]->getFD();
-_pollFds[i].events = events;
-}
+assert(events >= 0); // Or > 0 even?
+_pollFds[i].fd = _pollSockets[i]->getFD();
+_pollFds[i].events = events;
 _pollFds[i].revents = 0;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2018-10-15 Thread Libreoffice Gerrit user
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 116510296e5af7180beb50314de23d468b89068a
Author: Miklos Vajna 
AuthorDate: Mon Oct 15 09:31:03 2018 +0200
Commit: Miklos Vajna 
CommitDate: Mon Oct 15 09:31:03 2018 +0200

net: unnecessary value parameter in Socket

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 2c716cb43..55f041415 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -633,7 +633,7 @@ public:
 typedef std::function CallbackFn;
 
 /// Add a callback to be invoked in the polling thread
-void addCallback(CallbackFn fn)
+void addCallback(const CallbackFn& fn)
 {
 std::lock_guard lock(_mutex);
 _newCallbacks.emplace_back(fn);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2018-09-20 Thread Libreoffice Gerrit user
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 06051c833bff0e2054fba975c97bafcdf9716726
Author: Tor Lillqvist 
AuthorDate: Thu Sep 20 13:38:48 2018 +0300
Commit: Tor Lillqvist 
CommitDate: Thu Sep 20 13:38:53 2018 +0300

Comment out log.dump() call again

Change-Id: I27ecd6712e72182f3a943e7be86ef5ba7b05f746

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 671f345ba..2c716cb43 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -940,7 +940,7 @@ protected:
 if (log.trace()) {
 LOG_TRC("#" << getFD() << ": Incoming data buffer " << 
_inBuffer.size() <<
 " bytes, closeSocket? " << closed);
-log.dump("", &_inBuffer[0], _inBuffer.size());
+// log.dump("", &_inBuffer[0], _inBuffer.size());
 }
 
 // If we have data, allow the app to consume.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2018-05-24 Thread Miklos Vajna
 net/Socket.hpp |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 65df3e6ceb8bf06f8ed2afd9f3667a1458ceeec8
Author: Miklos Vajna 
Date:   Thu May 24 08:50:22 2018 +0200

net: use std::move() in the StreamSocket ctor

It was inconsistent that the StreamSocket ctor had a const parameter,
but the SslStreamSocket had a non-const one and used std::move(). Use
the later in the parent class as well for consistency.

Change-Id: I58597b97432a801d164d6ed9d831a0372280e687

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 6cd2190d4..965f08247 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -706,9 +706,9 @@ class StreamSocket : public Socket, public 
std::enable_shared_from_this socketHandler) :
+ std::shared_ptr socketHandler) :
 Socket(fd),
-_socketHandler(socketHandler),
+_socketHandler(std::move(socketHandler)),
 _bytesSent(0),
 _bytesRecvd(0),
 _wsState(WSState::HTTP),
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp net/WebSocketHandler.hpp

2018-01-22 Thread Ashod Nakashian
 net/Socket.hpp   |2 ++
 net/SslSocket.hpp|4 ++--
 net/WebSocketHandler.hpp |3 +++
 3 files changed, 7 insertions(+), 2 deletions(-)

New commits:
commit 11cdfb7688dea76d2647758af767187903a0ec72
Author: Ashod Nakashian 
Date:   Sun Jan 21 20:34:38 2018 -0500

wsd: avoid misleading socket error logs

Change-Id: Ie70d8eb1ecc0442643f4b2a4757b95688b4cf1f7
Reviewed-on: https://gerrit.libreoffice.org/48284
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 01759953..da34b5e3 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -730,6 +730,8 @@ public:
 }
 }
 
+bool isClosed() const { return _closed; }
+
 /// Just trigger the async shutdown.
 virtual void shutdown() override
 {
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index 4b5d1323..2f8d45cb 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -251,8 +251,8 @@ private:
 {
 if (rc == 0)
 {
-// Socket closed.
-LOG_ERR("Socket #" << getFD() << " SSL BIO error: 
closed (0).");
+// Socket closed. Not an error.
+LOG_INF("Socket #" << getFD() << " SSL BIO error: 
closed (0).");
 return 0;
 }
 else if (rc == -1)
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 1b37389d..161272e9 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -337,6 +337,9 @@ protected:
 if (!socket || data == nullptr || len == 0)
 return -1;
 
+if (socket->isClosed())
+return 0;
+
 socket->assertCorrectThread();
 std::vector& out = socket->_outBuffer;
 const size_t oldSize = out.size();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/Admin.cpp wsd/AdminModel.cpp

2018-01-06 Thread Ashod Nakashian
 net/Socket.hpp |4 ++--
 wsd/Admin.cpp  |   19 +++
 wsd/AdminModel.cpp |4 +---
 3 files changed, 10 insertions(+), 17 deletions(-)

New commits:
commit 57d535b15b94c0b506c17ab68838168d422c5deb
Author: Ashod Nakashian 
Date:   Tue Jan 2 21:33:52 2018 -0500

wsd: lambda cleanup and better readability

Change-Id: Iabb850be7a7c162847514ee0fb600297accfcffb
Reviewed-on: https://gerrit.libreoffice.org/47364
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 0b6af504..736be218 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -428,11 +428,11 @@ public:
 std::swap(_newCallbacks, invoke);
 }
 
-for (size_t i = 0; i < invoke.size(); ++i)
+for (const auto& callback : invoke)
 {
 try
 {
-invoke[i]();
+callback();
 }
 catch (const std::exception& exc)
 {
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index c3c121e7..f6ade65f 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -430,27 +430,24 @@ void Admin::pollingThread()
 }
 
 void Admin::modificationAlert(const std::string& dockey, Poco::Process::PID 
pid, bool value){
-addCallback([this, dockey, pid, value]
-{ _model.modificationAlert(dockey, pid, value); });
+addCallback([&] { _model.modificationAlert(dockey, pid, value); });
 }
 
 void Admin::addDoc(const std::string& docKey, Poco::Process::PID pid, const 
std::string& filename,
 const std::string& sessionId, const std::string& userName, const 
std::string& userId)
 {
-addCallback([this, docKey, pid, filename, sessionId, userName, userId]
- { _model.addDocument(docKey, pid, filename, sessionId, 
userName, userId); });
+addCallback([&] { _model.addDocument(docKey, pid, filename, sessionId, 
userName, userId); });
 }
 
 void Admin::rmDoc(const std::string& docKey, const std::string& sessionId)
 {
-addCallback([this, docKey, sessionId]
- { _model.removeDocument(docKey, sessionId); });
+addCallback([&] { _model.removeDocument(docKey, sessionId); });
 }
 
 void Admin::rmDoc(const std::string& docKey)
 {
 LOG_INF("Removing complete doc [" << docKey << "] from Admin.");
-addCallback([this, docKey]{ _model.removeDocument(docKey); });
+addCallback([&]{ _model.removeDocument(docKey); });
 }
 
 void Admin::rescheduleMemTimer(unsigned interval)
@@ -521,19 +518,17 @@ AdminModel& Admin::getModel()
 
 void Admin::updateLastActivityTime(const std::string& docKey)
 {
-addCallback([this, docKey]{ _model.updateLastActivityTime(docKey); });
+addCallback([&]{ _model.updateLastActivityTime(docKey); });
 }
 
 void Admin::updateMemoryDirty(const std::string& docKey, int dirty)
 {
-addCallback([this, docKey, dirty]
- { _model.updateMemoryDirty(docKey, dirty); });
+addCallback([&] { _model.updateMemoryDirty(docKey, dirty); });
 }
 
 void Admin::addBytes(const std::string& docKey, uint64_t sent, uint64_t recv)
 {
-addCallback([this, docKey, sent, recv]
- { _model.addBytes(docKey, sent, recv); });
+addCallback([&] { _model.addBytes(docKey, sent, recv); });
 }
 
 void Admin::notifyForkit()
diff --git a/wsd/AdminModel.cpp b/wsd/AdminModel.cpp
index ea0a0589..d23c39ae 100644
--- a/wsd/AdminModel.cpp
+++ b/wsd/AdminModel.cpp
@@ -449,10 +449,8 @@ void AdminModel::modificationAlert(const std::string& 
docKey, Poco::Process::PID
 assertCorrectThread();
 
 auto doc = _documents.find(docKey);
-if(doc != _documents.end())
-{
+if (doc != _documents.end())
 doc->second.setModified(value);
-}
 
 std::ostringstream oss;
 oss << "modifications "
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-09-18 Thread Miklos Vajna
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit f375a9d5de400b0da00b7065eac8927ab8ed891e
Author: Miklos Vajna 
Date:   Mon Sep 18 10:15:49 2017 +0200

Socket: mark setNoDelay() as non-virtual

No derived classes override it, and if they would, that would be a
problem, as setNoDelay() is called from init(), which is called from the
Socket ctor. Calling virtual functions from the base class ctor is not a
good idea, since the object is not fully constructed yet.

Change-Id: I4993e26d09f5d3429c7e2afae7688b84c0061c9d

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 3442fdb1..62a743b5 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -135,7 +135,7 @@ public:
 int events) = 0;
 
 /// manage latency issues around packet aggregation
-virtual void setNoDelay()
+void setNoDelay()
 {
 const int val = 1;
 ::setsockopt(_fd, IPPROTO_TCP, TCP_NODELAY,
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/Auth.hpp wsd/LOOLWSD.cpp wsd/Storage.hpp

2017-09-12 Thread Miklos Vajna
 net/Socket.hpp  |1 +
 wsd/Auth.hpp|1 +
 wsd/LOOLWSD.cpp |6 +++---
 wsd/Storage.hpp |2 ++
 4 files changed, 7 insertions(+), 3 deletions(-)

New commits:
commit bcb5b744b8cc56ca7d8e82b2db23146823546902
Author: Miklos Vajna 
Date:   Tue Sep 12 10:03:26 2017 +0200

net, wsd: fix -Werror,-Wdelete-non-virtual-dtor warnings

Two problem types:

- non-final class has virtual functions but no virtual dtor -> mark the
  class final
- abstract class has no virtual dtor -> add a virtual dtor

Change-Id: Iae208b65c774e6da7a3dda5e725fe07d4d589e4f

diff --git a/net/Socket.hpp b/net/Socket.hpp
index f3cf623c..3442fdb1 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -659,6 +659,7 @@ class StreamSocket;
 class SocketHandlerInterface
 {
 public:
+virtual ~SocketHandlerInterface() {}
 /// Called when the socket is newly created to
 /// set the socket associated with this ResponseClient.
 /// Will be called exactly once.
diff --git a/wsd/Auth.hpp b/wsd/Auth.hpp
index 98c0a2ce..96bcb86b 100644
--- a/wsd/Auth.hpp
+++ b/wsd/Auth.hpp
@@ -57,6 +57,7 @@ public:
 class AuthBase
 {
 public:
+virtual ~AuthBase() {}
 /// Called to acquire an access token.
 virtual const std::string getAccessToken() = 0;
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index dc389dcf..c2a452c7 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2280,7 +2280,7 @@ private:
 
 std::map 
ClientRequestDispatcher::StaticFileContentCache;
 
-class PlainSocketFactory : public SocketFactory
+class PlainSocketFactory final : public SocketFactory
 {
 std::shared_ptr create(const int physicalFd) override
 {
@@ -2299,7 +2299,7 @@ class PlainSocketFactory : public SocketFactory
 };
 
 #if ENABLE_SSL
-class SslSocketFactory : public SocketFactory
+class SslSocketFactory final : public SocketFactory
 {
 std::shared_ptr create(const int physicalFd) override
 {
@@ -2313,7 +2313,7 @@ class SslSocketFactory : public SocketFactory
 };
 #endif
 
-class PrisonerSocketFactory : public SocketFactory
+class PrisonerSocketFactory final : public SocketFactory
 {
 std::shared_ptr create(const int fd) override
 {
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 2c619581..389c228d 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -83,6 +83,8 @@ public:
 LOG_DBG("Storage ctor: " << uri.toString());
 }
 
+virtual ~StorageBase() {}
+
 const std::string getUri() const { return _uri.toString(); }
 
 /// Returns the root path to the jailed file.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/Ssl.cpp wsd/FileServer.hpp wsd/LOOLWSD.cpp

2017-07-02 Thread Ashod Nakashian
 net/Socket.hpp |4 
 net/Ssl.cpp|1 +
 wsd/FileServer.hpp |3 +++
 wsd/LOOLWSD.cpp|2 ++
 4 files changed, 10 insertions(+)

New commits:
commit 4f8ebca0cb3612ddbdcfbee6ea5a462b04689738
Author: Ashod Nakashian 
Date:   Sun Jul 2 22:10:23 2017 -0400

wsd: free leaking memory

With help from Valgrind to find and verify
these leaks.

Change-Id: I3afeed89dc4bcd714a222f81822144477a346fb0
Reviewed-on: https://gerrit.libreoffice.org/39464
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index d1d3018d..f3cf623c 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -615,6 +615,10 @@ private:
 
 // Invoke the virtual implementation.
 pollingThread();
+
+// Release sockets.
+_pollSockets.clear();
+_newSockets.clear();
 }
 catch (const std::exception& exc)
 {
diff --git a/net/Ssl.cpp b/net/Ssl.cpp
index e350257c..7c04cbd9 100644
--- a/net/Ssl.cpp
+++ b/net/Ssl.cpp
@@ -123,6 +123,7 @@ SslContext::SslContext(const std::string& certFilePath,
 
 SslContext::~SslContext()
 {
+SSL_CTX_free(_ctx);
 EVP_cleanup();
 ERR_free_strings();
 CRYPTO_set_locking_callback(0);
diff --git a/wsd/FileServer.hpp b/wsd/FileServer.hpp
index 01d5918c..c3ff59b7 100644
--- a/wsd/FileServer.hpp
+++ b/wsd/FileServer.hpp
@@ -31,6 +31,9 @@ public:
 /// Read all files that we can serve into memory and compress them.
 static void initialize();
 
+/// Clean cached files.
+static void uninitialize() { FileHash.clear(); }
+
 static void readDirToHash(const std::string , const std::string 
);
 
 static const std::string *getCompressedFile(const std::string );
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index eecc6d27..a1272c20 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2672,6 +2672,8 @@ int LOOLWSD::innerMain()
 
 void LOOLWSD::cleanup()
 {
+FileServerRequestHandler::uninitialize();
+
 // Finally, we no longer need SSL.
 if (LOOLWSD::isSSLEnabled())
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-06-21 Thread Miklos Vajna
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit ffbe55adb530813acd640faaa55f85f00c570080
Author: Miklos Vajna 
Date:   Wed Jun 21 09:05:42 2017 +0200

SocketDisposition::setMove(): parameter is passed by value, move it

Change-Id: I2c7facfc4fc5422cef886c6ba28ac60c656a908e

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 4c410d23..d1d3018d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -74,7 +74,7 @@ public:
 }
 void setMove(MoveFunction moveFn)
 {
-_socketMove = moveFn;
+_socketMove = std::move(moveFn);
 _disposition = Type::MOVE;
 }
 void setClosed()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp wsd/ClientSession.cpp wsd/DocumentBroker.cpp

2017-05-21 Thread Ashod Nakashian
 net/Socket.hpp   |   15 ---
 net/WebSocketHandler.hpp |8 ++--
 wsd/ClientSession.cpp|   13 +++--
 wsd/DocumentBroker.cpp   |   12 +++-
 4 files changed, 28 insertions(+), 20 deletions(-)

New commits:
commit bdd8b715ddfac90ea814ea87f58a2985a2bc66c0
Author: Ashod Nakashian 
Date:   Sat May 20 13:28:43 2017 -0400

wsd: include cleanup

Change-Id: I9f28ee329e318043c31c899d3a07cd3139d838f0
Reviewed-on: https://gerrit.libreoffice.org/37890
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 7c7b55ab..88e24f05 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -21,20 +21,21 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 
-#include "Common.hpp"
-#include "Log.hpp"
-#include "Util.hpp"
-#include "SigUtil.hpp"
+#include "common/Common.hpp"
+#include "common/Log.hpp"
+#include "common/Util.hpp"
+#include "common/SigUtil.hpp"
 
 namespace Poco
 {
@@ -136,8 +137,8 @@ public:
 virtual void setNoDelay()
 {
 const int val = 1;
-setsockopt (_fd, IPPROTO_TCP, TCP_NODELAY,
-(char *) , sizeof(val));
+::setsockopt(_fd, IPPROTO_TCP, TCP_NODELAY,
+ (char *) , sizeof(val));
 }
 
 /// Sets the kernel socket send buffer in size bytes.
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 4ff01c36..7c52cf58 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -10,8 +10,12 @@
 #ifndef INCLUDED_WEBSOCKETHANDLER_HPP
 #define INCLUDED_WEBSOCKETHANDLER_HPP
 
-#include "Common.hpp"
-#include "Log.hpp"
+#include 
+#include 
+#include 
+
+#include "common/Common.hpp"
+#include "common/Log.hpp"
 #include "Socket.hpp"
 
 #include 
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index d21d925d..387f7629 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -14,16 +14,17 @@
 #include 
 
 #include 
+#include 
 #include 
 
-#include "Common.hpp"
+#include "common/Common.hpp"
 #include "DocumentBroker.hpp"
 #include "LOOLWSD.hpp"
-#include "Log.hpp"
-#include "Protocol.hpp"
-#include "Session.hpp"
-#include "Util.hpp"
-#include "Unit.hpp"
+#include "common/Log.hpp"
+#include "common/Protocol.hpp"
+#include "common/Session.hpp"
+#include "common/Util.hpp"
+#include "common/Unit.hpp"
 
 using namespace LOOLProtocol;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 5b5f4ebd..956a2fe6 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -11,6 +11,7 @@
 
 #include "DocumentBroker.hpp"
 
+#include 
 #include 
 #include 
 #include 
@@ -27,14 +28,14 @@
 #include "Admin.hpp"
 #include "ClientSession.hpp"
 #include "Exceptions.hpp"
-#include "Message.hpp"
-#include "Protocol.hpp"
 #include "LOOLWSD.hpp"
-#include "Log.hpp"
+#include "SenderQueue.hpp"
 #include "Storage.hpp"
 #include "TileCache.hpp"
-#include "SenderQueue.hpp"
-#include "Unit.hpp"
+#include "common/Log.hpp"
+#include "common/Message.hpp"
+#include "common/Protocol.hpp"
+#include "common/Unit.hpp"
 
 using namespace LOOLProtocol;
 
@@ -409,6 +410,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 LOG_ERR("Failed to create Storage instance for [" << _docKey << "] 
in " << jailPath.toString());
 return false;
 }
+
 firstInstance = true;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp

2017-04-19 Thread Jan Holesovsky
 net/Socket.hpp   |4 ++--
 net/WebSocketHandler.hpp |1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

New commits:
commit 47ca32beb5659a58655a1cef6cc61b6aaccd355a
Author: Jan Holesovsky 
Date:   Wed Apr 19 11:07:55 2017 +0200

We never call setNoDelay() with false.

Change-Id: I865027300559b185222f21faa48ccd32100bd02d

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 70b229b3..8c07e38d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -84,9 +84,9 @@ public:
 virtual HandleResult handlePoll(std::chrono::steady_clock::time_point now, 
int events) = 0;
 
 /// manage latency issues around packet aggregation
-void setNoDelay(bool noDelay = true)
+void setNoDelay()
 {
-int val = noDelay ? 1 : 0;
+const int val = 1;
 setsockopt (_fd, IPPROTO_TCP, TCP_NODELAY,
 (char *) , sizeof(val));
 }
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index a863afad..14d97f81 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -417,7 +417,6 @@ protected:
 LOG_INF("#" << socket->getFD() << ": WebSocket version: " << wsVersion 
<<
 ", key: [" << wsKey << "], protocol: [" << wsProtocol << "].");
 
-socket->setNoDelay();
 #if ENABLE_DEBUG
 if (std::getenv("LOOL_ZERO_BUFFER_SIZE"))
 socket->setSocketBufferSize(0);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-04-18 Thread Ashod Nakashian
 net/Socket.hpp |3 +
 wsd/DocumentBroker.cpp |   75 +
 wsd/DocumentBroker.hpp |3 -
 wsd/LOOLWSD.cpp|   25 +++-
 4 files changed, 78 insertions(+), 28 deletions(-)

New commits:
commit 9b3a22aafee8d0163212ea0c1b499eb03cb632ba
Author: Ashod Nakashian 
Date:   Wed Apr 19 00:54:42 2017 -0400

wsd: save document upon server shutdown

The server correctly saves all documents
and waits to upload them before exiting.

Change-Id: I04dc9ce588bc0fa39a9deb298d0a5efa61a03f1a
Reviewed-on: https://gerrit.libreoffice.org/36654
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 89844912..c0b4b97e 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -438,7 +438,8 @@ public:
 void wakeup()
 {
 if (!isAlive())
-LOG_WRN("Waking up dead poll thread [" << _name << "]");
+LOG_WRN("Waking up dead poll thread [" << _name << "], started: " 
<<
+_threadStarted << ", finished: " << _threadFinished);
 
 wakeup(_wakeup[1]);
 }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8ad9571e..94a49a1d 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -12,6 +12,7 @@
 #include "DocumentBroker.hpp"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -220,29 +221,66 @@ void DocumentBroker::pollThread()
 
 auto last30SecCheckTime = std::chrono::steady_clock::now();
 
+static const bool AutoSaveEnabled = !std::getenv("LOOL_NO_AUTOSAVE");
+
 // Main polling loop goodness.
-while (!_stop && _poll->continuePolling() && !TerminationFlag && 
!ShutdownRequestFlag)
+while (!_stop && _poll->continuePolling() && !TerminationFlag)
 {
 _poll->poll(SocketPoll::DefaultPollTimeoutMs);
 
-if (!std::getenv("LOOL_NO_AUTOSAVE") && !_stop &&
-std::chrono::duration_cast
-(std::chrono::steady_clock::now() - last30SecCheckTime).count() >= 
30)
+const auto now = std::chrono::steady_clock::now();
+if (_lastSaveTime < _lastSaveRequestTime &&
+std::chrono::duration_cast
+(now - _lastSaveRequestTime).count() <= COMMAND_TIMEOUT_MS)
+{
+// We are saving, nothing more to do but wait.
+continue;
+}
+
+if (ShutdownRequestFlag)
 {
-LOG_TRC("Trigger an autosave ...");
+// Shutting down the server: notify clients, save, and stop.
+static const std::string msg("close: recycling");
+
+// First copy into local container, since removeSession
+// will erase from _sessions, but will leave the last.
+std::vector sessions;
+for (const auto& pair : _sessions)
+{
+sessions.push_back(pair.second);
+}
+
+for (const std::shared_ptr& session : sessions)
+{
+try
+{
+// Notify the client and disconnect.
+session->sendMessage(msg);
+
session->shutdown(WebSocketHandler::StatusCodes::ENDPOINT_GOING_AWAY, 
"recycling");
+
+// Remove session, save, and mark to destroy.
+removeSession(session->getId(), true);
+}
+catch (const std::exception& exc)
+{
+LOG_WRN("Error while shutting down client [" <<
+session->getName() << "]: " << exc.what());
+}
+}
+}
+else if (AutoSaveEnabled && !_stop &&
+ std::chrono::duration_cast(now - 
last30SecCheckTime).count() >= 30)
+{
+LOG_TRC("Triggering an autosave.");
 autoSave(false);
 last30SecCheckTime = std::chrono::steady_clock::now();
 }
 
-const bool notSaving = 
(std::chrono::duration_cast
-(std::chrono::steady_clock::now() - 
_lastSaveRequestTime).count() > COMMAND_TIMEOUT_MS);
-
 // Remove idle documents after 1 hour.
 const bool idle = (getIdleTimeSecs() >= 3600);
 
 // If all sessions have been removed, no reason to linger.
-if ((isLoaded() || _markToDestroy) && notSaving &&
-(_sessions.empty() || idle))
+if ((isLoaded() || _markToDestroy) && (_sessions.empty() || idle))
 {
 LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
 " DocumentBroker for docKey [" << getDocKey() << "].");
@@ -251,17 +289,8 @@ void DocumentBroker::pollThread()
 }
 
 LOG_INF("Finished polling doc [" << _docKey << "]. stop: " << _stop << ", 
continuePolling: " <<
-_poll->continuePolling() << ", TerminationFlag: " << 

[Libreoffice-commits] online.git: net/Socket.hpp wsd/AdminModel.hpp

2017-04-10 Thread Jan Holesovsky
 net/Socket.hpp |7 +++
 wsd/AdminModel.hpp |2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

New commits:
commit e0f7c3fc670c9570dd9856958fcf1f4f97a35fef
Author: Jan Holesovsky 
Date:   Mon Apr 10 14:54:17 2017 +0200

Set the _owner even in the release builds.

We are warning about thread affinity even in the non-debug builds.

Change-Id: Ia91170765e9f4a29939dee847899345e9396d2c3

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 46499414..89844912 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -221,11 +221,11 @@ protected:
 {
 setNoDelay();
 _sendBufferSize = DefaultSendBufferSize;
-#if ENABLE_DEBUG
 _owner = std::this_thread::get_id();
 LOG_DBG("#" << _fd << " Thread affinity set to 0x" << std::hex <<
 _owner << "." << std::dec);
 
+#if ENABLE_DEBUG
 const int oldSize = getSocketBufferSize();
 setSocketBufferSize(0);
 LOG_TRC("#" << _fd << ": Buffer size: " << getSendBufferSize() <<
@@ -236,7 +236,8 @@ protected:
 private:
 const int _fd;
 int _sendBufferSize;
-// always enabled to avoid ABI change in debug mode ...
+
+/// We check the owner even in the release builds, needs to be always 
correct.
 std::thread::id _owner;
 };
 
@@ -533,11 +534,9 @@ private:
 Util::setThreadName(_name);
 LOG_INF("Starting polling thread [" << _name << "].");
 
-#if ENABLE_DEBUG
 _owner = std::this_thread::get_id();
 LOG_DBG("Thread affinity of " << _name << " set to 0x" <<
 std::hex << _owner << "." << std::dec);
-#endif
 
 // Invoke the virtual implementation.
 pollingThread();
diff --git a/wsd/AdminModel.hpp b/wsd/AdminModel.hpp
index 9a7ee8c9..80f0437b 100644
--- a/wsd/AdminModel.hpp
+++ b/wsd/AdminModel.hpp
@@ -208,7 +208,7 @@ private:
 std::list _cpuStats;
 unsigned _cpuStatsSize = 100;
 
-// always enabled to avoid ABI change in debug mode ...
+/// We check the owner even in the release builds, needs to be always 
correct.
 std::thread::id _owner;
 };
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-09 Thread Ashod Nakashian
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit cdb80e56325ba0b4d9abbd438d085f6c91c75855
Author: Ashod Nakashian 
Date:   Sun Apr 9 20:56:39 2017 -0400

wsd: assert valid socket where it counts

Change-Id: I19faa175066cab4e0435f6a8bf29e6b051c86420
Reviewed-on: https://gerrit.libreoffice.org/36330
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index d35e8810..46499414 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -272,12 +272,12 @@ public:
 void removeSockets()
 {
 LOG_DBG("Removing all sockets from " << _name << ".");
-assert(socket);
 assertCorrectThread();
 
 while (!_pollSockets.empty())
 {
 const std::shared_ptr& socket = _pollSockets.back();
+assert(socket);
 
 LOG_DBG("Removing socket #" << socket->getFD() << " from " << 
_name);
 socket->assertCorrectThread();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp

2017-04-09 Thread Ashod Nakashian
 net/Socket.hpp|2 +-
 net/SslSocket.hpp |4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 2ad3cd4de169625f89911953f7311f157b6ee26d
Author: Ashod Nakashian 
Date:   Sun Apr 9 16:33:28 2017 -0400

wsd: don't call virtuals in dtors

Change-Id: I2490e2f63dc20cf6b3fa0be45341b041e3ccb1bf
Reviewed-on: https://gerrit.libreoffice.org/36321
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 754c4d12..d35e8810 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -646,7 +646,7 @@ public:
 if (!_shutdownSignalled)
 {
 _shutdownSignalled = true;
-closeConnection();
+StreamSocket::closeConnection();
 }
 }
 
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index 2e495883..4b5d1323 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -16,7 +16,7 @@
 #include "Socket.hpp"
 
 /// An SSL/TSL, non-blocking, data streaming socket.
-class SslStreamSocket : public StreamSocket
+class SslStreamSocket final : public StreamSocket
 {
 public:
 SslStreamSocket(const int fd, std::shared_ptr 
responseClient) :
@@ -55,7 +55,7 @@ public:
 if (!_shutdownSignalled)
 {
 _shutdownSignalled = true;
-closeConnection();
+SslStreamSocket::closeConnection();
 }
 
 SSL_free(_ssl);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/LOOLWSD.cpp

2017-04-07 Thread Michael Meeks
 net/Socket.hpp  |2 ++
 wsd/LOOLWSD.cpp |7 ---
 2 files changed, 6 insertions(+), 3 deletions(-)

New commits:
commit 254de88a586d3599df16201ff2713ad6f086c200
Author: Michael Meeks 
Date:   Fri Apr 7 20:47:10 2017 +0100

Clear ownership of socket while it is being transferred.

This addresses a gap between ServerSocket accepting new sockets,
and their being added to their new polls.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 3b44e803..33dbbe5e 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -453,6 +453,8 @@ public:
 {
 std::lock_guard lock(_mutex);
 LOG_DBG("Inserting socket #" << newSocket->getFD() << " into " << 
_name);
+// sockets in transit are un-owned.
+newSocket->setThreadOwner(std::thread::id(0));
 _newSockets.emplace_back(newSocket);
 wakeup();
 }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 0fe28328..1fca253b 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1445,12 +1445,13 @@ private:
 UnitWSD::get().newChild(*this);
 
 auto child = std::make_shared(pid, socket, request);
-_childProcess = child; // weak
-addNewChild(child);
 
-// We no longer own this socket.
+// Drop pretentions of ownership before adding to the list.
 socket->setThreadOwner(std::thread::id(0));
 
+_childProcess = child; // weak
+addNewChild(child);
+
 // Remove from prisoner poll since there is no activity
 // until we attach the childProcess (with this socket)
 // to a docBroker, which will do the polling.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-07 Thread Miklos Vajna
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit b31474690a6121e851c08124ec3243909d0b9ede
Author: Miklos Vajna 
Date:   Fri Apr 7 09:39:52 2017 +0200

net: Socket::assertCorrectThread() can be non-virtual

None of the subclasses override it, and if they would, it would be
problematic, since e.g. the StreamSocket dtor calls it (and virtual
calls during dtors are a problem).

Change-Id: Ie0891349808a81539078fd1f2d95a55a4ce5107a

diff --git a/net/Socket.hpp b/net/Socket.hpp
index c726f337..3b44e803 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -193,7 +193,7 @@ public:
 }
 
 /// Asserts in the debug builds, otherwise just logs.
-virtual void assertCorrectThread()
+void assertCorrectThread()
 {
 if (InhibitThreadChecks)
 return;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-04-06 Thread Michael Meeks
 net/Socket.hpp |3 ---
 wsd/DocumentBroker.cpp |5 -
 wsd/DocumentBroker.hpp |3 ---
 wsd/LOOLWSD.cpp|4 ++--
 4 files changed, 2 insertions(+), 13 deletions(-)

New commits:
commit 3d945a5c3846d662e878a5daace5554704e0e586
Author: Michael Meeks 
Date:   Thu Apr 6 16:35:55 2017 +0100

Revert "Don't cleanup DocumentBrokers that still have their thread running."

This reverts commit df8dc43be4980302d4287c0692d02cf4fe6ca253.

DocumentBroker::isAlive already checks _threadFinished.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 42238751..c726f337 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -500,9 +500,6 @@ public:
 /// Stop and join the polling thread before returning (if active)
 void joinThread();
 
-/// Did our thread complete its execution
-bool isThreadFinished() { return _threadFinished; }
-
 private:
 /// Initialize the poll fds array with the right events
 void setupPollFds(std::chrono::steady_clock::time_point now,
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 9515fbb4..a5a995df 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -305,11 +305,6 @@ DocumentBroker::~DocumentBroker()
 _childProcess.reset();
 }
 
-bool DocumentBroker::isThreadFinished()
-{
-return _poll->isThreadFinished();
-}
-
 void DocumentBroker::joinThread()
 {
 _poll->joinThread();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 11d50174..d05437e9 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -227,9 +227,6 @@ public:
 /// Thread safe termination of this broker if it has a lingering thread
 void joinThread();
 
-/// Is our polling thread safely out of the way
-bool isThreadFinished();
-
 /// Loads a document from the public URI into the jail.
 bool load(const std::shared_ptr& session, const 
std::string& jailId);
 bool isLoaded() const { return _isLoaded; }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 1c446462..e5d4cb68 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -250,8 +250,8 @@ void cleanupDocBrokers()
 " DocumentBroker for docKey [" << it->first << "].");
 docBroker->stop();
 
-// Remove only on next pass when the thread is finished.
-if (docBroker->isThreadFinished() && !docBroker->isAlive())
+// Remove only when not alive.
+if (!docBroker->isAlive())
 {
 LOG_INF("Removing " << (idle ? "idle" : "dead") <<
 " DocumentBroker for docKey [" << it->first << 
"].");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-04-06 Thread Michael Meeks
 net/Socket.hpp |3 +++
 wsd/DocumentBroker.cpp |5 +
 wsd/DocumentBroker.hpp |3 +++
 wsd/LOOLWSD.cpp|4 ++--
 4 files changed, 13 insertions(+), 2 deletions(-)

New commits:
commit df8dc43be4980302d4287c0692d02cf4fe6ca253
Author: Michael Meeks 
Date:   Wed Apr 5 21:48:51 2017 +0100

Don't cleanup DocumentBrokers that still have their thread running.

Plenty of time to do that next time around the cleanup.
We should still, really be doing the majority of the timeout work
inside the DocumentBroker poll itself.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index c726f337..42238751 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -500,6 +500,9 @@ public:
 /// Stop and join the polling thread before returning (if active)
 void joinThread();
 
+/// Did our thread complete its execution
+bool isThreadFinished() { return _threadFinished; }
+
 private:
 /// Initialize the poll fds array with the right events
 void setupPollFds(std::chrono::steady_clock::time_point now,
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a5a995df..9515fbb4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -305,6 +305,11 @@ DocumentBroker::~DocumentBroker()
 _childProcess.reset();
 }
 
+bool DocumentBroker::isThreadFinished()
+{
+return _poll->isThreadFinished();
+}
+
 void DocumentBroker::joinThread()
 {
 _poll->joinThread();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index d05437e9..11d50174 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -227,6 +227,9 @@ public:
 /// Thread safe termination of this broker if it has a lingering thread
 void joinThread();
 
+/// Is our polling thread safely out of the way
+bool isThreadFinished();
+
 /// Loads a document from the public URI into the jail.
 bool load(const std::shared_ptr& session, const 
std::string& jailId);
 bool isLoaded() const { return _isLoaded; }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index e5d4cb68..1c446462 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -250,8 +250,8 @@ void cleanupDocBrokers()
 " DocumentBroker for docKey [" << it->first << "].");
 docBroker->stop();
 
-// Remove only when not alive.
-if (!docBroker->isAlive())
+// Remove only on next pass when the thread is finished.
+if (docBroker->isThreadFinished() && !docBroker->isAlive())
 {
 LOG_INF("Removing " << (idle ? "idle" : "dead") <<
 " DocumentBroker for docKey [" << it->first << 
"].");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-06 Thread Ashod Nakashian
 net/Socket.hpp |4 
 1 file changed, 4 insertions(+)

New commits:
commit a4176cf2f5deed829ed4e762fddb3429c44c8c91
Author: Ashod Nakashian 
Date:   Thu Apr 6 03:32:21 2017 -0400

wsd: don't invoke poll handler when invalidated

Only during shutdown do we expect a callback
to invalidate the pollSockets, but if it happens
we shouldn't invoke the poll handlers.

Change-Id: I2f56da19aec2f04cc871bd4eae1f93da110e0eb9
Reviewed-on: https://gerrit.libreoffice.org/36189
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index bb08dca1..c726f337 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -390,6 +390,10 @@ public:
 }
 }
 
+// This should only happen when we're stopping.
+if (_pollSockets.size() != size)
+return;
+
 // Fire the poll callbacks and remove dead fds.
 std::chrono::steady_clock::time_point newNow =
 std::chrono::steady_clock::now();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp

2017-04-06 Thread Ashod Nakashian
 net/Socket.hpp |   18 +-
 wsd/DocumentBroker.cpp |3 +++
 2 files changed, 20 insertions(+), 1 deletion(-)

New commits:
commit 4a7a0fb477a376e5c281208525777c2a926f8c6a
Author: Ashod Nakashian 
Date:   Thu Apr 6 01:32:39 2017 -0400

wsd: remove sockets when stopping poll thread

And assume correct thread if poll thread is
not running (i.e. no race).

Change-Id: I17958e682aba434ebb47fe0de199b9f530b54dee
Reviewed-on: https://gerrit.libreoffice.org/36183
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index d1a59b22..cd1ea6cc 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -264,7 +264,23 @@ public:
 /// Stop the polling thread.
 void stop()
 {
+LOG_DBG("Stopping " << _name << " and removing all sockets.");
 _stop = true;
+
+assert(socket);
+assertCorrectThread();
+
+while (!_pollSockets.empty())
+{
+const std::shared_ptr& socket = _pollSockets.back();
+
+LOG_DBG("Removing socket #" << socket->getFD() << " from " << 
_name);
+socket->assertCorrectThread();
+socket->setThreadOwner(std::thread::id(0));
+
+_pollSockets.pop_back();
+}
+
 wakeup();
 }
 
@@ -293,7 +309,7 @@ public:
 void assertCorrectThread() const
 {
 // 0 owner means detached and can be invoked by any thread.
-const bool sameThread = (_owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner);
+const bool sameThread = (!isAlive() || _owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner);
 if (!sameThread)
 LOG_ERR("Incorrect thread affinity for " << _name << ". Expected: 
0x" << std::hex <<
 _owner << " (" << std::dec << Util::getThreadId() << ") 
but called from 0x" <<
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 396bf52b..3ab3d121 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -264,6 +264,9 @@ void DocumentBroker::pollThread()
 _poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 5));
 }
 
+// Stop to mark it done and cleanup.
+_poll->stop();
+
 // Async cleanup.
 LOOLWSD::doHousekeeping();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/LOOLWSD.cpp

2017-04-06 Thread Ashod Nakashian
 net/Socket.hpp  |4 ++--
 wsd/LOOLWSD.cpp |   13 ++---
 2 files changed, 8 insertions(+), 9 deletions(-)

New commits:
commit cbe6f0c813116b0fee78a78cee19f10a1c1b7b35
Author: Ashod Nakashian 
Date:   Wed Apr 5 22:35:22 2017 -0400

wsd: move prisoner socket in the poll thread

Change-Id: I4097da97d4485d98618604c039a4570efe52bc19
Reviewed-on: https://gerrit.libreoffice.org/36181
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 6bfc6312..d1a59b22 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -459,8 +459,8 @@ public:
 assert(it != _pollSockets.end());
 
 _pollSockets.erase(it);
-LOG_TRC("Release socket #" << socket->getFD() << " from " << _name <<
-" leaving " << _pollSockets.size());
+LOG_DBG("Removing socket #" << socket->getFD() << " (of " <<
+_pollSockets.size() << ") from " << _name);
 }
 
 size_t getSocketCount() const
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index d2506f24..08a20ce7 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1458,6 +1458,8 @@ private:
 return SocketHandlerInterface::SocketOwnership::UNCHANGED;
 }
 
+in.clear();
+
 LOG_INF("New child [" << pid << "].");
 
 UnitWSD::get().newChild(*this);
@@ -1466,15 +1468,13 @@ private:
 _childProcess = child; // weak
 addNewChild(child);
 
-// We no longer own this thread: FIXME.
+// We no longer own this socket.
 socket->setThreadOwner(std::thread::id(0));
 
 // Remove from prisoner poll since there is no activity
 // until we attach the childProcess (with this socket)
 // to a docBroker, which will do the polling.
-PrisonerPoll.releaseSocket(socket);
-
-in.clear();
+return SocketHandlerInterface::SocketOwnership::MOVED;
 }
 catch (const std::exception& exc)
 {
@@ -1848,7 +1848,6 @@ private:
 
 cleanupDocBrokers();
 
-// FIXME: What if the same document is already open? Need 
a fake dockey here?
 LOG_DBG("New DocumentBroker for docKey [" << docKey << 
"].");
 DocBrokers.emplace(docKey, docBroker);
 LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after 
inserting [" << docKey << "].");
@@ -1865,7 +1864,7 @@ private:
 // Make sure the thread is running before adding 
callback.
 docBroker->startThread();
 
-// We no longer own this thread: FIXME.
+// We no longer own this socket.
 socket->setThreadOwner(std::thread::id(0));
 
 docBroker->addCallback([docBroker, socket, 
clientSession, format]()
@@ -2094,7 +2093,7 @@ private:
 // Make sure the thread is running before adding callback.
 docBroker->startThread();
 
-// We no longer own this thread: FIXME.
+// We no longer own this socket.
 socket->setThreadOwner(std::thread::id(0));
 
 docBroker->addCallback([docBroker, socket, clientSession]()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-05 Thread Jan Holesovsky
 net/Socket.hpp |4 
 1 file changed, 4 deletions(-)

New commits:
commit b6270fae57bf5f9512ea23a86c24eb9920dbe32f
Author: Jan Holesovsky 
Date:   Wed Apr 5 14:54:54 2017 +0200

setThreadOwner() is now needed in the release builds too.

Change-Id: I1a60bcbac4251866739fee59994a202394339015

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 706c8ef2..3692bd10 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -183,16 +183,12 @@ public:
 /// Set the thread-id we're bound to
 void setThreadOwner(const std::thread::id )
 {
-#if ENABLE_DEBUG
 if (id != _owner)
 {
 LOG_DBG("#" << _fd << " Thread affinity set to 0x" << std::hex <<
 id << " (was 0x" << _owner << ")." << std::dec);
 _owner = id;
 }
-#else
-   (void)id;
-#endif
 }
 
 /// Asserts in the debug builds, otherwise just logs.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp net/WebSocketHandler.hpp wsd/AdminModel.cpp wsd/AdminModel.hpp wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd

2017-04-05 Thread Jan Holesovsky
 net/Socket.hpp   |   53 ---
 net/SslSocket.hpp|   14 ++--
 net/WebSocketHandler.hpp |2 -
 wsd/AdminModel.cpp   |   48 +++---
 wsd/AdminModel.hpp   |3 +-
 wsd/ClientSession.cpp|2 -
 wsd/ClientSession.hpp|3 +-
 wsd/DocumentBroker.cpp   |   38 -
 wsd/DocumentBroker.hpp   |3 +-
 wsd/LOOLWSD.cpp  |2 -
 wsd/TestStubs.cpp|2 -
 11 files changed, 81 insertions(+), 89 deletions(-)

New commits:
commit cb2b788cc77912ce943bb891eebb2299950a0fc2
Author: Jan Holesovsky 
Date:   Wed Apr 5 14:48:49 2017 +0200

assert(isCorrectThread()) -> assertCorrectThread().

assert()'s are no-op in the release builds, but we still want to see 
threading
problems in the log at least.

Change-Id: Idb02bb018e8f2d628a57ab570249613ad00bcff2

diff --git a/net/Socket.hpp b/net/Socket.hpp
index a96c5c60..706c8ef2 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -195,20 +195,17 @@ public:
 #endif
 }
 
-virtual bool isCorrectThread()
+/// Asserts in the debug builds, otherwise just logs.
+virtual void assertCorrectThread()
 {
-#if ENABLE_DEBUG
 // 0 owner means detached and can be invoked by any thread.
 const bool sameThread = (_owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner);
 if (!sameThread)
-LOG_WRN("#" << _fd << " Invoked from foreign thread. Expected: 0x" 
<< std::hex <<
+LOG_ERR("#" << _fd << " Invoked from foreign thread. Expected: 0x" 
<< std::hex <<
 _owner << " but called from 0x" << 
std::this_thread::get_id() << " (" <<
 std::dec << Util::getThreadId() << ").");
 
-return sameThread;
-#else
-return true;
-#endif
+assert(sameThread);
 }
 
 protected:
@@ -293,25 +290,23 @@ public:
 }
 
 /// Are we running in either shutdown, or the polling thread.
-bool isCorrectThread() const
+/// Asserts in the debug builds, otherwise just logs.
+void assertCorrectThread() const
 {
-#if ENABLE_DEBUG
 // 0 owner means detached and can be invoked by any thread.
-if (_owner != std::thread::id(0) && std::this_thread::get_id() != 
_owner)
-LOG_WRN("Incorrect thread affinity for " << _name << ". Expected: 
0x" << std::hex <<
+const bool sameThread = (_owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner);
+if (!sameThread)
+LOG_ERR("Incorrect thread affinity for " << _name << ". Expected: 
0x" << std::hex <<
 _owner << " (" << std::dec << Util::getThreadId() << ") 
but called from 0x" <<
 std::hex << std::this_thread::get_id() << std::dec << ", 
stop: " << _stop);
 
-return _stop || _owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner;
-#else
-return true;
-#endif
+assert(_stop || sameThread);
 }
 
 /// Poll the sockets for available data to read or buffer to write.
 void poll(int timeoutMaxMs)
 {
-assert(isCorrectThread());
+assertCorrectThread();
 
 std::chrono::steady_clock::time_point now =
 std::chrono::steady_clock::now();
@@ -460,8 +455,8 @@ public:
 void releaseSocket(const std::shared_ptr& socket)
 {
 assert(socket);
-assert(isCorrectThread());
-assert(socket->isCorrectThread());
+assertCorrectThread();
+socket->assertCorrectThread();
 auto it = std::find(_pollSockets.begin(), _pollSockets.end(), socket);
 assert(it != _pollSockets.end());
 
@@ -472,7 +467,7 @@ public:
 
 size_t getSocketCount() const
 {
-assert(isCorrectThread());
+assertCorrectThread();
 return _pollSockets.size();
 }
 
@@ -621,10 +616,8 @@ public:
 
 if (!_closed)
 {
-if (isCorrectThread())
-_socketHandler->onDisconnect();
-else
-LOG_WRN("#" << getFD() << " not properly shutdown. 
onDisconnect not called.");
+assertCorrectThread();
+_socketHandler->onDisconnect();
 }
 
 if (!_shutdownSignalled)
@@ -651,7 +644,7 @@ public:
   int ) override
 {
 // cf. SslSocket::getPollEvents
-assert(isCorrectThread());
+assertCorrectThread();
 int events = _socketHandler->getPollEvents(now, timeoutMaxMs);
 if (!_outBuffer.empty() || _shutdownSignalled)
 events |= POLLOUT;
@@ -661,7 +654,7 @@ public:
 /// Send data to the socket peer.
 void send(const char* data, const int len, const bool flush = true)
 {
-assert(isCorrectThread());
+assertCorrectThread();
 if (data != nullptr && len > 0)
 {
 _outBuffer.insert(_outBuffer.end(), data, 

[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-05 Thread Jan Holesovsky
 net/Socket.hpp |4 
 1 file changed, 4 insertions(+)

New commits:
commit d345c29a477bf7edd98b7b884aaacc4c06b82869
Author: Jan Holesovsky 
Date:   Wed Apr 5 11:35:59 2017 +0200

The other isCorrectThread() should be active only in the debug build too.

Change-Id: Ieadb7e14f70752f5cfb2fd9ee569b56fb39d528b

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 4fa51dce..a96c5c60 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -295,6 +295,7 @@ public:
 /// Are we running in either shutdown, or the polling thread.
 bool isCorrectThread() const
 {
+#if ENABLE_DEBUG
 // 0 owner means detached and can be invoked by any thread.
 if (_owner != std::thread::id(0) && std::this_thread::get_id() != 
_owner)
 LOG_WRN("Incorrect thread affinity for " << _name << ". Expected: 
0x" << std::hex <<
@@ -302,6 +303,9 @@ public:
 std::hex << std::this_thread::get_id() << std::dec << ", 
stop: " << _stop);
 
 return _stop || _owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner;
+#else
+return true;
+#endif
 }
 
 /// Poll the sockets for available data to read or buffer to write.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-04 Thread Ashod Nakashian
 net/Socket.hpp |9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

New commits:
commit 463f26f417958d55270118f3aeac279ce689f2bc
Author: Ashod Nakashian 
Date:   Wed Apr 5 00:26:31 2017 -0400

wsd: mark detached sockets to have no owner

The DocBroker might not get a chance to
take ownership of a socket (which is done
via callbacks that are invoked in the poll loop)
if it (or WSD) is flagged for termination.

In that case, DocBroker doesn't take ownership
but ultimately needs to disconnect the socket.

By detaching ownership we signal that any thread
can rightly take ownership and thus avoid spurious
warning or assertions.

Change-Id: Idb192bfaac05c5c86809cb21876f3926a080b775
Reviewed-on: https://gerrit.libreoffice.org/36117
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index f0a9975c..4fa51dce 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -198,7 +198,8 @@ public:
 virtual bool isCorrectThread()
 {
 #if ENABLE_DEBUG
-const bool sameThread = std::this_thread::get_id() == _owner;
+// 0 owner means detached and can be invoked by any thread.
+const bool sameThread = (_owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner);
 if (!sameThread)
 LOG_WRN("#" << _fd << " Invoked from foreign thread. Expected: 0x" 
<< std::hex <<
 _owner << " but called from 0x" << 
std::this_thread::get_id() << " (" <<
@@ -294,12 +295,13 @@ public:
 /// Are we running in either shutdown, or the polling thread.
 bool isCorrectThread() const
 {
-if (std::this_thread::get_id() != _owner)
+// 0 owner means detached and can be invoked by any thread.
+if (_owner != std::thread::id(0) && std::this_thread::get_id() != 
_owner)
 LOG_WRN("Incorrect thread affinity for " << _name << ". Expected: 
0x" << std::hex <<
 _owner << " (" << std::dec << Util::getThreadId() << ") 
but called from 0x" <<
 std::hex << std::this_thread::get_id() << std::dec << ", 
stop: " << _stop);
 
-return _stop || std::this_thread::get_id() == _owner;
+return _stop || _owner == std::thread::id(0) || 
std::this_thread::get_id() == _owner;
 }
 
 /// Poll the sockets for available data to read or buffer to write.
@@ -392,6 +394,7 @@ public:
 {
 LOG_DBG("Removing socket #" << _pollFds[i].fd << " (of " <<
 _pollSockets.size() << ") from " << _name);
+_pollSockets[i]->setThreadOwner(std::thread::id(0));
 _pollSockets.erase(_pollSockets.begin() + i);
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/LOOLWSD.cpp

2017-04-04 Thread Ashod Nakashian
 net/Socket.hpp  |5 -
 wsd/LOOLWSD.cpp |4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

New commits:
commit cbd78484ad6efcea708b0deb3efb94bb6f0f
Author: Ashod Nakashian 
Date:   Tue Apr 4 21:04:48 2017 -0400

wsd: warn when waking dead poll

And insert sockets after starting the
thread so we poll the socket immediately.

Change-Id: Id336e1838f2f624ebfe59c4c2caf33eaa1a638c9
Reviewed-on: https://gerrit.libreoffice.org/36110
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 9e06a040..f0a9975c 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -407,12 +407,15 @@ public:
 } while (rc == -1 && errno == EINTR);
 
 if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
-LOG_WRN("wakeup socket #" << fd << " is closd at wakeup? error: " 
<< errno);
+LOG_SYS("wakeup socket #" << fd << " is closd at wakeup?");
 }
 
 /// Wakeup the main polling loop in another thread
 void wakeup()
 {
+if (!isAlive())
+LOG_WRN("Waking up dead poll thread [" << _name << "]");
+
 wakeup(_wakeup[1]);
 }
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 9e7bc8f8..e334f457 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2165,14 +2165,14 @@ public:
 
 void startPrisoners(const int port)
 {
-PrisonerPoll.insertNewSocket(findPrisonerServerPort(port));
 PrisonerPoll.startThread();
+PrisonerPoll.insertNewSocket(findPrisonerServerPort(port));
 }
 
 void start(const int port)
 {
-_acceptPoll.insertNewSocket(findServerPort(port));
 _acceptPoll.startThread();
+_acceptPoll.insertNewSocket(findServerPort(port));
 WebServerPoll.startThread();
 Admin::instance().start();
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-03 Thread Ashod Nakashian
 net/Socket.hpp |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

New commits:
commit 7ca1f03770c117a316b23644306160a6a80ea583
Author: Ashod Nakashian 
Date:   Mon Apr 3 23:13:03 2017 -0400

wsd: don't invoke onDisconnect from wrong thread

...and warn if we are in the wrong thread.

This can happen when the socket is not properly
closed from the poll thread and is being destroyed.

Change-Id: I749c09b15d04b49038f7cee6a7a13e8f0145acff
Reviewed-on: https://gerrit.libreoffice.org/36057
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 9cf83c49..9e06a040 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -610,7 +610,12 @@ public:
 LOG_DBG("StreamSocket dtor #" << getFD());
 
 if (!_closed)
-_socketHandler->onDisconnect();
+{
+if (isCorrectThread())
+_socketHandler->onDisconnect();
+else
+LOG_WRN("#" << getFD() << " not properly shutdown. 
onDisconnect not called.");
+}
 
 if (!_shutdownSignalled)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp

2017-04-02 Thread Ashod Nakashian
 net/Socket.hpp   |   16 ++--
 net/WebSocketHandler.hpp |2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

New commits:
commit 8932a1e92e9dbe61841a92d970751ecc41f32a80
Author: Ashod Nakashian 
Date:   Mon Apr 3 01:02:35 2017 -0400

wsd: remove LOOL_CHECK_THREADS

isCorrectThread now always checks
with ENABLE_DEBUG.

Change-Id: I2b5747f3ab18c8ebdbc92e7ffc86a2469b8c7d13
Reviewed-on: https://gerrit.libreoffice.org/36038
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 7d227732..9cf83c49 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -195,7 +195,7 @@ public:
 #endif
 }
 
-virtual bool isCorrectThread(bool hard = false)
+virtual bool isCorrectThread()
 {
 #if ENABLE_DEBUG
 const bool sameThread = std::this_thread::get_id() == _owner;
@@ -204,12 +204,8 @@ public:
 _owner << " but called from 0x" << 
std::this_thread::get_id() << " (" <<
 std::dec << Util::getThreadId() << ").");
 
-if (hard)
-return sameThread;
-else
-return !getenv("LOOL_CHECK_THREADS") || sameThread;
+return sameThread;
 #else
-(void)hard;
 return true;
 #endif
 }
@@ -455,7 +451,7 @@ public:
 {
 assert(socket);
 assert(isCorrectThread());
-assert(socket->isCorrectThread(true));
+assert(socket->isCorrectThread());
 auto it = std::find(_pollSockets.begin(), _pollSockets.end(), socket);
 assert(it != _pollSockets.end());
 
@@ -650,7 +646,7 @@ public:
 /// Send data to the socket peer.
 void send(const char* data, const int len, const bool flush = true)
 {
-assert(isCorrectThread(true));
+assert(isCorrectThread());
 if (data != nullptr && len > 0)
 {
 _outBuffer.insert(_outBuffer.end(), data, data + len);
@@ -732,7 +728,7 @@ protected:
 HandleResult handlePoll(std::chrono::steady_clock::time_point now,
 const int events) override
 {
-assert(isCorrectThread(true));
+assert(isCorrectThread());
 
 _socketHandler->checkTimeout(now);
 
@@ -800,7 +796,7 @@ protected:
 /// Override to write data out to socket.
 virtual void writeOutgoingData()
 {
-assert(isCorrectThread(true));
+assert(isCorrectThread());
 assert(!_outBuffer.empty());
 do
 {
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 0cf63a36..8d689de3 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -330,7 +330,7 @@ protected:
 if (!socket || data == nullptr || len == 0)
 return -1;
 
-assert(socket->isCorrectThread(true));
+assert(socket->isCorrectThread());
 std::vector& out = socket->_outBuffer;
 
 out.push_back(flags);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-02 Thread Ashod Nakashian
 net/Socket.hpp |   54 ++
 1 file changed, 26 insertions(+), 28 deletions(-)

New commits:
commit 78d1cc4ac5ec421777085abf2835425954378105
Author: Ashod Nakashian 
Date:   Sun Apr 2 21:33:36 2017 -0400

wsd: process callbacks before poll handlers

Callbacks are used to initialize handlers,
as is the case with addSession on DocumentBroker.

If the socket gets data before the callback is
invoked, the handler will fail since the expected
initialization hasn't happened yet.

This race indeed happens (rarely) with addSession.

100% (94/94) of old-style tests PASS.

Change-Id: Id9b4f63b45c5564add252e1671b7b0b08aff8150
Reviewed-on: https://gerrit.libreoffice.org/36035
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index e3d9569d..7d227732 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -327,32 +327,7 @@ public:
 LOG_TRC("Poll completed with " << rc << " live polls max (" <<
 timeoutMaxMs << "ms)" << ((rc==0) ? "(timedout)" : ""));
 
-// Fire the callback and remove dead fds.
-std::chrono::steady_clock::time_point newNow =
-std::chrono::steady_clock::now();
-for (int i = static_cast(size) - 1; i >= 0; --i)
-{
-Socket::HandleResult res = Socket::HandleResult::SOCKET_CLOSED;
-try
-{
-res = _pollSockets[i]->handlePoll(newNow, _pollFds[i].revents);
-}
-catch (const std::exception& exc)
-{
-LOG_ERR("Error while handling poll for socket #" <<
-_pollFds[i].fd << " in " << _name << ": " << 
exc.what());
-}
-
-if (res == Socket::HandleResult::SOCKET_CLOSED ||
-res == Socket::HandleResult::MOVED)
-{
-LOG_DBG("Removing socket #" << _pollFds[i].fd << " (of " <<
-_pollSockets.size() << ") from " << _name);
-_pollSockets.erase(_pollSockets.begin() + i);
-}
-}
-
-// Process the wakeup pipe (always the last entry).
+// First process the wakeup pipe (always the last entry).
 if (_pollFds[size].revents)
 {
 std::vector invoke;
@@ -399,6 +374,31 @@ public:
 "] wakeup hook: " << exc.what());
 }
 }
+
+// Fire the poll callbacks and remove dead fds.
+std::chrono::steady_clock::time_point newNow =
+std::chrono::steady_clock::now();
+for (int i = static_cast(size) - 1; i >= 0; --i)
+{
+Socket::HandleResult res = Socket::HandleResult::SOCKET_CLOSED;
+try
+{
+res = _pollSockets[i]->handlePoll(newNow, _pollFds[i].revents);
+}
+catch (const std::exception& exc)
+{
+LOG_ERR("Error while handling poll for socket #" <<
+_pollFds[i].fd << " in " << _name << ": " << 
exc.what());
+}
+
+if (res == Socket::HandleResult::SOCKET_CLOSED ||
+res == Socket::HandleResult::MOVED)
+{
+LOG_DBG("Removing socket #" << _pollFds[i].fd << " (of " <<
+_pollSockets.size() << ") from " << _name);
+_pollSockets.erase(_pollSockets.begin() + i);
+}
+}
 }
 
 /// Write to a wakeup descriptor
@@ -430,8 +430,6 @@ public:
 if (newSocket)
 {
 std::lock_guard lock(_mutex);
-// Beware - _thread may not be created & started yet.
-newSocket->setThreadOwner(_thread.get_id());
 LOG_DBG("Inserting socket #" << newSocket->getFD() << " into " << 
_name);
 _newSockets.emplace_back(newSocket);
 wakeup();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-04-02 Thread Ashod Nakashian
 net/Socket.hpp |   22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

New commits:
commit 6e596d11f3ebe09ad1b50c395f920b591805f4b6
Author: Ashod Nakashian 
Date:   Sun Apr 2 19:56:13 2017 -0400

wsd: catch exceptions from callbacks and wakup hook

Change-Id: Ib4579a34c91cfe43e5bd7038b175175a9ab0036a
Reviewed-on: https://gerrit.libreoffice.org/36033
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 200c389b..e3d9569d 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -377,9 +377,27 @@ public:
 }
 
 for (size_t i = 0; i < invoke.size(); ++i)
-invoke[i]();
+{
+try
+{
+invoke[i]();
+}
+catch (const std::exception& exc)
+{
+LOG_ERR("Exception while invoking poll [" << _name <<
+"] callback: " << exc.what());
+}
+}
 
-wakeupHook();
+try
+{
+wakeupHook();
+}
+catch (const std::exception& exc)
+{
+LOG_ERR("Exception while invoking poll [" << _name <<
+"] wakeup hook: " << exc.what());
+}
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp

2017-03-31 Thread Michael Meeks
 net/Socket.hpp   |   23 +--
 net/WebSocketHandler.hpp |6 ++
 2 files changed, 7 insertions(+), 22 deletions(-)

New commits:
commit 194c169f6811d0a00e04108ef2f3e4061ca4fac8
Author: Michael Meeks 
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 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 getWriteLock() { return 
std::unique_lock(_writeMutex); }
-
 protected:
 /// Client handling the actual data.
 std::shared_ptr _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(WSFrameMask::Fin)
   | static_cast(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& 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& out = socket->_outBuffer;
 
 out.push_back(flags);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-30 Thread Jan Holesovsky
 net/Socket.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 1d335b92ce771e311e8c0faaeaf112208bea75f6
Author: Jan Holesovsky 
Date:   Thu Mar 30 11:21:10 2017 +0200

Avoid extensive warning about a normal situation.

Change-Id: Ie67a12847afddac087f74e4872744b2b8bb07b1e

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 8bddac16..111b32df 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -792,7 +792,7 @@ protected:
 // log.dump("", &_outBuffer[0], len);
 }
 
-if (len <= 0)
+if (len <= 0 && errno != EAGAIN && errno != EWOULDBLOCK)
 LOG_SYS("#" << getFD() << ": Wrote outgoing data " << len 
<< " bytes.");
 }
 while (len < 0 && errno == EINTR);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp

2017-03-26 Thread Ashod Nakashian
 net/Socket.hpp |6 ++
 wsd/DocumentBroker.cpp |4 
 2 files changed, 10 insertions(+)

New commits:
commit 6d7f39356c26aed41aef5042b13e52aa63e9d812
Author: Ashod Nakashian 
Date:   Sun Mar 26 23:10:24 2017 -0400

wsd: flush sockets before exiting DocBroker poll thread

Change-Id: Id5384c113bd761b5b8c25286f1bd5a28051c63d3
Reviewed-on: https://gerrit.libreoffice.org/35740
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 9ff5a85a..95384397 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -435,6 +435,12 @@ public:
 " leaving " << _pollSockets.size());
 }
 
+size_t getSocketCount() const
+{
+assert(isCorrectThread());
+return _pollSockets.size();
+}
+
 const std::string& name() const { return _name; }
 
 /// Start the polling thread (if desired)
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 26452a9b..97b81fdd 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -247,6 +247,10 @@ void DocumentBroker::pollThread()
 }
 }
 
+// Flush socket data.
+for (int i = 0; i < 7 && _poll->getSocketCount() > 0; ++i)
+_poll->poll(POLL_TIMEOUT_MS / 5);
+
 // Terminate properly while we can.
 auto lock = getLock();
 terminateChild(lock, "", false);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/LOOLWSD.cpp

2017-03-26 Thread Ashod Nakashian
 net/Socket.hpp  |2 +-
 wsd/LOOLWSD.cpp |1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

New commits:
commit f2f00402755e765019c9a38a84500f243156a1bd
Author: Ashod Nakashian 
Date:   Sun Mar 26 23:08:10 2017 -0400

wsd: use isCorrectThread

Change-Id: Id63c30b19489d590b995e0ea66ef2f44e8cddfb7
Reviewed-on: https://gerrit.libreoffice.org/35738
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 6a511744..9ff5a85a 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -288,7 +288,7 @@ public:
 }
 
 /// Are we running in either shutdown, or the polling thread.
-bool isCorrectThread()
+bool isCorrectThread() const
 {
 return _stop || std::this_thread::get_id() == _owner;
 }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 05abba1d..ad1f4ece 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1416,6 +1416,7 @@ private:
 if (docBroker)
 {
 auto lock = docBroker->getLock();
+assert(docBroker->isCorrectThread());
 docBroker->terminateChild(lock, "Service unavailable", false);
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp wsd/LOOLWSD.cpp

2017-03-26 Thread Ashod Nakashian
 net/Socket.hpp   |2 +-
 net/WebSocketHandler.hpp |9 -
 wsd/LOOLWSD.cpp  |   20 +++-
 3 files changed, 24 insertions(+), 7 deletions(-)

New commits:
commit 5ae94cc7ecc023122dfa4b67fa22bb2cf75fb088
Author: Ashod Nakashian 
Date:   Sun Mar 26 23:06:44 2017 -0400

wsd: onConnect takes shared_ptr and better logging

Change-Id: I175dfa1f28444b9bb1f612242ee44b6d0507272c
Reviewed-on: https://gerrit.libreoffice.org/35737
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 56a33de6..6a511744 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -516,7 +516,7 @@ public:
 /// Called when the socket is newly created to
 /// set the socket associated with this ResponseClient.
 /// Will be called exactly once.
-virtual void onConnect(const std::weak_ptr& socket) = 0;
+virtual void onConnect(const std::shared_ptr& socket) = 0;
 
 enum class SocketOwnership
 {
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 6983fbae..ce0d13e9 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -62,9 +62,10 @@ public:
 }
 
 /// Implementation of the SocketHandlerInterface.
-void onConnect(const std::weak_ptr& socket) override
+void onConnect(const std::shared_ptr& socket) override
 {
 _socket = socket;
+LOG_TRC("#" << socket->getFD() << " Connected to WS Handler 0x" << 
std::hex << this << std::dec);
 }
 
 enum WSOpCode {
@@ -105,7 +106,10 @@ public:
 {
 auto socket = _socket.lock();
 if (socket == nullptr)
+{
+LOG_ERR("No socket associated with WebSocketHandler 0x" << 
std::hex << this << std::dec);
 return;
+}
 
 LOG_TRC("#" << socket->getFD() << ": Shutdown websocket, code: " <<
 static_cast(statusCode) << ", message: " << 
statusMessage);
@@ -128,7 +132,10 @@ public:
 {
 auto socket = _socket.lock();
 if (socket == nullptr)
+{
+LOG_ERR("No socket associated with WebSocketHandler 0x" << 
std::hex << this << std::dec);
 return false;
+}
 
 // websocket fun !
 const size_t len = socket->_inBuffer.size();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index d9b1db56..05abba1d 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1396,15 +1396,19 @@ public:
 
 private:
 /// Keep our socket around ...
-void onConnect(const std::weak_ptr& socket) override
+void onConnect(const std::shared_ptr& socket) override
 {
-LOG_TRC("Prisoner - new socket");
 _socket = socket;
+LOG_TRC("#" << socket->getFD() << " Prisoner connected.");
 }
 
 void onDisconnect() override
 {
-LOG_TRC("Prisoner connection disconnected");
+auto socket = _socket.lock();
+if (socket)
+LOG_TRC("#" << socket->getFD() << " Prisoner connection 
disconnected.");
+else
+LOG_WRN("Prisoner connection disconnected but without valid 
socket.");
 
 // Notify the broker that we're done.
 auto child = _childProcess.lock();
@@ -1525,7 +1529,11 @@ private:
 if (UnitWSD::get().filterChildMessage(data))
 return;
 
-LOG_TRC("Prisoner message [" << getAbbreviatedMessage([0], 
data.size()) << "].");
+auto socket = _socket.lock();
+if (socket)
+LOG_TRC("#" << socket->getFD() << " Prisoner message [" << 
getAbbreviatedMessage([0], data.size()) << "].");
+else
+LOG_WRN("Message handler called but without valid socket.");
 
 auto child = _childProcess.lock();
 auto docBroker = child ? child->getDocumentBroker() : nullptr;
@@ -1567,10 +1575,11 @@ public:
 private:
 
 /// Set the socket associated with this ResponseClient.
-void onConnect(const std::weak_ptr& socket) override
+void onConnect(const std::shared_ptr& socket) override
 {
 _id = LOOLWSD::GenSessionId();
 _socket = socket;
+LOG_TRC("#" << socket->getFD() << " Connected to 
ClientRequestDispatcher.");
 }
 
 /// Called after successful socket reads.
@@ -2108,6 +2117,7 @@ private:
 {
 // Set the ClientSession to handle Socket events.
 socket->setHandler(clientSession);
+LOG_DBG("Socket #" << socket->getFD() << " handler is " << 
clientSession->getName());
 
 // Move the socket into DocBroker.
 docBroker->addSocketToPoll(socket);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/SslSocket.hpp net/WebSocketHandler.hpp

2017-03-25 Thread Ashod Nakashian
 net/Socket.hpp   |1 +
 net/SslSocket.hpp|2 +-
 net/WebSocketHandler.hpp |   15 ++-
 3 files changed, 12 insertions(+), 6 deletions(-)

New commits:
commit 3895897213930c45c63b9ab3049c6bc101ebc114
Author: Ashod Nakashian 
Date:   Sat Mar 25 21:50:24 2017 -0400

wsd: improved socket logging

Change-Id: Ib4751a5a73b7ec0c7ca319f552d5e0aaff06ffea
Reviewed-on: https://gerrit.libreoffice.org/35707
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index e0ecc807..56a33de6 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -69,6 +69,7 @@ public:
 /// TODO: Support separate read/write shutdown.
 virtual void shutdown()
 {
+LOG_TRC("#" << _fd << ": socket shutdown RDWR.");
 ::shutdown(_fd, SHUT_RDWR);
 }
 
diff --git a/net/SslSocket.hpp b/net/SslSocket.hpp
index 3654c4b7..ec732c1a 100644
--- a/net/SslSocket.hpp
+++ b/net/SslSocket.hpp
@@ -64,7 +64,7 @@ public:
 /// Shutdown the TLS/SSL connection properly.
 void closeConnection() override
 {
-LOG_DBG("SslStreamSocket::performShutdown() #" << getFD());
+LOG_DBG("SslStreamSocket::closeConnection() #" << getFD());
 if (SSL_shutdown(_ssl) == 0)
 {
 // Complete the bidirectional shutdown.
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 64b057b9..08500bf2 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -107,7 +107,9 @@ public:
 if (socket == nullptr)
 return;
 
-LOG_TRC("#" << socket->getFD() << ": Shutdown websocket.");
+LOG_TRC("#" << socket->getFD() << ": Shutdown websocket, code: " <<
+static_cast(statusCode) << ", message: " << 
statusMessage);
+_shuttingDown = true;
 
 const size_t len = statusMessage.size();
 std::vector buf(2 + len);
@@ -119,7 +121,6 @@ public:
 
 auto lock = socket->getWriteLock();
 sendFrame(socket, buf.data(), buf.size(), flags);
-_shuttingDown = true;
 }
 
 /// Implementation of the SocketHandlerInterface.
@@ -197,16 +198,16 @@ public:
 socket->_inBuffer.erase(socket->_inBuffer.begin(), 
socket->_inBuffer.begin() + headerLen + payloadLen);
 
 // FIXME: fin, aggregating payloads into _wsPayload etc.
-LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " 
<< code << " fin? " << fin << " payload length " << _wsPayload.size());
+LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " 
<< code << " fin? " << fin << ", payload length: " << _wsPayload.size());
 
 switch (code)
 {
 case WSOpCode::Pong:
 _pingTimeUs = 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 - _pingSent).count();
-LOG_TRC("Pong received: " << _pingTimeUs << " microseconds");
+LOG_TRC("#" << socket->getFD() << ": Pong received: " << 
_pingTimeUs << " microseconds");
 break;
 case WSOpCode::Ping:
-LOG_ERR("Clients should not send pings, only servers");
+LOG_ERR("#" << socket->getFD() << ": Clients should not send 
pings, only servers");
 // drop through
 case WSOpCode::Close:
 if (!_shuttingDown)
@@ -224,6 +225,10 @@ public:
 shutdown(statusCode);
 }
 }
+else
+{
+LOG_TRC("#" << socket->getFD() << ": Client responded to our 
shutdown.");
+}
 
 // TCP Close.
 socket->closeConnection();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp wsd/Admin.cpp

2017-03-17 Thread Michael Meeks
 net/Socket.hpp   |9 +++--
 net/WebSocketHandler.hpp |   45 +++--
 wsd/Admin.cpp|4 ++--
 3 files changed, 48 insertions(+), 10 deletions(-)

New commits:
commit a6a4094e52c3a7fafac4a617ca3956dc6228eb29
Author: Michael Meeks 
Date:   Fri Mar 17 22:59:03 2017 +

Send ping message, handle pong & store ping-time on the Websocket.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 268994a7..37b9478c 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -304,7 +304,7 @@ public:
 int rc;
 do
 {
-rc = ::poll(&_pollFds[0], size + 1, timeoutMaxMs);
+rc = ::poll(&_pollFds[0], size + 1, std::max(timeoutMaxMs,0));
 }
 while (rc < 0 && errno == EINTR);
 LOG_TRC("Poll completed with " << rc << " live polls max (" << 
timeoutMaxMs << "ms)"
@@ -524,6 +524,9 @@ public:
 virtual int getPollEvents(std::chrono::steady_clock::time_point now,
   int ) = 0;
 
+/// Do we need to handle a timeout ?
+virtual void checkTimeout(std::chrono::steady_clock::time_point /* now */) 
{}
+
 /// Do some of the queued writing.
 virtual void performWrites() = 0;
 
@@ -673,11 +676,13 @@ protected:
 
 /// Called when a polling event is received.
 /// @events is the mask of events that triggered the wake.
-HandleResult handlePoll(std::chrono::steady_clock::time_point /* now */,
+HandleResult handlePoll(std::chrono::steady_clock::time_point now,
 const int events) override
 {
 assert(isCorrectThread());
 
+_socketHandler->checkTimeout(now);
+
 if (!events)
 return Socket::HandleResult::CONTINUE;
 
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 50c5d0e9..bb6af23b 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -23,6 +23,10 @@ protected:
 // The socket that owns us (we can't own it).
 std::weak_ptr _socket;
 
+const int PingFrequencyMs = 18 * 1000;
+std::chrono::steady_clock::time_point _pingSent;
+int _pingTimeUs;
+
 std::vector _wsPayload;
 bool _shuttingDown;
 enum class WSState { HTTP, WS } _wsState;
@@ -35,6 +39,8 @@ protected:
 
 public:
 WebSocketHandler() :
+_pingSent(std::chrono::steady_clock::now()),
+_pingTimeUs(0),
 _shuttingDown(false),
 _wsState(WSState::HTTP)
 {
@@ -44,6 +50,8 @@ public:
 WebSocketHandler(const std::weak_ptr& socket,
  const Poco::Net::HTTPRequest& request) :
 _socket(socket),
+_pingSent(std::chrono::steady_clock::now()),
+_pingTimeUs(0),
 _shuttingDown(false),
 _wsState(WSState::HTTP)
 {
@@ -187,8 +195,16 @@ public:
 // FIXME: fin, aggregating payloads into _wsPayload etc.
 LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " 
<< code << " fin? " << fin << " payload length " << _wsPayload.size());
 
-if (code & WSOpCode::Close)
+switch (code)
 {
+case WSOpCode::Pong:
+_pingTimeUs = 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 - _pingSent).count();
+LOG_TRC("Pong received: " << _pingTimeUs << " microseconds");
+break;
+case WSOpCode::Ping:
+LOG_ERR("Clients should not send pings, only servers");
+// drop through
+case WSOpCode::Close:
 if (!_shuttingDown)
 {
 // Peer-initiated shutdown must be echoed.
@@ -207,10 +223,10 @@ public:
 
 // TCP Close.
 socket->shutdown();
-}
-else
-{
+break;
+default:
 handleMessage(fin, code, _wsPayload);
+break;
 }
 
 _wsPayload.clear();
@@ -225,12 +241,29 @@ public:
 ; // can have multiple msgs in one recv'd packet.
 }
 
-int getPollEvents(std::chrono::steady_clock::time_point /* now */,
-  int & /* timeoutMaxMs */) override
+int getPollEvents(std::chrono::steady_clock::time_point now,
+  int & timeoutMaxMs) override
 {
+int timeSincePingMs =
+std::chrono::duration_cast(now - 
_pingSent).count();
+timeoutMaxMs = std::min(timeoutMaxMs, PingFrequencyMs - 
timeSincePingMs);
 return POLLIN;
 }
 
+/// Do we need to handle a timeout ?
+void checkTimeout(std::chrono::steady_clock::time_point now) override
+{
+int timeSincePingMs =
+std::chrono::duration_cast(now - 
_pingSent).count();
+if (timeSincePingMs >= PingFrequencyMs)
+{
+LOG_TRC("Send ping message");
+// FIXME: allow an empty payload.
+sendMessage("", 1, WSOpCode::Ping, false);
+_pingSent = now;
+}
+}
+
 /// By default rely on 

[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-13 Thread Ashod Nakashian
 net/Socket.hpp |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

New commits:
commit b2583550393ec0ad44636d0ae27b89495b36b24e
Author: Ashod Nakashian 
Date:   Mon Mar 13 21:59:50 2017 -0400

wsd: StreamSocket supports changing its SocketHandler

Change-Id: I2ffc33daad4da5b98183af39e3c2a64e7e10b3e8
Reviewed-on: https://gerrit.libreoffice.org/35158
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 75d92ee..a5405a8 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -513,7 +513,7 @@ public:
 };
 
 /// A plain, non-blocking, data streaming socket.
-class StreamSocket : public Socket
+class StreamSocket : public Socket, public 
std::enable_shared_from_this
 {
 public:
 /// Create a StreamSocket from native FD and take ownership of handler 
instance.
@@ -625,6 +625,13 @@ public:
 return len != 0; // zero is eof / clean socket close.
 }
 
+/// Replace the existing SocketHandler with a new one.
+void setHandler(std::unique_ptr handler)
+{
+_socketHandler = std::move(handler);
+_socketHandler->onConnect(shared_from_this());
+}
+
 /// Create a socket of type TSocket given an FD and a handler.
 /// We need this helper since the handler needs a shared_ptr to the socket
 /// but we can't have a shared_ptr in the ctor.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/FileServer.cpp wsd/LOOLWSD.cpp

2017-03-13 Thread Ashod Nakashian
 net/Socket.hpp |   20 +++-
 wsd/FileServer.cpp |   12 ++--
 wsd/LOOLWSD.cpp|8 
 3 files changed, 13 insertions(+), 27 deletions(-)

New commits:
commit 8b9623010a1878f6af4509af939f3fceafca
Author: Ashod Nakashian 
Date:   Mon Mar 13 19:38:19 2017 -0400

wsd: sendHttpResponse -> send

Change-Id: I7c94f6d4cd1054ea86585bfcd4079140471f3518
Reviewed-on: https://gerrit.libreoffice.org/35157
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index f85fa9b..75d92ee 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -290,7 +290,6 @@ public:
 return _stop || std::this_thread::get_id() == _owner;
 }
 
-public:
 /// Poll the sockets for available data to read or buffer to write.
 void poll(const int timeoutMaxMs)
 {
@@ -586,26 +585,13 @@ public:
 send(str.data(), str.size(), flush);
 }
 
-/// Sends HTTP response data.
-void sendHttpResponse(const char* data, const int len)
-{
-// Send the data and flush.
-send(data, len, true);
-}
-
-/// Sends HTTP response string.
-void sendHttpResponse(const std::string& str)
-{
-sendHttpResponse(str.data(), str.size());
-}
-
 /// Sends HTTP response.
-void sendHttpResponse(Poco::Net::HTTPResponse& response)
+void send(Poco::Net::HTTPResponse& response)
 {
 response.set("User-Agent", HTTP_AGENT_STRING);
 std::ostringstream oss;
 response.write(oss);
-sendHttpResponse(oss.str());
+send(oss.str());
 }
 
 /// Reads data by invoking readData() and buffering.
@@ -836,7 +822,7 @@ namespace HttpHelper
 response.write(oss);
 const std::string header = oss.str();
 LOG_TRC("Sending file [" << path << "]: " << header);
-socket->sendHttpResponse(header);
+socket->send(header);
 
 std::ifstream file(path, std::ios::binary);
 bool flush = true;
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 8c35f3f..2189205 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -190,7 +190,7 @@ void FileServerRequestHandler::handleRequest(const 
HTTPRequest& request, Poco::M
 << "User-Agent: LOOLWSD WOPI Agent\r\n"
 << "Cache-Control: max-age=11059200\r\n"
 << "\r\n";
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 socket->shutdown();
 return;
 }
@@ -212,7 +212,7 @@ void FileServerRequestHandler::handleRequest(const 
HTTPRequest& request, Poco::M
 << "Content-Length: 0\r\n"
 << "WWW-Authenticate: Basic realm=\"online\"\r\n"
 << "\r\n";
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 }
 catch (const Poco::FileAccessDeniedException& exc)
 {
@@ -225,7 +225,7 @@ void FileServerRequestHandler::handleRequest(const 
HTTPRequest& request, Poco::M
 << "User-Agent: LOOLWSD WOPI Agent\r\n"
 << "Content-Length: 0\r\n"
 << "\r\n";
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 }
 catch (const Poco::FileNotFoundException& exc)
 {
@@ -238,7 +238,7 @@ void FileServerRequestHandler::handleRequest(const 
HTTPRequest& request, Poco::M
 << "User-Agent: LOOLWSD WOPI Agent\r\n"
 << "Content-Length: 0\r\n"
 << "\r\n";
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 }
 }
 
@@ -273,7 +273,7 @@ void FileServerRequestHandler::preprocessFile(const 
HTTPRequest& request, Poco::
 << "User-Agent: LOOLWSD WOPI Agent\r\n"
 << "Content-Length: 0\r\n"
 << "\r\n";
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 return;
 }
 
@@ -336,7 +336,7 @@ void FileServerRequestHandler::preprocessFile(const 
HTTPRequest& request, Poco::
 << "\r\n"
 << preprocess;
 
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 LOG_DBG("Sent file: " << path.toString() << ": " << preprocess);
 }
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 7c5a5a3..9f44137 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1779,7 +1779,7 @@ private:
 << "User-Agent: LOOLWSD WOPI Agent\r\n"
 << "Content-Length: 0\r\n"
 << "\r\n";
-socket->sendHttpResponse(oss.str());
+socket->send(oss.str());
 socket->shutdown();
 }
 }
@@ -1845,7 +1845,7 @@ private:
 }
 
 auto socket = _socket.lock();
-socket->sendHttpResponse(oss.str());
+

[Libreoffice-commits] online.git: net/Socket.hpp wsd/LOOLWSD.cpp

2017-03-13 Thread Michael Meeks
 net/Socket.hpp  |2 +-
 wsd/LOOLWSD.cpp |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit bf8068de18c9d20d80a7bfc5138e6723e61f4d9c
Author: Michael Meeks 
Date:   Mon Mar 13 13:39:05 2017 +

Clarify comment a little.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 396339f..f85fa9b 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -311,7 +311,7 @@ public:
 }
 while (rc < 0 && errno == EINTR);
 LOG_TRC("Poll completed with " << rc << " live polls "
-<< ((rc==0) ? "timeout" : ""));
+<< ((rc==0) ? "(timeout)" : ""));
 
 // Fire the callback and remove dead fds.
 Poco::Timestamp newNow;
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index b4d42ab..7c5a5a3 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1822,7 +1822,7 @@ private:
 void handleAdminRequest(const Poco::Net::HTTPRequest& request)
 {
 LOG_ERR("Admin request: " << request.getURI());
-// FIXME: implement admin support.
+// requestHandler = Admin::createRequestHandler();
 }
 
 void handleRootRequest(const Poco::Net::HTTPRequest& request)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-13 Thread Andras Timar
 net/Socket.hpp |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 07c0452ec1ec68e7a4d1992893570d9a9ad5
Author: Andras Timar 
Date:   Mon Mar 13 13:22:45 2017 +0100

fix error: unused parameter 'hard' [-Werror=unused-parameter]

Change-Id: Ie2f2a12cc2f5d6c2fd3319d3c870cc7f0a226fae

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 16c0cdc..396339f 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -196,6 +196,7 @@ public:
 else
 return !getenv("LOOL_CHECK_THREADS") || sameThread;
 #else
+(void)hard;
 return true;
 #endif
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-03-13 Thread Michael Meeks
 net/Socket.hpp |1 -
 wsd/DocumentBroker.cpp |5 +
 wsd/DocumentBroker.hpp |8 
 wsd/LOOLWSD.cpp|6 +-
 4 files changed, 14 insertions(+), 6 deletions(-)

New commits:
commit 97e9463f173c833ce9d4b0503ea865ebd70a7a33
Author: Michael Meeks 
Date:   Mon Mar 13 12:00:31 2017 +

Revert "wsd: TerminatingPoll always starts its own thread"

This reverts commit 388d7b1dbf1a5c2d155c0149247b3a319114f8b0.

It is vital to have clean control of thread start. By starting
a thread during init. of a member (or base-clase) we loose lots of
control, some examples:

Any members initialized after a member that auto-starts a
thread, is effectively un-defined, and cannot be accessed
reliably.

This is particularly problematic for sub-classes.

I've seen threads started before the base-class has
finished constructing in the original creating thread -
such that the vtable was not yet updated to the sub-class
causing the transient parent vtable used during construction
to be used in-error.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 5cced5f..16c0cdc 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -435,7 +435,6 @@ public:
 
 const std::string& name() const { return _name; }
 
-protected:
 /// Start the polling thread (if desired)
 void startThread();
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a53a7c1..04fe5ac 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -162,6 +162,11 @@ DocumentBroker::DocumentBroker(const std::string& uri,
 LOG_INF("DocumentBroker [" << _uriPublic.toString() << "] created. DocKey: 
[" << _docKey << "]");
 }
 
+void DocumentBroker::startThread()
+{
+_poll->startThread();
+}
+
 // The inner heart of the DocumentBroker - our poll loop.
 void DocumentBroker::pollThread()
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 8d7eb2a..8d36cb2 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -44,10 +44,7 @@ class TerminatingPoll : public SocketPoll
 {
 public:
 TerminatingPoll(const std::string ) :
-SocketPoll(threadName)
-{
-startThread();
-}
+SocketPoll(threadName) {}
 
 bool continuePolling() override
 {
@@ -221,6 +218,9 @@ public:
 
 ~DocumentBroker();
 
+/// Start processing events
+void startThread();
+
 /// Loads a document from the public URI into the jail.
 bool load(std::shared_ptr& session, const std::string& 
jailId);
 bool isLoaded() const { return _isLoaded; }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 97cf845..b4d42ab 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2177,6 +2177,7 @@ private:
 
 void handleClientWsUpgrade(const Poco::Net::HTTPRequest& request, const 
std::string& url)
 {
+// requestHandler = new ClientRequestHandler();
 LOG_INF("Client WS request" << request.getURI() << ", url: " << url);
 
 // First Upgrade.
@@ -2230,9 +2231,9 @@ private:
 _clientSession->onConnect(socket);
 docBroker->addSocketToPoll(socket);
 }
+docBroker->startThread();
 }
 }
-
 if (!docBroker || !_clientSession)
 LOG_WRN("Failed to connect DocBroker and Client Session.");
 }
@@ -2358,11 +2359,14 @@ public:
 void startPrisoners(const int port)
 {
 PrisonerPoll.insertNewSocket(findPrisonerServerPort(port));
+PrisonerPoll.startThread();
 }
 
 void start(const int port)
 {
 _acceptPoll.insertNewSocket(findServerPort(port));
+_acceptPoll.startThread();
+WebServerPoll.startThread();
 }
 
 void stop()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-12 Thread Ashod Nakashian
 net/Socket.hpp |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 94051f21b5ebbbc5c410842df8a302f2e2ff0832
Author: Ashod Nakashian 
Date:   Sun Mar 12 22:30:30 2017 -0400

wsd: SocketPoll::startThread can be protected

Change-Id: Idd17f7314ac181e9a412e05a1287e15edf5047d2
Reviewed-on: https://gerrit.libreoffice.org/35125
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 01f985c..5cced5f 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -252,9 +252,6 @@ public:
 /// Default poll time - useful to increase for debugging.
 static int DefaultPollTimeoutMs;
 
-/// Start the polling thread (if desired)
-void startThread();
-
 /// Stop the polling thread.
 void stop()
 {
@@ -438,8 +435,11 @@ public:
 
 const std::string& name() const { return _name; }
 
-private:
+protected:
+/// Start the polling thread (if desired)
+void startThread();
 
+private:
 /// Initialize the poll fds array with the right events
 void setupPollFds(Poco::Timestamp )
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-12 Thread Ashod Nakashian
 net/Socket.hpp |   39 ---
 1 file changed, 24 insertions(+), 15 deletions(-)

New commits:
commit 862d7a07342f1caad5a9474c480b06585c813bea
Author: Ashod Nakashian 
Date:   Sun Mar 12 22:29:30 2017 -0400

wsd: write as many messages to socket as possible

Change-Id: Ie2702ea68dd1ae6200fcc304224dea34fc94544f
Reviewed-on: https://gerrit.libreoffice.org/35123
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 4fe334b..01f985c 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -682,26 +682,35 @@ protected:
 _socketHandler->handleIncomingMessage();
 }
 
-// If we have space for writing and that was requested
-if ((events & POLLOUT) && _outBuffer.empty())
-_socketHandler->performWrites();
+do
+{
+// If we have space for writing and that was requested
+if ((events & POLLOUT) && _outBuffer.empty())
+_socketHandler->performWrites();
 
-// perform the shutdown if we have sent everything.
-if (_shutdownSignalled && _outBuffer.empty())
-closeConnection();
+// perform the shutdown if we have sent everything.
+if (_shutdownSignalled && _outBuffer.empty())
+{
+closeConnection();
+closed = true;
+break;
+}
 
-// SSL might want to do handshake,
-// even if we have no data to write.
-if ((events & POLLOUT) || !_outBuffer.empty())
-{
-std::unique_lock lock(_writeMutex, std::defer_lock);
+oldSize = _outBuffer.size();
 
-// The buffer could have been flushed while we waited for the lock.
-if (lock.try_lock() && !_outBuffer.empty())
-writeOutgoingData();
+// Write if we can and have data to write.
+if ((events & POLLOUT) || !_outBuffer.empty())
+{
+std::unique_lock lock(_writeMutex, 
std::defer_lock);
 
-closed = closed || (errno == EPIPE);
+// The buffer could have been flushed while we waited for the 
lock.
+if (lock.try_lock() && !_outBuffer.empty())
+writeOutgoingData();
+
+closed = closed || (errno == EPIPE);
+}
 }
+while (oldSize != _outBuffer.size());
 
 if (closed)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp

2017-03-12 Thread Ashod Nakashian
 net/Socket.hpp   |1 +
 net/WebSocketHandler.hpp |2 ++
 2 files changed, 3 insertions(+)

New commits:
commit c9a07a3087cced9c0ea8973a039b284bcb01a0e7
Author: Ashod Nakashian 
Date:   Sun Mar 12 19:04:52 2017 -0400

wsd: assert socket is in correct thread

Change-Id: I22c3f62bdf45188641326774dd86b7cacfce9198
Reviewed-on: https://gerrit.libreoffice.org/35120
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 6929938..c4badea 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -555,6 +555,7 @@ public:
 
 int getPollEvents() override
 {
+assert(isCorrectThread());
 if (!_outBuffer.empty() || _socketHandler->hasQueuedWrites() || 
_shutdownSignalled)
 return POLLIN | POLLOUT;
 else
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 7416586..d89f49b 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -255,6 +255,7 @@ public:
 if (socket == nullptr)
 return -1; // no socket == error.
 
+assert(socket->isCorrectThread());
 auto lock = socket->getWriteLock();
 std::vector& out = socket->_outBuffer;
 
@@ -287,6 +288,7 @@ protected:
 if (!socket || data == nullptr || len == 0)
 return -1;
 
+assert(socket->isCorrectThread());
 std::vector& out = socket->_outBuffer;
 
 out.push_back(flags);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-10 Thread Michael Meeks
 net/Socket.hpp |6 ++
 1 file changed, 6 insertions(+)

New commits:
commit c30fb670d800d9f3ef9d6006af5308111320fd9a
Author: Michael Meeks 
Date:   Fri Mar 10 18:20:51 2017 +

Work on LOOL_CHECK_THREADS=1 a little.

The situation made more problematic since the std::thread is only
created in startThread - so getting ownership right before then in
Socket is problematic.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 9259d88..87b8dea 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -354,6 +354,11 @@ public:
 // Copy the new sockets over and clear.
 _pollSockets.insert(_pollSockets.end(),
 _newSockets.begin(), _newSockets.end());
+
+// Update thread ownership.
+for (auto  : _newSockets)
+i->setThreadOwner(std::this_thread::get_id());
+
 _newSockets.clear();
 
 // Extract list of callbacks to process
@@ -395,6 +400,7 @@ public:
 if (newSocket)
 {
 std::lock_guard lock(_mutex);
+// Beware - _thread may not be created & started yet.
 newSocket->setThreadOwner(_thread.get_id());
 LOG_DBG("Inserting socket #" << newSocket->getFD() << " into " << 
_name);
 _newSockets.emplace_back(newSocket);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-03-10 Thread Michael Meeks
 net/Socket.hpp   |5 ++-
 net/WebSocketHandler.hpp |2 +
 wsd/DocumentBroker.cpp   |1 
 wsd/DocumentBroker.hpp   |1 
 wsd/LOOLWSD.cpp  |   64 ---
 5 files changed, 13 insertions(+), 60 deletions(-)

New commits:
commit 160446fd235c3d1bf25413fea18c72f1e3487cbe
Author: Michael Meeks 
Date:   Fri Mar 10 17:58:51 2017 +

Work on resurrecting dying DocumentBrokers if we can.

The hope is that they will close lingering session sockets at the
end and the client will re-connect.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index c5e5ece..9259d88 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -52,7 +52,9 @@ public:
 
 virtual ~Socket()
 {
-//TODO: Should we shutdown here or up to the client?
+// TODO: Should we shutdown here or up to the client?
+
+LOG_TRC("#" << getFD() << " close socket.");
 
 // Doesn't block on sockets; no error handling needed.
 close(_fd);
@@ -551,6 +553,7 @@ public:
 virtual void shutdown() override
 {
 _shutdownSignalled = true;
+LOG_TRC("#" << getFD() << ": shutdown signalled");
 }
 
 /// Perform the real shutdown.
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 5e987fb..7416586 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -97,6 +97,8 @@ public:
 if (socket == nullptr)
 return;
 
+LOG_TRC("#" << socket->getFD() << " shutdown websocket.");
+
 const size_t len = statusMessage.size();
 std::vector buf(2 + len);
 buf[0] = int)statusCode) >> 8) & 0xff);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f50d9a3..1369ba5 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -751,6 +751,7 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 // document). It is safe to reset their values to their defaults whenever 
a new session is added.
 _lastEditableSession = false;
 _markToDestroy = false;
+_stop = false;
 
 const auto id = session->getId();
 if (!_sessions.emplace(id, session).second)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 5594c70..b07b9b5 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -175,7 +175,6 @@ public:
 try
 {
 return _pid > 1 && _ws && kill(_pid, 0) == 0;
-// FIXME:!_ws->poll(Poco::Timespan(0), 
Poco::Net::Socket::SelectMode::SELECT_ERROR));
 }
 catch (const std::exception&)
 {
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 8d0a3a4e..7eafcdf 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1335,59 +1335,12 @@ static std::shared_ptr 
findOrCreateDocBroker(WebSocketHandler& w
 // Get the DocumentBroker from the Cache.
 LOG_DBG("Found DocumentBroker with docKey [" << docKey << "].");
 docBroker = it->second;
-if (docBroker->isMarkedToDestroy())
-{
-// Let the waiting happen in parallel to new requests.
-docBrokersLock.unlock();
-
-// If this document is going out, wait.
-LOG_DBG("Document [" << docKey << "] is marked to destroy, waiting 
to reload.");
-
-// FIXME: - easiest to send a fast message to the
-//  client to wait & retry in a bit ...
-
-#if 0 // loolnb
-bool timedOut = true;
-for (size_t i = 0; i < COMMAND_TIMEOUT_MS / POLL_TIMEOUT_MS; ++i)
-{
-
-// FIXME: blocks !
-
std::this_thread::sleep_for(std::chrono::milliseconds(POLL_TIMEOUT_MS));
-
-docBrokersLock.lock();
-it = DocBrokers.find(docKey);
-if (it == DocBrokers.end())
-{
-// went away successfully
-docBroker.reset();
-docBrokersLock.unlock();
-timedOut = false;
-break;
-}
-else if (it->second && !it->second->isMarkedToDestroy())
-{
-// was actually replaced by a real document
-docBroker = it->second;
-docBrokersLock.unlock();
-timedOut = false;
-break;
-}
 
-docBrokersLock.unlock();
-if (TerminationFlag)
-{
-LOG_ERR("Termination flag set. Not loading new session [" 
<< id << "]");
-return nullptr;
-}
-}
-
-if (timedOut)
-{
-// Still here, but marked to destroy. Proceed and hope to 
recover.
-LOG_ERR("Timed out while waiting for document to unload before 
loading.");
-}
-#endif
-}
+// Avoid notifying the client - 

[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-10 Thread Michael Meeks
 net/Socket.hpp |1 +
 1 file changed, 1 insertion(+)

New commits:
commit 34d9d52207166fb6ef05bc8b205844164d40c5f5
Author: Michael Meeks 
Date:   Fri Mar 10 12:11:46 2017 +

Avoid assert failure and zero size socket buffer in product build.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 98a2978..c09ad53 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -207,6 +207,7 @@ protected:
 void init()
 {
 setNoDelay();
+_sendBufferSize = DefaultSendBufferSize;
 #if ENABLE_DEBUG
 _owner = std::this_thread::get_id();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp

2017-03-10 Thread Michael Meeks
 net/Socket.hpp |4 
 1 file changed, 4 insertions(+)

New commits:
commit f4f083e6fe502f684e2ff888fbbba8da0d291134
Author: Michael Meeks 
Date:   Fri Mar 10 11:35:17 2017 +

Cache JS etc. on the client side for 128 days.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 583d580..98a2978 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -818,6 +818,10 @@ namespace HttpHelper
 
 response.setContentLength(st.st_size);
 response.set("User-Agent", HTTP_AGENT_STRING);
+// 60 * 60 * 24 * 128 (days) = 11059200
+response.set("Cache-Control", "max-age=11059200");
+response.set("ETag", LOOLWSD_VERSION_HASH);
+
 std::ostringstream oss;
 response.write(oss);
 const std::string header = oss.str();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp

2017-03-10 Thread Michael Meeks
 net/Socket.hpp   |   67 ++-
 net/WebSocketHandler.hpp |4 ++
 2 files changed, 53 insertions(+), 18 deletions(-)

New commits:
commit a5a227e9a3327bee423df9de6c3faae112aaa4bd
Author: Michael Meeks 
Date:   Fri Mar 10 09:55:28 2017 +

Re-work socket buffer options, sizing and setting.

Only set nodelay and small socket buffers on WebSockets.
Avoid writing more data than can be absorbed by our socket buffer.
It is fine to set socket buffer sizes after bind/accept.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 7b3199b..583d580 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -40,10 +40,14 @@
 class Socket
 {
 public:
+static const int DefaultSendBufferSize = 16 * 1024;
+static const int MaximumSendBufferSize = 128 * 1024;
+
 Socket() :
-_fd(socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0))
+_fd(socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0)),
+_sendBufferSize(DefaultSendBufferSize)
 {
-setNoDelay();
+init();
 }
 
 virtual ~Socket()
@@ -82,23 +86,39 @@ public:
 (char *) , sizeof(val));
 }
 
-/// Sets the send buffer in size bytes.
-/// Must be called before accept or connect.
+/// Sets the kernel socket send buffer in size bytes.
 /// Note: TCP will allocate twice this size for admin purposes,
 /// so a subsequent call to getSendBufferSize will return
 /// the larger (actual) buffer size, if this succeeds.
 /// Note: the upper limit is set via /proc/sys/net/core/wmem_max,
 /// and there is an unconfigurable lower limit as well.
 /// Returns true on success only.
-bool setSendBufferSize(const int size)
+bool setSocketBufferSize(const int size)
 {
-constexpr unsigned int len = sizeof(size);
-const int rc = ::setsockopt(_fd, SOL_SOCKET, SO_SNDBUF, , len);
-return (rc == 0);
+int rc = ::setsockopt(_fd, SOL_SOCKET, SO_SNDBUF, , sizeof(size));
+
+_sendBufferSize = getSocketBufferSize();
+if (rc != 0 || _sendBufferSize < 0 )
+{
+LOG_ERR("Error getting socket buffer size " << errno);
+_sendBufferSize = DefaultSendBufferSize;
+return false;
+}
+else
+{
+if (_sendBufferSize > MaximumSendBufferSize * 2)
+{
+LOG_TRC("Clamped send buffer size to " << 
MaximumSendBufferSize << " from " << _sendBufferSize);
+_sendBufferSize = MaximumSendBufferSize;
+}
+else
+LOG_TRC("Set socket buffer size to " << _sendBufferSize);
+return true;
+}
 }
 
 /// Gets the actual send buffer size in bytes, -1 for failure.
-int getSendBufferSize() const
+int getSocketBufferSize() const
 {
 int size;
 unsigned int len = sizeof(size);
@@ -106,10 +126,15 @@ public:
 return (rc == 0 ? size : -1);
 }
 
+/// Gets our fast cache of the socket buffer size
+int getSendBufferSize() const
+{
+return _sendBufferSize;
+}
+
 /// Sets the receive buffer size in bytes.
-/// Must be called before accept or connect.
 /// Note: TCP will allocate twice this size for admin purposes,
-/// so a subsequent call to getSendBufferSize will return
+/// so a subsequent call to getReceieveBufferSize will return
 /// the larger (actual) buffer size, if this succeeds.
 /// Note: the upper limit is set via /proc/sys/net/core/rmem_max,
 /// and there is an unconfigurable lower limit as well.
@@ -185,8 +210,8 @@ protected:
 #if ENABLE_DEBUG
 _owner = std::this_thread::get_id();
 
-const int oldSize = getSendBufferSize();
-setSendBufferSize(0);
+const int oldSize = getSocketBufferSize();
+setSocketBufferSize(0);
 LOG_TRC("Socket #" << _fd << " buffer size: " << getSendBufferSize() 
<< " (was " << oldSize << ")");
 #endif
 
@@ -194,6 +219,7 @@ protected:
 
 private:
 const int _fd;
+int _sendBufferSize;
 // always enabled to avoid ABI change in debug mode ...
 std::thread::id _owner;
 };
@@ -699,7 +725,9 @@ protected:
 ssize_t len;
 do
 {
-len = writeData(&_outBuffer[0], _outBuffer.size());
+// Writing more than we can absorb in the kernel causes SSL 
wasteage.
+len = writeData(&_outBuffer[0], 
std::min((int)_outBuffer.size(),
+ getSendBufferSize()));
 
 auto& log = Log::logger();
 if (log.trace() && len > 0) {
@@ -781,9 +809,12 @@ namespace HttpHelper
 return;
 }
 
-const int socketBufferSize = 16 * 1024;
-if (st.st_size >= socketBufferSize)
-socket->setSendBufferSize(socketBufferSize);
+int bufferSize =