forked from analogdevicesinc/libiio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase error reporting on iiod and network backend
This was taken from Lar's old branch "stresstest" analogdevicesinc@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
Showing
2 changed files
with
35 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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,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 */ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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++) { | ||
|