Skip to content

Commit

Permalink
Increase error reporting on iiod and network backend
Browse files Browse the repository at this point in the history
This was taken from Lar's old branch "stresstest"
dc33705

and adds a few more error output when things go wrong.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Feb 13, 2020
1 parent f7943e0 commit 4384760
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

#include <stdio.h>

#ifdef _WIN32
#define __func__ __FUNCTION__
#endif

#define NoLog_L 0
#define Error_L 1
#define Warning_L 2
Expand Down
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: %s %zu\n",__func__, 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: %s %zu\n",__func__, 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: %s %zu\n",__func__, 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: %s %zu\n",__func__, 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: %s %zu\n",__func__, 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: %s %d\n",__func__, 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("Opend unlocked: %s %d\n",__func__, 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: %s %zu\n",__func__, 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: %s %zu\n",__func__, 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: %s %zu\n",__func__, ret);
return ret;
}

bytes_read += to_trunc;
} while (!found && len);

if (!found)
if (!found) {
ERROR("EIO: %s %zu\n",__func__, ret);
return -EIO;
else
} else
return bytes_read;
#else
for (i = 0; i < len - 1; i++) {
Expand Down

0 comments on commit 4384760

Please sign in to comment.