Skip to content

Commit

Permalink
Merge pull request #376 from analogdevicesinc/rgetz-verbose-iiod-errors
Browse files Browse the repository at this point in the history
Increase error reporting on iiod and network backend
  • Loading branch information
dNechita authored Feb 14, 2020
2 parents 5674795 + 497d3da commit 404bcbf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
23 changes: 16 additions & 7 deletions iiod-client.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -606,24 +609,30 @@ 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)
break;

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 */
}
Expand Down
27 changes: 19 additions & 8 deletions network.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -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;
Expand All @@ -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("Open unlocked: %d\n", ret);
goto err_close_socket;
}

ret = setup_cancel(&ppdata->io_ctx);
if (ret < 0)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 404bcbf

Please sign in to comment.