From abdd0723332fcaea00878c1bab2330ed572e5689 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Wed, 12 Feb 2020 10:54:06 -0500 Subject: [PATCH 1/2] Increase error reporting on iiod and network backend This was taken from Lar's old branch "stresstest" https://github.com/analogdevicesinc/libiio/commit/dc337057506507c35ab7185af810048eb2e69259 and adds a few more error output when things go wrong. Signed-off-by: Lars-Peter Clausen Signed-off-by: Robin Getz --- iiod-client.c | 23 ++++++++++++++++------- network.c | 27 +++++++++++++++++++-------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/iiod-client.c b/iiod-client.c index 1798cd653..aaea669ca 100644 --- a/iiod-client.c +++ b/iiod-client.c @@ -1,7 +1,7 @@ /* * libiio - Library for interfacing industrial I/O (IIO) devices * - * Copyright (C) 2014-2016 Analog Devices, Inc. + * Copyright (C) 2014-2020 Analog Devices, Inc. * Author: Paul Cercueil * * This library is free software; you can redistribute it and/or @@ -43,8 +43,10 @@ static ssize_t iiod_client_read_integer(struct iiod_client *client, do { ret = client->ops->read_line(client->pdata, desc, buf, sizeof(buf)); - if (ret < 0) + if (ret < 0) { + ERROR("READ LINE: %zu\n", ret); return ret; + } for (i = 0; i < (unsigned int) ret; i++) { if (buf[i] != '\n') { @@ -568,9 +570,10 @@ static int iiod_client_read_mask(struct iiod_client *client, return -ENOMEM; ret = iiod_client_read_all(client, desc, buf, words * 8 + 1); - if (ret < 0) + if (ret < 0) { + ERROR("READ ALL: %zu\n", ret); goto out_buf_free; - else + } else ret = 0; buf[words*8] = '\0'; @@ -606,15 +609,19 @@ ssize_t iiod_client_read_unlocked(struct iiod_client *client, void *desc, iio_device_get_id(dev), (unsigned long) len); ret = iiod_client_write_all(client, desc, buf, strlen(buf)); - if (ret < 0) + if (ret < 0) { + ERROR("WRITE ALL: %zu\n", ret); return ret; + } do { int to_read; ret = iiod_client_read_integer(client, desc, &to_read); - if (ret < 0) + if (ret < 0) { + ERROR("READ INTEGER: %zu\n", ret); return ret; + } if (to_read < 0) return (ssize_t) to_read; if (!to_read) @@ -622,8 +629,10 @@ ssize_t iiod_client_read_unlocked(struct iiod_client *client, void *desc, if (mask) { ret = iiod_client_read_mask(client, desc, mask, words); - if (ret < 0) + if (ret < 0) { + ERROR("READ ALL: %zu\n", ret); return ret; + } mask = NULL; /* We read the mask only once */ } diff --git a/network.c b/network.c index d1f746580..acd1e7615 100644 --- a/network.c +++ b/network.c @@ -1,7 +1,7 @@ /* * libiio - Library for interfacing industrial I/O (IIO) devices * - * Copyright (C) 2014-2015 Analog Devices, Inc. + * Copyright (C) 2014-2020 Analog Devices, Inc. * Author: Paul Cercueil * * This library is free software; you can redistribute it and/or @@ -735,8 +735,10 @@ static int network_open(const struct iio_device *dev, goto out_mutex_unlock; ret = create_socket(pdata->addrinfo, DEFAULT_TIMEOUT_MS); - if (ret < 0) + if (ret < 0) { + ERROR("Create socket: %d\n", ret); goto out_mutex_unlock; + } ppdata->io_ctx.fd = ret; ppdata->io_ctx.cancelled = false; @@ -745,8 +747,10 @@ static int network_open(const struct iio_device *dev, ret = iiod_client_open_unlocked(pdata->iiod_client, &ppdata->io_ctx, dev, samples_count, cyclic); - if (ret < 0) + if (ret < 0) { + ERROR("Opend unlocked: %d\n", ret); goto err_close_socket; + } ret = setup_cancel(&ppdata->io_ctx); if (ret < 0) @@ -849,8 +853,10 @@ static ssize_t read_all(struct iio_network_io_context *io_ctx, uintptr_t ptr = (uintptr_t) dst; while (len) { ssize_t ret = network_recv(io_ctx, (void *) ptr, len, 0); - if (ret < 0) + if (ret < 0) { + ERROR("NETWORK RECV: %zu\n", ret); return ret; + } ptr += ret; len -= ret; } @@ -892,8 +898,10 @@ static ssize_t network_read_mask(struct iio_network_io_context *io_ctx, ssize_t ret; ret = read_integer(io_ctx, &read_len); - if (ret < 0) + if (ret < 0) { + ERROR("READ INTEGER: %zu\n", ret); return ret; + } if (read_len > 0 && mask) { size_t i; @@ -1354,15 +1362,18 @@ static ssize_t network_read_line(struct iio_context_pdata *pdata, ret = network_recv(io_ctx, NULL, to_trunc, MSG_TRUNC); else ret = network_recv(io_ctx, dst - ret, to_trunc, 0); - if (ret < 0) + if (ret < 0) { + ERROR("NETWORK RECV: %zu\n", ret); return ret; + } bytes_read += to_trunc; } while (!found && len); - if (!found) + if (!found) { + ERROR("EIO: %zu\n", ret); return -EIO; - else + } else return bytes_read; #else for (i = 0; i < len - 1; i++) { From 497d3dac46804daacce2119d0067b10de5fca637 Mon Sep 17 00:00:00 2001 From: Dan Nechita Date: Fri, 14 Feb 2020 10:38:09 +0200 Subject: [PATCH 2/2] network: Fix typo in error message related to iiod client open Signed-off-by: Dan Nechita --- network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network.c b/network.c index acd1e7615..3319d1f4f 100644 --- a/network.c +++ b/network.c @@ -748,7 +748,7 @@ static int network_open(const struct iio_device *dev, ret = iiod_client_open_unlocked(pdata->iiod_client, &ppdata->io_ctx, dev, samples_count, cyclic); if (ret < 0) { - ERROR("Opend unlocked: %d\n", ret); + ERROR("Open unlocked: %d\n", ret); goto err_close_socket; }