network: Handle EINTR

When a recv() or send() operation is interrupted by a signal make sure to
retry the operation. Otherwise we'll get communication issues from which we
wont be able to recover.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
iio_readdev: Don't access IIO API in signal handler

Accessing the IIO API from a signal handler is not safe and e.g. when using
the network backend can result in deadlocks or communication failures.  So
instead of cleaning up from within the signal handler add a variable that
says whether the application should be running or not and set it to false
from the signal handler. The main loop will then quit once it sees it being
false.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
iio_readdev: Use fflush instead of unbuffered output

Using a unbuffered output for stdout will generate one write() system call
per received sample. This adds a huge amount of overhead. Instead make it
buffered and call fflush() after each block that has been received. This
means, depending on the size of the block, there will typically only one
system call per block.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
iio_readdev: Make buffer size configurable

The buffer size is a trade of between latency and management overhead. A
larger buffer will have less management overhead but a higher latency. So it
makes sense to make this configurable so it can be set depending on the
requirements.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
iio_readdev: Allow to specify the number of samples to capture

Currently iio_readdev will capture samples until it is stopped. This patch
adds a option that allows to specify the number of samples that should be
capture. Once the specified number of samples has been captured iio_readdev
will stop automatically.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>