Commit graph

309 commits

Author SHA1 Message Date
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