tinyiio crashed when libiio refill was called on an empty tinyiio buffer.
My assumption with the READBUF or when a refill call from the host using libiio is if the circular buffer used to store samples with a trigger handler is empty or less than what was configured as buffer size in the host, it should just get an -EAGAIN. However, it crashed the tinyiio and looking at the code here, https://github.com/analogdevicesinc/no-OS/blob/05c0d208758c1d60fd7009a5356146f76276fa4f/iio/iiod.c#L832 the -EAGAIN propagated to the iio_app instead of passing it to the conn->res.
Catching the -EAGAIN and preventing it from propagating to the calling functions solved the issue of crashing. But, libiio now returns a timeout when refill was called when circular buffer in tinyiio was empty, which is fine since we can just call the refill function with a backoff timer from the application. Is there a way to safely refill when tinyiio buffer is empty?
To replicate:
- You need an iio driver with a trigger handler (without .submit/read_rev ops) that fills the circullar buffer with samples. Use a large delay for example 5000ms per trigger. Set the number of samples pushed to 2 per trigger.
- You can create a very simple pyadi-iio (or maybe use iio cli toos) to get the buffer contents every 1 second. Set the buffer size to 2.
- If the interrupt started ahead of your .rx() call in pyadi-iio, you will get data until the buffer is empty and it will crash after a few timeouts and READ INTEGER and READLINE errors.
Do you think you can replicate this issue using the timer_trigger_example of iio_demo (projects/iio_demo/src/examples/iio_timer_trigger_example/iio_timer_trigger_example.c) and iio_rwdev (iio_rwdev -u serial:/dev/ttyACM0,57600,8n1n -b 4 -s 4 -t adc_demo_timer_trig adc_demo | hexdump -C)?