Commit graph

393 commits

Author SHA1 Message Date
Miklos Vajna
85f24ccb55 CRYPTO_dynlock_value: make members private
Change-Id: I5328bd272d4aaef1a445b9ddc5dd4c878d803777
2018-12-03 09:11:22 +01:00
Michael Meeks
d00aa78c9b Don't name parameter after a local method.
Change-Id: I06929d23009b851cf3fb20da5bfe66d9795dcdd9
2018-11-07 17:37:25 +00:00
Michael Meeks
738abc1de7 Respond to SSL/TLS over http - when we don't expect it.
Change-Id: I48c7607cd4e1416fb4ac28c552c2cd96b51d60a6
2018-11-07 17:36:18 +00:00
Tor Lillqvist
f8a0fb4c32 WaE: -Werror=unused-parameter
Change-Id: Icadfcb19ce1fff2b5009d42acf33297cda6e36f2
2018-11-01 21:34:16 +02:00
Tor Lillqvist
9a0decc406 WaE: -Werror=sign-compare
Change-Id: Iaac48bd91864d44ce9442dd68aa26ec74fb5507a
2018-11-01 21:30:16 +02:00
Tor Lillqvist
ffe66b3efc Avoid 'Unused variable' warnings in the MOBILEAPP casse
Change-Id: I30d631559379da4baa5a73712f002435b1a36360
2018-10-30 22:03:04 +02:00
Tor Lillqvist
4ce96fb8ff Don't access nonexistent vector element in the EOF case 2018-10-30 00:47:26 +02:00
Tor Lillqvist
9fec3b0e27 Handle EOF case (when fakeSocketAvailableDataLength() returns 0) 2018-10-30 00:47:21 +02:00
Miklos Vajna
d1e183f20d SocketPoll: make members private
All these protected members are unused by child classes, except read
access to a single member.
2018-10-29 09:06:33 +01:00
Miklos Vajna
5167cf9f58 StreamSocket: make members private
Only a single member needed a setter, otherwise getters were enough.
2018-10-26 09:07:30 +02:00
Tor Lillqvist
a4b4f6bf36 Fix fakeSocketAvailableDataLength() when peer socket is closed
Also bin a few lines of unnecessary code.
2018-10-25 21:57:44 +03:00
Tor Lillqvist
8bc97c0f9e Adapt after 4724aa0cf7 2018-10-25 21:33:57 +03:00
Miklos Vajna
4724aa0cf7 Socket: do what the TODO says
Drop the list of friends and just add getters for the relevant
members.
2018-10-25 16:39:02 +02:00
Miklos Vajna
22fac18fcd WebSocket: make members private
All of them were protected, but only _socket was used actually. Add a
protected setter/getter for that field.
2018-10-24 09:36:13 +02:00
Tor Lillqvist
decf78ff2e Buffer an unlimited (eek, scary) number of messages per fake socket
Matches the behaviour of real sockets in a real Online server better.
Seems to get rid of the occasional hang problem.

I had already some time ago suspected that such a change would fix
that problem, but unfortunately my first attempt missed one crucial
detail, so it didn't, and I spent days looking for other ways to fix
the problem instead, in vain.

Probably I should add some sanity limit on the number of buffered
messages, though... But if such a sanity limit then would be hit, most
likely much else is totally broken already anyway.

Change-Id: Ice43057814ee5abd85b2935ffaa91765845a515a
2018-10-23 15:23:01 +03:00
Tor Lillqvist
d6d0c3e8a3 As far as I see, no getPollEvents() implementation will ever return negative
In 1c7f94045a 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 <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2018-10-19 13:41:18 +02:00
Tor Lillqvist
c6c6e8cc46 In fakeSocketConnect() log also the fd the corresponding accept returned 2018-10-19 02:03:32 +03:00
Tor Lillqvist
452a0a46c2 More work on the GTK+ testbed app
Add plumbing to send messages from the Online code to the JavaScript
code, and vice versa. Similar to what is done for iOS.

Sadly, it crashes. Multi-thread issues. Not surprisingly, it crashes
when I call webkit_web_view_run_javascript() in another thread than
the one where the GTK+ and other Webkit calls were done. I need to
come up with some clever way to do everything from the same thread.

(On iOS, I use dispatch_async(dispatch_get_main_queue(),...) to
schedule a block (i.e., a lambda expression) to be run in the main
thread.)
2018-10-17 22:48:14 +03:00
Tor Lillqvist
05c2782a81 Empty out _newCallbacks when stopping a SocketPoll in the MOBILEAPP case
The wakeup() call in SocketPoll::stop() doesn't always (or ever?)
actually cause the wakeup code to be invoked and callbacks called
right after, and we don't want to risk the leftover callbacks being
invoked when the same SocketPoll object is started again. (This did
actually happen.)

