IIOD: Fixed two races

The first race was happening when a call to read_buffer was made
just a tiny bit after the read thread entered its shutdown phase;
in this case, iio_device_open() was sometimes called before
iio_device_close(), which returned an error.

The second race was happening when the read thread was signaling
back the waiting threads; those would instantly free the ThdEntry
structure, which was still needed in the read thread (to obtain the
address of the next element).

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Fix thread list mutex not initialized + added more debug

This caused random crashes, as the mutex was sometimes reported
as locked, sometimes as unlocked.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
tests: Accept -x and -n arguments to select the backend

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
tests: Added a 'iio_readdev' test

This test program uses the libiio library to read the raw stream
from a device, and output it on its standard output.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Network backend: Added backend function network_read

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Don't exit when a client socket is closed

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