Skip to content

Commit

Permalink
IIOD: Better handle errors of iio_buffer_{refill,push}
Browse files Browse the repository at this point in the history
Pass the error code to the connected clients, instead of disconnecting
them.

This means that for a very slow device, a connected client will simply
get a -ETIMEDOUT error when a configured timeout expires, and will still
be able to communicate with the server.

Fixes: #981.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jun 23, 2023
1 parent 41d14d4 commit ad199c6
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions iiod/ops.c
Expand Up @@ -678,9 +678,22 @@ static void rw_thd(struct thread_pool *pool, void *d)
}

if (ret < 0) {
IIO_ERROR("Reading from device failed: %i\n",
(int) ret);
break;
/* Reading from the device failed - signal the
* error to all connected clients. */

/* Don't use SLIST_FOREACH - see comment below */
for (thd = SLIST_FIRST(&entry->thdlist_head);
thd; thd = next_thd) {
next_thd = SLIST_NEXT(thd, dev_list_entry);

if (!thd->active || thd->is_writer)
continue;

signal_thread(thd, ret);
}

pthread_mutex_unlock(&entry->thdlist_lock);
continue;
}

nb_bytes = ret;
Expand Down Expand Up @@ -750,18 +763,18 @@ static void rw_thd(struct thread_pool *pool, void *d)
pthread_mutex_unlock(&entry->thdlist_lock);
continue;
}
if (ret < 0) {
IIO_ERROR("Writing to device failed: %i\n",
(int) ret);
break;
}

/* Signal threads which completed their RW command */
for (thd = SLIST_FIRST(&entry->thdlist_head);
thd; thd = next_thd) {
next_thd = SLIST_NEXT(thd, dev_list_entry);
if (thd->active && thd->is_writer &&
thd->nb < sample_size)

if (!thd->active || !thd->is_writer)
continue;

if (ret < 0)
signal_thread(thd, ret);
else if (thd->nb < sample_size)
signal_thread(thd, thd->nb);
}

Expand Down

0 comments on commit ad199c6

Please sign in to comment.