In a normal Online, this is not a problem, as SocketPolls aren't
reused. One document per kit process, a separate kit process for each
document. Not so in a mobile app, there we have just one process that
handles document after document as the user closes one, opens another
(or the same anew), etc.
2018-10-17 20:10:52 +03:00
Ashod Nakashian
f3d02cb9e2 wsd: support polling on client thread
Previously SocketPoll expected to be
running its own thread for polling.
This is unnecessary when we have a
spare thread (e.g. main) that can
(and should, for efficiency) be used
for polling rather than starting
dedicated thread.

Not starting the SocketPoll's thread
and calling SocketPoll::poll() directly
worked, the warning logs on each activity
notwithstanding.

The warnings aren't just noisy, they are
a performance drain as well, and signal
that something is wrong. The new code
now makes the API cleaner and avoids
unnecessary warning logs, while being
faster.

Change-Id: Ibf9a223c59dae6522a5fc2e5d84a8ef191b577b1
2018-10-16 20:12:23 -04:00
Ashod Nakashian
3158d4c31c wsd: always use signal-safe calls
The async-signal-safe functions to get thread-id
and thread-name, which cache the results, are
faster, cleaner, and signal-safe. No reason why
we shouldn't always use them.

Especially since it appears the logic was
inverted in Log::prefix, such that the signal
un-safe calls were made during signal-handling,
and the safe ones were called otherwise!

Instead of passing the signal-safe flag to
Log::prefix, we pass the buffer size, for
improved security.

Furthermore, reduce header dependencies
and reduce clutter.

Change-Id: I697689b2f0a290b6d8cce4babc3ac1e576141da6
2018-10-16 20:12:23 -04:00
Ashod Nakashian
63c3fce2c6 wsd: clang-format logging macros and pass logger explicitly
Change-Id: I37e7f4b5687b64b36e0985942627a4b84a8249eb
2018-10-16 20:12:23 -04:00
Tor Lillqvist
e9d0b38103 Add some includes that are missing if compiling this on Linux
Change-Id: Iffe3481e56842f29f0e7838ca024b28e1f7187f3
2018-10-16 23:56:46 +03:00
Tor Lillqvist
6316aaf0f5 Initialise also _threadFinished and _stop in SocketPoll::startThread()
I am trying to get a SocketPoll object to be "restartable".

Also make the lambda expression in joinThread multiple lines, so that
one can set a breakpoint in it.
2018-10-16 23:06:05 +03:00
Tor Lillqvist
c617a8c73f Improve a comment 2018-10-16 23:05:59 +03:00
Tor Lillqvist
223cc97175 Log each line separately in fakeSocketDumpState() instead of with embedded newlines 2018-10-16 23:04:24 +03:00
Tor Lillqvist
cab2f9b6bb Add fakeSocketDumpState() 2018-10-16 01:11:20 +03:00
Miklos Vajna
116510296e net: unnecessary value parameter in Socket 2018-10-15 09:31:03 +02:00
Tor Lillqvist
e907d0ee01 Switch to using just one mutex in FakeSocket.cpp for now
Makes things simpler and easier to follow, I hope. I had hoped it
would also make the occasional hang I see when loading the document go
away, but nope. Possibly it isn't caused by FakeSocket after all, even
if FakeSocket is the obvious first suspect.
2018-10-10 10:31:07 +03:00
Tor Lillqvist
be945ed51b Bin duplicate const variable 2018-10-10 10:31:07 +03:00
Andras Timar
3c005f952a fix that internal port 9981 was opened on all interfaces
Change-Id: I04cd12b7fa2f0be9b08a3d325f08b36ca2ce240e
Reviewed-on: https://gerrit.libreoffice.org/61296
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
2018-10-05 16:38:03 +02:00
Tor Lillqvist
06051c833b Comment out log.dump() call again
Change-Id: I27ecd6712e72182f3a943e7be86ef5ba7b05f746
2018-09-20 13:38:53 +03:00
Tor Lillqvist
f4ce5df7e1 Implement the timeout parameter to fakeSocketPoll()
Adapt callers that mistakenly passed 0 assuming it meant "forever".

This also seems to help with the occasional hangs.
2018-09-19 20:03:24 +03:00
Tor Lillqvist
5ee96e0271 Small correction to poll semantics 2018-09-19 20:03:24 +03:00
Tor Lillqvist
8b5246b038 Bin one presumably pointless lock and unlock 2018-09-19 20:03:24 +03:00
Tor Lillqvist
9c57ffd3b3 Avoid potential deadlock 2018-09-19 17:55:14 +03:00
Tor Lillqvist
95eb849217 Still more iOS app and related Online C++ code hacking
Re-think the plumbing between the different parts of the C++ Online
code. Do try to have it work more like in real Online on all but the
lowest socket level. Except that we don't have multiple processes, but
threads inside the same process. And instead of using actual system
sockets for WebSocket traffic between the threads, we use our own
FakeSocket things, with no WebSocket framing of messages.

Reduce the amount of #ifdef MOBILEAPP a bit also by compiling in the
UnitFoo things. Hardcode that so that no unit testing is ever
attempted, though. We don't try to dlopen any library.

Corresponding changes in the app Objective-C code. Plus fixes and
functionality improvements.

Now it gets so far that the JavaScript code thinks it has the document
tiles presented, and doesn't crash. But it hangs occasionally. And all
tiles show up blank.

