Local backend: Disable buffer mode before opening the IIO device

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Local backend: Verify that the file handler is valid before closing it

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Network backend: Added backend functions network_open / network_close

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Network backend: Update the network_read function to handle masks

Channel masks are now sent by the IIO Daemon when the READBUF
command is used.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Read the data format of the channels on context creation

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Reorder channels on context creation according to their index

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Added API function iio_channel_get_data_format

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Network backend: Save the initial mask in the device's pdata struct

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Added API function iio_device_get_sample_size

This function can be used to retrieve the sample size of a given
channel mask.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Fix mutex not unlocked in close_dev_helper

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Change prototype of command READBUF

Previously, the command was
READBUF <device> <nb_samples> <sample_size>

Now, the command is
READBUF <device> <nb_bytes>

This change is required, as the sample size depends of the channel
mask, which itself can change at every moment; thus the sample
size cannot be fixed.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Added missing include in iio.h

<sys/types.h> is required to use the "ssize_t" data type.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Cache the number of words of the mask in the DevEntry structure

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Update the sample size when the mask is modified

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Re-allocate the read buffer only when the mask changes

When the mask does not change, the sample size stays the same, and
so it is possible to reuse the previous buffer.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: prevent un-necessary mutex locking / unlocking operations

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
IIOD: Don't exit on read error, and read by multiples of sample size

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