Ashod Nakashian
8b9623010a
wsd: sendHttpResponse -> send
...
Change-Id: I7c94f6d4cd1054ea86585bfcd4079140471f3518
Reviewed-on: https://gerrit.libreoffice.org/35157
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-14 04:30:55 +00:00
Michael Meeks
bf8068de18
Clarify comment a little.
2017-03-13 13:42:05 +00:00
Andras Timar
07c0452ec1
fix error: unused parameter 'hard' [-Werror=unused-parameter]
...
Change-Id: Ie2f2a12cc2f5d6c2fd3319d3c870cc7f0a226fae
2017-03-13 13:22:56 +01:00
Michael Meeks
97e9463f17
Revert "wsd: TerminatingPoll always starts its own thread"
...
This reverts commit 388d7b1dbf
.
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.
2017-03-13 12:13:22 +00:00
Ashod Nakashian
94051f21b5
wsd: SocketPoll::startThread can be protected
...
Change-Id: Idd17f7314ac181e9a412e05a1287e15edf5047d2
Reviewed-on: https://gerrit.libreoffice.org/35125
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:25:20 +00:00
Ashod Nakashian
c4d27fd060
wsd: prevent and warn when joining own thread
...
Change-Id: I8405a1aacb1281e52bbd07d32cdcf35bdc484d8b
Reviewed-on: https://gerrit.libreoffice.org/35124
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:25:04 +00:00
Ashod Nakashian
862d7a0734
wsd: write as many messages to socket as possible
...
Change-Id: Ie2702ea68dd1ae6200fcc304224dea34fc94544f
Reviewed-on: https://gerrit.libreoffice.org/35123
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:24:37 +00:00
Ashod Nakashian
9248107702
wsd: SocketPoll reports thread isAlive and use in DocBroker
...
Now that DocumentBroker has SocketPoll thread,
it's isAlive() must be defined by the lifetime of
both the SocketPoll thread and the ChildProcess,
which it previously did.
Change-Id: I093f8774cf4374d01729a383f6c535de4143fec6
Reviewed-on: https://gerrit.libreoffice.org/35122
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:23:18 +00:00
Ashod Nakashian
c9a07a3087
wsd: assert socket is in correct thread
...
Change-Id: I22c3f62bdf45188641326774dd86b7cacfce9198
Reviewed-on: https://gerrit.libreoffice.org/35120
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:20:41 +00:00
Ashod Nakashian
04bbb75200
wsd: dump state to generic ostream for flexiblity and to log
...
Change-Id: I4670ee2e90b7809ebc66a2b324a44334b3dbba2b
Reviewed-on: https://gerrit.libreoffice.org/35119
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:19:58 +00:00
Ashod Nakashian
2e2f62edde
wsd: improved logging
...
Change-Id: I6c4a5bcd54c0748cc413afbfcfb34c365b347669
Reviewed-on: https://gerrit.libreoffice.org/35118
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:11:24 +00:00
Ashod Nakashian
6f11918661
wsd: more informative SSL error logging
...
Change-Id: I32baadf995f6fc4c9b112d1a62fee2d618fc9e95
Reviewed-on: https://gerrit.libreoffice.org/35116
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:10:03 +00:00
Michael Meeks
5763d8d9bb
Improve debugging.
2017-03-10 23:28:34 +00:00
Michael Meeks
a9d5801c37
Unwind releaseSocket complexity.
...
We only move sockets in response to input on the socket, which
must happen in the thread that we're processing that input on.
Ergo - no need for this complexity.
2017-03-10 18:46:31 +00:00
Michael Meeks
027b8110ed
Allow isCorrectThread asserts to be hard, or off by default.
2017-03-10 18:46:16 +00:00
Michael Meeks
c30fb670d8
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.
2017-03-10 18:20:51 +00:00
Michael Meeks
160446fd23
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.
2017-03-10 17:58:51 +00:00
Michael Meeks
1065441e7c
Don't autosave if we're being stopped and happened to be overdue.
2017-03-10 16:42:59 +00:00
Michael Meeks
173ca5e3d6
Quote ETag.
2017-03-10 16:42:48 +00:00
Michael Meeks
7a90430f85
Cleanup logging on single packet websocket messages more cleanly.
2017-03-10 14:49:19 +00:00
Michael Meeks
11f3a29cb2
WebSocket - several messages can appear in a single packet.
2017-03-10 14:36:21 +00:00
Michael Meeks
34d9d52207
Avoid assert failure and zero size socket buffer in product build.
2017-03-10 12:12:10 +00:00
Michael Meeks
f4f083e6fe
Cache JS etc. on the client side for 128 days.
2017-03-10 11:36:10 +00:00
Michael Meeks
a5a227e9a3
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.
2017-03-10 10:55:29 +00:00
Miklos Vajna
2f07eb9a7d
Fix remaining -Werror,-Winconsistent-missing-override warnings
...
The last ones introduced by the non-blocking merge.
Change-Id: I0b9264428669cdd2b8f6eac911c336c6b0e8de99
2017-03-10 11:11:58 +01:00
Miklos Vajna
400c580800
net: fix -Werror,-Wconstant-conversion
...
Change-Id: If2bbad6d3909c7d6df9eed5edf260609d64db3a8
2017-03-10 11:06:43 +01:00
Miklos Vajna
33cbe908c5
net: fix -Werror,-Winconsistent-missing-override
...
Change-Id: Ia8c1f0233e0b65f5fae01272b4f31638aceac9ee
2017-03-10 10:54:08 +01:00
Ashod Nakashian
2d621f1a47
nb: logging
...
Change-Id: Ic3b724d5869f75234af2238b96a90c4745155b86
2017-03-10 10:47:44 +01:00
Ashod Nakashian
1da9bc3d69
nb: set the polling thread name for better logging
...
Change-Id: Iccc4337827f00af08327a4430f3d40fa69ac71b2
2017-03-10 10:47:44 +01:00
Michael Meeks
3bfc8aa7f3
Use larger socket buffers for serving files to improve efficiency.
...
The combination of nodelay + minimum buffers is horrific for
file-serving; speedup is from 3.3s to 33ms to serve bundle.js.
2017-03-10 10:47:44 +01:00
Michael Meeks
42a19e66e3
Centralize idle poll time.
2017-03-10 10:47:44 +01:00
Michael Meeks
438630c68f
Start DocBroker thread later - when we've added our 1st session.
2017-03-10 10:47:44 +01:00
Michael Meeks
e16fc97c15
SocketPoll - better control starting our threads.
...
Extraordinary trace with a thread starting before the SocketPoll's
derived classes had started - ie. with wrong vtables etc.
2017-03-10 10:47:44 +01:00
Michael Meeks
842b261d9f
Move auto-save of document into the DocumentBroker poll more convincingly.
2017-03-10 10:47:44 +01:00
Jan Holesovsky
4eccd4d7b4
nb: Check threads only when LOOL_CHECK_THREADS is set.
...
Change-Id: I4137685eb956469d419bded318b83de2b10ce19d
2017-03-10 10:47:44 +01:00
Jan Holesovsky
b895393cea
nb: Perform the socket shutdown asynchronously after the data is served.
...
Change-Id: I642e26abf4ef9c8d2be1be428b5786692dfea2c7
2017-03-10 10:47:44 +01:00
Ashod Nakashian
b8af470918
nb: serve files synchronously
...
As there isn't support (yet) to send files
asynchronously, when the socket native buffer
is small, asynchronous writes naturally return
EWOULDBLOCK. As a temp solution, we send files
synchronously, so there is no need to poll.
This should be replaced witha file-server
polling/serving thread that is dedicated to
sending files only (which closes the connection
when done).
Change-Id: I062fea44bfe54ab8d147b745da97bd499bf00657
2017-03-10 10:47:44 +01:00
Michael Meeks
37de43bb58
Tie sockets to threads, and assert that we're being used in the right one.
...
This shows up some problems around cleaning up prisoners etc. that will
need fixing subsequently.
2017-03-10 10:47:43 +01:00
Michael Meeks
0eaef6c896
config.h - get includes right: must always be the first include.
2017-03-10 10:47:43 +01:00
Ashod Nakashian
7b1ed1b4d4
nb: more informative logging of socket activity
...
Change-Id: I9036c778c195936678c6451ba57cc794d6ba0006
2017-03-10 10:47:43 +01:00
Ashod Nakashian
221bfdefc8
nb: get the poll sockets size after setting up
...
Change-Id: I35174f2f9345286791ccefe2d6dc521a767b6571
2017-03-10 10:47:43 +01:00
Ashod Nakashian
aee954af8b
nb: include the SocketPoll name in logs
...
Change-Id: I7a93edfe0bc74e62bd2726f6fa8425c719326023
2017-03-10 10:47:43 +01:00
Michael Meeks
ce4bd9b9be
Unify DocumentBroker thread and its SocketPoll.
2017-03-10 10:47:43 +01:00
Michael Meeks
79fb1e2c1f
Sub-class the SocketPoll to allow more flexibility in termination.
2017-03-10 10:47:43 +01:00
Ashod Nakashian
c6dbce9767
nb: transfer client sockets to respective DocumentBroker
...
Change-Id: I6af656ec6cbb09d4dd80b7b583a009a763de6eb9
2017-03-10 10:47:43 +01:00
Ashod Nakashian
76e96c92c8
nb: SocketPoll is now a thread object
...
Change-Id: I01d13292f0b97a9ebd1ccdef9e41fec46bfa0b11
2017-03-10 10:47:43 +01:00
Michael Meeks
20f15d4001
Switch Prisoner socket handling to use the SocketPoll.
...
Kills the Poco ThreadPool usage, and significantly improves debuggability.
2017-03-10 10:47:43 +01:00
Michael Meeks
a856a95138
Dump buffer contents as hex if we have them.
2017-03-10 10:47:42 +01:00
Michael Meeks
d4cc2e899c
ClientSession: kill the writing thread.
2017-03-10 10:47:42 +01:00
Michael Meeks
6711701721
Socket API to allow asynchronous writing.
2017-03-10 10:47:42 +01:00
Michael Meeks
1655e5d062
Improve socket state dumping on USR1.
2017-03-10 10:47:42 +01:00
Ashod Nakashian
d68377748d
nb: ReadOrWrite -> Neither
...
SSL only requests what to poll for next.
So it's more accurate to rename ReadOrWrite
to Neither, since in that case SSL really
isn't blocked on either read or write.
Change-Id: I62dd4f94730d51666a7661b10a9d582d69fbf45e
2017-03-10 10:47:42 +01:00
Ashod Nakashian
9c0d8cc5b2
nb: log more socket activity
...
Change-Id: Ibcdf5abc3054691c93382c00bb8a9ecc4b882652
2017-03-10 10:47:42 +01:00
Michael Meeks
fa96673ee0
Connect USR1 to initial global state dumping goodness.
2017-03-10 10:47:42 +01:00
Michael Meeks
fffd970425
Work around global initialization order issue with global wakeups.
2017-03-10 10:47:42 +01:00
Michael Meeks
fa6b756346
signal handling: keep track of all socket poll wakeups & wakeup.
...
Instead of waiting for polls to timeout; wake them up.
2017-03-10 10:47:42 +01:00
Jan Holesovsky
17d8b645b4
nb: It seems uppercase 'S' is preferred in Sec-WebSocket-Accept.
...
Change-Id: I6cc86f26cf7e3c9370e5d534877bfeeb6607f5a4
2017-03-10 10:47:42 +01:00
Jan Holesovsky
62afe66df0
nb: Make the loolnb / clientnb work again.
...
The more testing the better :-)
Change-Id: Ibe4249f18109d50b06e1fa35e6d0fef67f9b3643
2017-03-10 10:47:42 +01:00
Ashod Nakashian
8040dc0746
nb: disable hex dumping
...
No longer necessary to have them enabled
permanently, especially that they affect
performance significantly negatively.
Change-Id: I02ef99da00ba4ecb8e24647ee372a03d79d07fe7
2017-03-10 10:47:42 +01:00
Jan Holesovsky
653df9dcce
nb: No need for the WebSocketSender I think.
...
Change-Id: I133bb8341a846d70f95e0c70274541b5db62f65d
2017-03-10 10:47:42 +01:00
Jan Holesovsky
759895a8d7
nb: This file is not needed any more.
...
Change-Id: Ic73ddcc61495889fd36eb6f23f41c1bd45eb85c6
2017-03-10 10:47:42 +01:00
Jan Holesovsky
be743c115d
nb: When we cannot send the file, we must respond with 404.
...
Change-Id: I5f11e7de4b0bfb6e44929b8317e4788d2cc81610
2017-03-10 10:47:41 +01:00
Jan Holesovsky
67293c8183
nb: Fix the check in loolnb.
...
Change-Id: I54f23cb5fb76e4f9aab2743ddc2e6cda04a2656b
2017-03-10 10:47:41 +01:00
Ashod Nakashian
a68c33477d
nb: support inserting image
...
Change-Id: I6ef11634bbda7e3ecdc467ce10727c8573caef8d
2017-03-10 10:47:41 +01:00
Ashod Nakashian
b7e94d03ea
nb: websocket closing handshake
...
Change-Id: I45a6f2e680349fa2f77c20bb8f783093b9e1f212
2017-03-10 10:47:41 +01:00
Ashod Nakashian
4abf706af6
nb: websocket shutdown support
...
Change-Id: I2fcab98e9725eca86d097f34236889fdf9289c47
2017-03-10 10:47:41 +01:00
Ashod Nakashian
27452ec98c
nb: support WS shutdown
...
Change-Id: I08084abb25e494384235260dd1df83adc5e3a624
2017-03-10 10:47:41 +01:00
Ashod Nakashian
f9197ff020
nb: separate sendMessage and sendFrame
...
There are other types of frames than application
data.
Also a message can be composed of multiple frames.
Change-Id: Ia97349553b61ae05fa78854222808eaa43386c0e
2017-03-10 10:47:41 +01:00
Ashod Nakashian
17fc91e220
nb: process POST requests
...
These are really GET requests that aren't
WebSocket upgrade. Should rename to something
less misleading.
Re-enabled testSlideShow which depended on this.
Change-Id: I52b7f67b650fcdcbae7c2bff020b756099263141
2017-03-10 10:47:41 +01:00
Ashod Nakashian
9d72496038
nb: prefix large WS with nextmessage
...
Change-Id: Ie6583c93ada9cff8aa50137431b5c2c5f7b39d97
2017-03-10 10:47:41 +01:00
Ashod Nakashian
0c19d81fee
nb: read the socket on accept
...
It's necessary to do the SSL handshake
and to get the request (if we get there)
on accepting so by the time we poll we know
what SSL needs to do next. No reason to
read on first poll when we should be
expecting a request upon connection anyway.
Change-Id: I8eecaad5f8450075d45e487702972418cad125bc
2017-03-10 10:47:41 +01:00
Ashod Nakashian
72669bf929
nb: logging
...
Change-Id: Ia67f746a6c71b4753d04b92472eddf1614c0d337
2017-03-10 10:47:41 +01:00
Michael Meeks
aa0a85c16d
Add debug, and set the 'fin' bit on messages as we send them.
2017-03-10 10:47:41 +01:00
Ashod Nakashian
df45db9da2
nb: shutdown socket after file-serving
...
Change-Id: Ibe0b33f371d46e62637f570265fcdf9c8bf60b2d
2017-03-10 10:47:41 +01:00
Ashod Nakashian
2f2ba870b3
nb: handle socket poll exceptions and remove socket
...
Change-Id: Ibdee316f102d6606c38470e5ccacd2a7bd7ea7ce
2017-03-10 10:47:41 +01:00
Ashod Nakashian
784dd41eae
nb: simplify WS sendMessage interface
...
No need to construct vector<char> where
a simple char*/size_t suffice.
Change-Id: Ic70ad65a2078a1f653695504a79532f7831d88be
2017-03-10 10:47:40 +01:00
Ashod Nakashian
de92b1627e
nb: send files over HTTP
...
Change-Id: I346e97cd19a8dbbdee493d23b89c390ea6e3c948
2017-03-10 10:47:40 +01:00
Ashod Nakashian
0d9bbac18c
nb: serve wopi discovery XML
...
Change-Id: I7bb4910f948e8b4e89f3bbdf2a62a8b1540eef2f
2017-03-10 10:47:40 +01:00
Ashod Nakashian
9bf8720d2b
nb: SSL socket support in wsd
...
Change-Id: I21e8b2d04caf7da872fe07b4950b02a8c52a3552
2017-03-10 10:47:40 +01:00
Ashod Nakashian
d488efd3b7
nb: move openssl-specific struct to avoid conflicts
...
Change-Id: I4cf4ceb5b9ae1748f5087d4884dc40c280f5a00c
2017-03-10 10:47:40 +01:00
Ashod Nakashian
e184a371a0
nb: write socket buffer to socket safely
...
Since a socket client can push data into
the socket in a different thread than the one
polling (indeed that's the only possible scenario),
the write buffer must be protected by a lock.
On the other hand, the read buffer is always
invoked from a single thread, the polling. So
it is perfectly safe without locks.
Change-Id: Id0b6a01f8e96124a299810f0aacab9cecd1ff979
2017-03-10 10:47:40 +01:00
Ashod Nakashian
c2444bba9e
nb: more informative WebSocket message logging
...
Change-Id: I3229a98dcefc115fe1b730b57fcac71aeb868aad
2017-03-10 10:47:40 +01:00
Ashod Nakashian
fdc658845d
nb: always call onDisconnected when socket is closed
...
Change-Id: Ib42354fd1e8c68e78c6e5c501802a0e145b39260
2017-03-10 10:47:40 +01:00
Ashod Nakashian
2b4e7bd067
nb: SocketHandlerInterface must hold weak_ptr to Socket
...
Because the socket can be freed while a separate
thread is sending data via the handler, we must
have a locked reference to the socket instance
in the handler.
Change-Id: Iefad3fc2b147f96b8d538d9edd7cac3fce25b5bf
2017-03-10 10:47:40 +01:00
Ashod Nakashian
3b68944226
nb: socket logging
...
Change-Id: I1ee80eea39b7e910acf4ef0d12ea8aa436937041
2017-03-10 10:47:40 +01:00
Ashod Nakashian
576bd3ab4d
nb: write WS frame to socket
...
We need to flush writes to socket as soon as
ready to either send or, if buffers are full,
to poll for write.
With WebSocket we do this after writing a frame.
Change-Id: I1bc276e678375a84079e69624414a16271f25351
2017-03-10 10:47:40 +01:00
Ashod Nakashian
9efb14def7
nb: pass the WS frame type explicitly
...
Change-Id: Iaf4d832af4313b629701c7f07832dcaaf3e53c20
2017-03-10 10:47:40 +01:00
Ashod Nakashian
32b7d5ceee
nb: WebSocketSender used to send back loading progress
...
Change-Id: I3b09c44c4d64db39217d364ebff0a647a82457f4
2017-03-10 10:47:40 +01:00
Ashod Nakashian
5b944cf99b
nb: don't own your owner
...
Change-Id: Ia74dbd3441b8b1f682091ba3d973dd33b2599309
2017-03-10 10:47:40 +01:00
Ashod Nakashian
221059cd6b
nb: move WebSocket upgrade to the ClientRequestDispatcher
...
Change-Id: Id11b139563a55e50d3f7e216e2231d79e07015b3
2017-03-10 10:47:40 +01:00
Ashod Nakashian
73f9001004
nb: remove HTTP handling from WebSocketHandler
...
WebSocketHandler now supports upgrading given
the original HTTP header.
Change-Id: Ifb3b8fee9aef8015548a625bbb88e75f4e97255f
2017-03-10 10:47:40 +01:00
Ashod Nakashian
7fdb7a1861
nb: StreamSocket takes ownership of SocketHandler instance
...
Change-Id: Ica99dc8afbcca71c8d79eecb276ba19f6f01fa57
2017-03-10 10:47:39 +01:00
Ashod Nakashian
5e79581952
nb: StreamSocket must always have a handler
...
And also emits disonnection event.
Change-Id: Ibb60c6fca55c58b886f5ff77c6e22769a128e950
2017-03-10 10:47:39 +01:00
Ashod Nakashian
d9d6bfdb80
nb: new ClientRequestDispatcher added
...
Requests need to be introspected and
dispatched to the appropriate handler.
File serving, admin, POST request, etc.
are all valid types that we need to support.
But of course the primary one is the WS request
to load to and interact with a document.
Change-Id: Id2c3214deb6b54b06b2735ec3370f09ed7a1ae51
2017-03-10 10:47:39 +01:00
Ashod Nakashian
2e651f4199
nb: cout -> logger
...
Change-Id: I44c6d83efc7aef50cb793fc6e88da32e73797c74
2017-03-10 10:47:39 +01:00
Michael Meeks
37e9b25882
Add thread-safe cross-thread callbacks, split out wakeup and simplify
2017-03-10 10:47:39 +01:00
Michael Meeks
2a5823557e
Add initial support for socket timeouts.
2017-03-10 10:47:39 +01:00
Michael Meeks
3e9f05d071
Use pseudo-random-ness in test to make strace cleaner.
2017-03-10 10:47:39 +01:00
Michael Meeks
5b7e12c16e
Cleanup logging, and add message tracing / dumper.
2017-03-10 10:47:39 +01:00
Jan Holesovsky
205a1453d3
nb: Moved the WebSocketHandler to an own header & cpp.
...
The cpp is there to keep the header free from the POCO dependency.
Change-Id: I2202c4ed403084ec1ed40001e10b1ec4fc226f7b
2017-03-10 10:47:39 +01:00
Jan Holesovsky
a2d457d778
nb: Abstract WebSocketHandler.
...
We don't need a special "WebSocket" class, as websocket itself is just an
upgrade of an existing socket / connection, and trying to come up with a
concept where a Socket class magically upgrades to a WebSocket class would be
messy.
So let's have just a WebSocketHandler, that communicates over a StreamSocket
or SslStreamSocket, and be done with that :-)
Change-Id: I449e4d662fbe2c5b1789e308053e4a71376fe481
2017-03-10 10:47:39 +01:00
Jan Holesovsky
18876119ad
nb: SimpleResponseClient is a client, not a socket I guess.
...
Introduce the appropriate interface instead of the template, so that we can
de-couple the ResponseClient from the Socket itself.
Change-Id: I21892bbce5d83a18ca580a25cfc2efbb05b08705
2017-03-10 10:47:39 +01:00
Jan Holesovsky
72666d5625
nb: Let's avoid too much abstraction.
...
Change-Id: If349e6273580b09386ad0a89467a99c6c2c0d4ec
2017-03-10 10:47:39 +01:00
Ashod Nakashian
69e4123173
nb: de-templatize ServerSocket
...
Change-Id: I5680bbf24ade807e34f67f7fce4698ffe5364cb2
2017-03-10 10:47:39 +01:00
Ashod Nakashian
9c595755ff
nb: move SslStreamSocket to own file
...
Change-Id: I4b6f2b0b4be3fc595dfeafc8e2b6d3e73694bd49
2017-03-10 10:47:39 +01:00
Ashod Nakashian
18b131f30d
nb: more consistent filenames
...
Change-Id: I2f1ff0b18080d469dc68b75ea0d7b9ddf5ea7d57
2017-03-10 10:47:39 +01:00
Ashod Nakashian
393071573b
nb: write while output buffer not empty
...
Change-Id: I257b72365b4711fd7ffc8bbda5a21d501828575b
2017-03-10 10:47:39 +01:00
Ashod Nakashian
cff706861f
nb: failing to drain the wakeup pipe is no error
...
Change-Id: Ie7a75f96b655cb7861d1bae539d78cbf702cf334
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fafd8a370e
nb: throw when we run out of resources
...
Change-Id: I12fd236bffd50dbf7a1bb9eb4c665ea9d9d545e4
2017-03-10 10:47:38 +01:00
Ashod Nakashian
ab82db72ee
nb: read to the end of the full buffer
...
Change-Id: I94264f748ac974f636ab6d21a5ccbb77532136f6
2017-03-10 10:47:38 +01:00
Ashod Nakashian
c37079fcee
nb: assert on trying to write empty data
...
Change-Id: Ie18b5d00acf769a112b47d45f8c7783fb5746acf
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b72dd13cb0
nb: fixme for HTTP handling
...
Change-Id: I4364e2e4cd3233134c026890ce690abaf46b961d
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fa97687485
nb: safer endianness conversion
...
Change-Id: I63977e6e99119fef2a61911d07d645a606d4c443
2017-03-10 10:47:38 +01:00
Michael Meeks
86185a2544
Restore plain HTTP, and add 'ssl' parameter to loolnb.
2017-03-10 10:47:38 +01:00
Ashod Nakashian
bb5f3b5c98
nb: properly shutdown and cleanup SSL
...
Change-Id: Idd39851775e16c62d6192e08c9058cd9fb40104f
Reviewed-on: https://gerrit.libreoffice.org/34454
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
a8f5923214
nb: cleanup some logging
...
Change-Id: I28e211e5a727ea308824651f417a91d7b388a30d
Reviewed-on: https://gerrit.libreoffice.org/34452
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
031ee124da
nb: use 16kb socket read buffer to match SSL
...
SSL's decryption frame is 16kb, so it
makes sense to read by that multiple
for efficiency reasons.
Change-Id: Ib5d7b5bfc18fa1b27bcbc9aac93350c4e1292874
Reviewed-on: https://gerrit.libreoffice.org/34451
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
1db8884f60
nb: support websocket payloads larger than 64kb
...
Change-Id: Ic21e11a70dae74b80ce3b1b604159ec14851972c
Reviewed-on: https://gerrit.libreoffice.org/34450
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
7a904d44bc
nb: http request is consumed completely
...
Change-Id: I3525840deaf3ec95b8e74634ac36f22072bdf476
Reviewed-on: https://gerrit.libreoffice.org/34449
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
7f41627d52
nb: improved poll handler
...
We now always read new data, because
SSL might need to process internal buffers,
and call the app message handler as long
as it keeps consuming data.
Finally, we write when we have data
to flush, even if we didn't get POLLOUT
event, because SSL might need to do
handshake, which is handled by the write
handler.
Change-Id: I909333c3a0492b0830044d51ae478ac5981b1d90
Reviewed-on: https://gerrit.libreoffice.org/34448
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
a0df079c9b
nb: flush all write data as long as we make progress
...
Change-Id: I138c54258eb54570e7a583bb62b1f4d26ef70ef1
Reviewed-on: https://gerrit.libreoffice.org/34447
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
11c7a213d6
nb: retry reading only when the buffer is full
...
We expect to have more data if the buffer was
filled completely. Otherwise, there is no
reason to suspect there is more data, unless
we hope to have received time in that short
interval, which is not very likely.
Change-Id: I9a3dcb6378e8dcfa0d49b6c7ea92d7cec6690787
Reviewed-on: https://gerrit.libreoffice.org/34446
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
eb76fc2d4f
nb: the last item in the read buffer is sentinel
...
Change-Id: I13d80a8d436c188dbfa558ddf8fbc7c1a3a6567e
Reviewed-on: https://gerrit.libreoffice.org/34444
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
6a46571455
nb: handle as many incoming messages as ready
...
Change-Id: I082f4a8b86b1f1827e4fba6927248bc6bd2cb1fa
Reviewed-on: https://gerrit.libreoffice.org/34443
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b6943b9c2a
nb: server socket should accept only on POLLIN
...
Change-Id: I50e9a7f78e51bbf7e42e3eafde6e32d6538f5657
Reviewed-on: https://gerrit.libreoffice.org/34442
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
fe5545d591
nb: websocket echo test
...
The new test sends data of of 1 byte to
N bytes and expects the exact same data
returned in response.
This tests both buffering sizes and
websocket frames.
Change-Id: Ic6232b4e899d82d90a0ee7c96e4852ffaaf8e958
Reviewed-on: https://gerrit.libreoffice.org/34441
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
f8efd03d99
nb: allow moving write buffer
...
SSL expects the write buffer to be the same on
retry. This requirement cannot be guaranteed
when using standard containers as the internal
memory might be re-allocated between calls.
Luckily SSL can relax this requirement when asked.
Change-Id: I26771609a8cc0f9de0e554f9fa255d998f6c7b14
Reviewed-on: https://gerrit.libreoffice.org/34440
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
b4ab8f2014
nb: unmask only to the payload end
...
Change-Id: I511db5fea51ff8c623ca894f9d512749ef9f5a1b
Reviewed-on: https://gerrit.libreoffice.org/34424
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
9d95eec642
nb: support 64kb websocket messages
...
Change-Id: Id42efabb67137c737899adbe544cb0d2de08422a
Reviewed-on: https://gerrit.libreoffice.org/34423
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
e2d5d446b1
nb: refactor and reuse ssl handshake handler
...
Change-Id: Ie65b7d1bac8391ccb2905fa8376a26ee4c3d4e30
Reviewed-on: https://gerrit.libreoffice.org/34416
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
25e00d8d75
nb: reuse buffered reading and writing in SSL too
...
Change-Id: I3f835bc9ae4ed6c093b87ac5a45c9dd6b41780f9
Reviewed-on: https://gerrit.libreoffice.org/34415
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
336c3340f4
nb: move more into BufferingSocket
...
Reduces code duplication and makes
buffer management easier.
Change-Id: I4f3bcf02b273d7ae23f4fd7600e66644ccec0d2a
Reviewed-on: https://gerrit.libreoffice.org/34414
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
22f365abbe
nb: move handleIncomingMessage to BufferingSocket
...
Change-Id: Iddcac9a9ca51f060e32b8f2600518e4a7cea98d2
Reviewed-on: https://gerrit.libreoffice.org/34413
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
bb2be404d2
nb: refactor getResponse into raw string and int versions
...
Change-Id: I77d8085cc811c7caf4434af823e62fd1333090f1
Reviewed-on: https://gerrit.libreoffice.org/34412
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:38 +01:00
Ashod Nakashian
31dd434136
nb: drain the read buffer before dispatching
...
Draining the buffer is the correct appraoch
to avoid accumulating data in the kernel
unnecessarily. But it also reduces the overhead
of reparsing the incoming data for message
boundaries.
The client that is to parse the data should
parse as many messages as possible and remove
them from the socket buffer.
Finally, we probably need to cap the maximum
buffer size to avoid bloating. However this
heavily depends on the application's max
message size, assuming there is no separate
buffer beyond that of the socket to accumulate
the messages in.
Change-Id: I49c4eccebd474cd07ca84f3f4eae33bc717ed1f2
Reviewed-on: https://gerrit.libreoffice.org/34411
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
d9f4903ec3
nb: cosmetics
...
Change-Id: I3a9f95c0b8edacff69b3c3733e833e3a82c545a9
Reviewed-on: https://gerrit.libreoffice.org/34410
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Michael Meeks
783cd72f1b
SSL - accept self-signed certificates for tests.
2017-03-10 10:47:37 +01:00
Michael Meeks
1f79a93476
Socket - set nodelay.
2017-03-10 10:47:37 +01:00
Ashod Nakashian
4fbc754b4e
nb: enable HTTPS in server
...
Change-Id: Ib0a4cb29f239bafe477ffab4194d3c91a588c384
2017-03-10 10:47:37 +01:00
Ashod Nakashian
9f0c1a4ec3
nb: support ssl handshake
...
Change-Id: I9974b1228cdc35a22ee784b734811720ddd2a311
2017-03-10 10:47:37 +01:00
Ashod Nakashian
e30998e47e
nb: support ssl in all client tests
...
Change-Id: Ie077212426a07817914abe796c1280ef2afe89be
2017-03-10 10:47:37 +01:00
Michael Meeks
bc8fca1ec0
WS: cleanup calculation, masking, short reads and other bits.
2017-03-10 10:47:37 +01:00
Ashod Nakashian
936b3e5736
nb: basic SSL socket implementation
...
Change-Id: Iaa2da47df17f14dfded44a8cf805020e8ef6b1ff
Reviewed-on: https://gerrit.libreoffice.org/34395
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
b439490a11
nb: support SSL in clientnb
...
Change-Id: Ia895558c7115a39824474ba7acff060102192c10
Reviewed-on: https://gerrit.libreoffice.org/34394
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
de10d8054c
nb: SimpleResponseClient can now be an SSL or plain socket
...
Depending on the base class, which is passed as
template parameter, SimpleResponseClient can
abstract away the underlying socket type.
Change-Id: I59a403357512f329aa2565c1ef55094704e3b4ad
Reviewed-on: https://gerrit.libreoffice.org/34393
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
ff75e8fda2
nb: server can create any socket type on accept
...
Change-Id: I1a786421628500844277e6a2f1d2fd7b0ac0c3e4
Reviewed-on: https://gerrit.libreoffice.org/34392
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
477be66577
nb: support http and https in parallel
...
Change-Id: I35f55abc853e8797625bef1b0f60eeda127681b4
Reviewed-on: https://gerrit.libreoffice.org/34391
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
d39f86c73b
nb: Enable partial writes and no retry
...
Change-Id: I75567754b81cc43190087bae4f848a0742201fe0
Reviewed-on: https://gerrit.libreoffice.org/34390
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
d86544d7fd
nb: create SSL socket
...
Change-Id: I2d5cc3441bcdb67b868557fefe93e2d0bd7770af
Reviewed-on: https://gerrit.libreoffice.org/34389
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
820f3c4e52
nb: no redundant visibility
...
Change-Id: I8ad303f534ca8c953e4bf42d252c38fb2561f505
Reviewed-on: https://gerrit.libreoffice.org/34388
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
6a2cb967dc
nb: use make_shared where possible
...
Change-Id: I7fb4e7086ac0ce86447db9de4c7ac77cdd7b40af
Reviewed-on: https://gerrit.libreoffice.org/34387
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
0e862301a4
nb: initialize the SSL Context
...
Change-Id: Id0ec4992a73a9b4de76b4efec8afa7c603e9cbb0
Reviewed-on: https://gerrit.libreoffice.org/34356
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
8dd115a419
nb: more SSL initialization
...
Multi-threading support.
Change-Id: I7233ca61f9a0dce5601b4de03a7ad3273acc0f3c
Reviewed-on: https://gerrit.libreoffice.org/34355
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
62c4828af6
nb: add OpenSSL dependency and initialization
...
Change-Id: I0d369acbc95db5d2b678032632ac4edfa561cbad
Reviewed-on: https://gerrit.libreoffice.org/34354
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
6a3242ce96
wsd: no tabs
...
Change-Id: I0537f7437328cb758e691d8e0ddc12d78da11f6a
Reviewed-on: https://gerrit.libreoffice.org/34353
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
1920481aca
nb: refactor buffer management into BufferingSocket
...
Now we have plain and ssl sockets based on
the BufferingSocket, each is responsible for
the socket IO only.
The SSL socket is only shell missing implementation.
Change-Id: I51d274a9335cec52c13b6a19927ddd46d98265a0
Reviewed-on: https://gerrit.libreoffice.org/34352
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
b5efc65cef
nb: ClientSocket -> StreamSocket
...
StreamSocket has nothing Client-side specific.
Indeed it could be used on the Server-side.
As such, it's data-streaming, rather than client,
hence the new name.
Change-Id: I4e048def968b3a12e11edb49760ed03e3843ae6b
Reviewed-on: https://gerrit.libreoffice.org/34351
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Ashod Nakashian
ae14786443
nb: retry on EINTR
...
Change-Id: Iea972096854308a80f96af056639417be7573a82
Reviewed-on: https://gerrit.libreoffice.org/34350
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:37 +01:00
Michael Meeks
3b0b31f5e2
WS: initial masking implementation & better parsing.
2017-03-10 10:47:37 +01:00
Michael Meeks
568569659b
WS - basic handshake / upgrade and start of read framing.
2017-03-10 10:47:37 +01:00
Michael Meeks
b16ead036f
More WS-ness.
2017-03-10 10:47:37 +01:00
Michael Meeks
d9ff82ce83
Websocket client test with WS=1
2017-03-10 10:47:37 +01:00
Michael Meeks
2f5d3e4412
Bang on the server with some threads.
2017-03-10 10:47:37 +01:00
Michael Meeks
23270347e5
Thread to poke server.
2017-03-10 10:47:36 +01:00
Michael Meeks
a06fb365cb
Get number response / ping bits working.
2017-03-10 10:47:36 +01:00
Michael Meeks
7a225dcbb3
Lean on Poco for request parsing.
2017-03-10 10:47:36 +01:00
Michael Meeks
d254899e74
Initial http header parsing pieces.
2017-03-10 10:47:36 +01:00
Michael Meeks
feb8192ec3
De-templatize and simplify.
2017-03-10 10:47:36 +01:00
Michael Meeks
0263078de7
Handle EOF - ie. zero length reads on sockets.
...
Close and cleanup sockets nicely.
2017-03-10 10:47:36 +01:00
Michael Meeks
92364f3ebf
Implement basic buffering.
...
The socket now buffers input, and output, updates its poll record too.
We pass a simple message from client to server and back using lamers HTTP.
Sub-classed ClientSocket to provide a simple message handler.
not very convinced by templatization here, but made it consistent.
more ideal to have some virtual socket pieces.
2017-03-10 10:47:36 +01:00
Michael Meeks
8f1ae36c8a
First cut at a Poco based client.
2017-03-10 10:47:36 +01:00
Michael Meeks
257a79da89
Cleanup comments, naming related warnings etc.
...
Avoid using 'poll' as a member function, and a local variable.
Avoid using 'fd' as a member function, and a parameter.
Add assertions around wake pipe.
Always setup sockets for polling, strobing events is expected.
2017-03-10 10:47:36 +01:00
Ashod Nakashian
0a05a34f66
nb: move Socket family into own file
...
Change-Id: I17802f00a6e9e7d920b175b9721b158ea90a9880
Reviewed-on: https://gerrit.libreoffice.org/34238
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
22b1ae9553
nb: separate Socket into ClientSocket and ServerSocket
...
Change-Id: I1aafd6192b955e51b8f1e74c1aad5fc3603f71d6
Reviewed-on: https://gerrit.libreoffice.org/34237
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
b6b36f454b
nb: refactor the client code into own function
...
Change-Id: I23735785cc4a66589fd81c7cb0f08476829ba7e8
Reviewed-on: https://gerrit.libreoffice.org/34236
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
f41968a726
nb: refactor server code into own function
...
Change-Id: Iba7363df7452da271fcf9afb54ad1f6177260ddd
Reviewed-on: https://gerrit.libreoffice.org/34235
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
10ab785fa4
nb: recreate the poll fds only when needed
...
Change-Id: I17accfb0339c590b7e155e8fd804e3e32c57e3ed
Reviewed-on: https://gerrit.libreoffice.org/34234
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
5ed0c601e3
nb: poll wakeup pipe and simplified polling
...
Change-Id: I2e688b985d4a9bf7cbe8eef5df10f67bfc96f91c
Reviewed-on: https://gerrit.libreoffice.org/34233
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-10 10:47:36 +01:00
Ashod Nakashian
a8b2f982b6
nb: support N clients and asynchronously communicate with all
...
Change-Id: I81f63895180141e554072b6cf5300139299f282c
2017-03-10 10:47:36 +01:00
Ashod Nakashian
0edb2f6679
nb: poll using multi-socket poll class SocketPoll
...
Change-Id: If244c4ec92f70fd458665b88d4da3c5fbcb11077
2017-03-10 10:47:36 +01:00
Ashod Nakashian
f086079d25
nb: SocketPoll class to poll events on N-Sockets
...
Internally SocketPoll manages the sockets
and handles the polling and firing of callback.
It's thread-safe and handles asynchronous calls
to remove sockets correctly while potentially
being in poll(2).
The choice for using poll(2) compared to epoll
or select are the following:
1. For our use-case, poll(2) works great up to
a few hundred sockets, which we don't expect
to have on a single document normally.
2. select(2) has an awkward API (modifies input,
f.e) and has limit on max fds that we need to
be mindful of (even if we'll not hit it in
practice). poll(2) preserves the input and has
a no-nonsense API that's simple and readable.
3. While select(2) is the most portable, poll(2)
isn't far behind. Yet in practice we'll probably
not support other systems than Linux.
4. epoll(2) starts to scale with hundreds or
thousands of sockets. Meanwhile, it has high
overhead to adding/removing sockets (context
switch to kernel and back). Our typical case
will have a handful to a dozen sockets.
Hardly a justification for epoll's heavy guns.
Change-Id: Idf88257ea85e061a37af29eed21e38655ff43c9b
2017-03-10 10:47:36 +01:00
Ashod Nakashian
e4563f7d42
nb: ping-pong messages between client and server
...
Change-Id: I3856dde09764075a138e8574520487e6e5accd90
2017-03-10 10:47:36 +01:00
Ashod Nakashian
85a398ad9c
nb: Socket connect supports waiting with timeout
...
Change-Id: Ib2d713d68f3a27067b121adb356188a164da4589
2017-03-10 10:47:36 +01:00
Ashod Nakashian
976381f633
nb: server now accepts asynchronously
...
Change-Id: Ic98f31d4f432fc8a06690b94899314b7c9106c69
2017-03-10 10:47:36 +01:00
Ashod Nakashian
d9c88322e2
nb: connect and read asynchronously
...
Change-Id: I04733f8dbf06f5f31e6b05e7f017ef75c629a015
2017-03-10 10:47:36 +01:00
Ashod Nakashian
3e6ceda91b
nb: add polling to Socket
...
Change-Id: Ie3fd1f271d9c6fa24e8583316e68a443489d1967
2017-03-10 10:47:36 +01:00
Ashod Nakashian
b772f8a860
nb: add socket error getter
...
Change-Id: Ia0dfd1d6e6bfd2b34b5a9b01c883d78f9bb15e7d
2017-03-10 10:47:36 +01:00
Ashod Nakashian
06990cb703
nb: Socket fd member is const
...
Change-Id: Icc7f4d9bbd15ce0feb3a58339771fbfd168e20e5
2017-03-10 10:47:36 +01:00
Ashod Nakashian
6a82f12d5f
nb: add recv and client connection
...
Change-Id: I311a475428ff410ca26f6049d5371943aa88cc59
2017-03-10 10:47:36 +01:00
Ashod Nakashian
2ebf4bdd58
nb: accept connections and send
...
Change-Id: Ie99b8c15e097fcaca0675aba11e11a11c2e7098f
2017-03-10 10:47:36 +01:00
Ashod Nakashian
1e2f7a9f65
nb: bind reuses address automatically
...
This is virtually always desirable, since
without it we may fail to bind after recycling
if the previous socket is TIME_WAIT.
However, if a socket is bound to same address
this will not prevent the failure to bind,
and we'll detect that the address/port is busy.
So the advantage is in minimizing recycling time.
Change-Id: Ib3bbbf7065f9822acfbd2d7f8ff3e8951739c0ef
2017-03-10 10:47:36 +01:00
Ashod Nakashian
21d6fbd948
nb: Socket doesn't throw on failures and better doc
...
Change-Id: I125c417c5d9e1a3f40ec386f4871bf6cf2c56ac8
2017-03-10 10:47:35 +01:00
Ashod Nakashian
3d2c2655cd
nb: Socket supports listen and accept
...
Change-Id: I210ee7843f9ff977fde719773b920f1c9c720598
2017-03-10 10:47:35 +01:00
Ashod Nakashian
bd92b09da5
nb: add Socket class
...
The new socket class is implicitly
non-blocking, streaming, ipv4 socket.
Ipv6 to be added later, as necessary.
Change-Id: I722cc63ea97394d47a50b733c58a69cc1529d815
2017-03-10 10:47:35 +01:00
Ashod Nakashian
41f58f4b4d
nb: add new loolnb program
...
Change-Id: Ib08ff3cdc037876e9c53b87603140b3c603ee916
2017-03-10 10:47:35 +01:00