Commit graph

19 commits

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