IIOD: Only send the number of bytes the client asked for, not more

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Absorbe internal function into iio_buffer_foreach_sample

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Mark a client as active as soon as added to the client list

Before, the clients were only marked active at the beginning of the loop
in rw_thd, before refilling the buffer was refilled and demuxing the
data to the clients.

This was a problem when streaming to more than one client, because most
of the time one client would connect while the buffer is refilling, and
would only obtain data on the next iteration of the loop. As the clients
generally ask for a number of bytes that correspond to the buffer size,
they are only active for one iteration of the loop, and by the time a
new read command is issued, it's already too late to register for the
next iteration and get the following samples.

Now, the buffer is still refilled only if clients are already waiting,
but the clients who connected while the buffer was refilling will also
be served.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Refill the buffer when no clients, if we had clients just before

Then we don't wait for new clients to arrive if they are likely to
arrive; we just refill the buffer and chances are that by the time we're
done they will be connected.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>