Anyway, progress.

Change-Id: I769497c9a46ddb74984bc7af36d132b7b43895d4
2018-09-19 11:31:18 +03:00
Tor Lillqvist
a4f19ac229 Avoid double "0x" prefix for pointer values in log output
No need for explicit "0x" and std::hex when outputting a pointer. A
pointer will be output as a hex number anyway. We used to have things
like this in the log:

TRC  #25 Connected to WS Handler 0x0x3610b60| ./net/WebSocketHandler.hpp:80
2018-09-19 10:33:41 +03:00
Tor Lillqvist
763a27280a Add possiblity to force logging to stderr with environment variable
At least LOOLWSD.cpp has a couple of global variables of types that in
their constructors invoke FakeSocket APIs. If we turn on FakeSocket
logging (fakeSocketSetLoggingCallback()) only in the app's
initialization code, we will miss logging from those global variable
constructors.

Sure, the clean solution would be to turn those global variables into
members in the LOOLWSD class instead, but this will do for now.
2018-09-18 15:31:01 +03:00
Tor Lillqvist
c09dfda052 In the logging always precede FakeSocket "fd" numbers with #
Makes it easier to search log files.

Also, Online uses this convention for socket fds in many places (not
sure if consistently).
2018-09-18 13:04:16 +03:00
Tor Lillqvist
435718e9f3 Improve shutdown semantics 2018-09-18 13:04:11 +03:00
Tor Lillqvist
53416a290d Add fakeSocketShutdown() and drop fakeSocketFeed()
Not sure whether the shutdown() implementation matches real shutdown()
semantics, especially with regards to the behaviour of poll(), read(),
and write() (on both the socket itself and the connectd one)
afterwards. But let's see.

The feed() API turned out to be not needed. (And in any case, it was
suposed to be completely equivalent to writing to the peer socket.)
2018-09-17 20:44:18 +03:00
Tor Lillqvist
7fd28d5676 Revert part of my iOS related commit, causes compilation warning with Clang
Won't actually be needed anyway, the way the code is going in my work
tree.

Change-Id: I4480ed59fe96ddcfad8483517f2a23452606f332
Reviewed-on: https://gerrit.libreoffice.org/60576
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
2018-09-17 12:51:07 +02:00
Tor Lillqvist
3bcde388ed FakeSocket poll fix and minor hacking
fakeSocketPoll() needs to return a correct return value.

Use notify_all() instead of notify_one(). Just to see if it makes any
difference.
2018-09-16 22:39:44 +03:00
Tor Lillqvist
7399a86f6a Use optional logging callback in FakeSocket.cpp instead of hardcoded writes
It's easier to either call the function to set the logging callback,
or not, in one place in client code, than to comment in and out all
the logging lines in FakeSocket.cpp as needed.

Change-Id: Id17f7e461c7df817440b47cb3124fcece13b189b
2018-09-16 13:39:43 +03:00
Tor Lillqvist
30ec64566b Attempt to fix various FakeSocket problems
Also add a bit of internals documentation.
2018-09-16 10:42:01 +03:00
Tor Lillqvist
0a2868b8d4 More FakeSocket hacking
As we use #ifdefs at all call sites anyway (because we don't dare use
the generic overrides of close() etc), we can leave out the parameters
related to actual BSD sockets that we ignore anyway.

"Real" Online always uses non-blocking sockets. We don't need to take
flags for that or check it. We can hardcode such behaviour always.
(Assuing that is what we want; let's see once something works.)

Change-Id: I6863907d71c5599b00ce1f8305a44d41bbaf7bee
2018-09-15 12:35:23 +03:00
Tor Lillqvist
55a2f804a6 Change the FakeSocket to be record-oriented
That is how Online uses the sockets for communication between the
processes anyway: It send and receives complete WebSocket frames.
Sure, in the mobile case there is just one process, but (I think) we
want to keep the same basic structure anyway, even if "wsd" and "kit"
are just threads. (We probably also want to drop the WebSocket framing
of the messages.)

Change-Id: I2397f321029c1cbbbc448a9b2403ad185a51cf14
2018-09-15 12:34:29 +03:00
Tor Lillqvist
6d81ebcfeb Add FakeSocket
Intended as a replacement for the real sockets used for WebSocket IPC
in Online on Linux. The idea is that in a mobile app we don't want to
bother with any actual sockets or WebSocket protocol (because we are
running as a single process after all), but keep much of the code that
thinks it is using such mostly unmodified. Just an idea so far, let's
see how this turns out.

Change-Id: I7878b0db99d9cbf70650227186c1fec9677fa74b
2018-09-15 12:30:50 +03:00
Tor Lillqvist
4841ee4f47 Move SocketPoll::pollingThreadEntry() implementation to cpp file
Makes it easier to put a breakpoint in it in Xcode...

Not sure if we have any consistent convention around here anyway about
which member functions should be defined inline in the class
definition in the hpp file, and which ones should be in the cpp file.
2018-09-13 09:33:40 +03:00