aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <jaylink-dev@marcschink.de>2016-07-23 11:49:58 +0200
committerMarc Schink <jaylink-dev@marcschink.de>2016-07-23 11:49:58 +0200
commitc00c1058699d98e2e17ad167177a7bd21e4e6e70 (patch)
tree264b56d859f9c68647fb06fcfe198f8198961905
parent2344ec8140f1671fff97ff2a4600db9e47e14425 (diff)
Minor code cleanups
Signed-off-by: Marc Schink <jaylink-dev@marcschink.de>
-rw-r--r--configure.ac23
-rw-r--r--libjaylink/buffer.c6
-rw-r--r--libjaylink/core.c2
-rw-r--r--libjaylink/device.c84
-rw-r--r--libjaylink/discovery.c5
-rw-r--r--libjaylink/emucom.c15
-rw-r--r--libjaylink/fileio.c1
-rw-r--r--libjaylink/jtag.c1
-rw-r--r--libjaylink/libjaylink-internal.h2
-rw-r--r--libjaylink/libjaylink.h12
-rw-r--r--libjaylink/swd.c1
-rw-r--r--libjaylink/swo.c3
-rw-r--r--libjaylink/transport.c127
13 files changed, 138 insertions, 144 deletions
diff --git a/configure.ac b/configure.ac
index 909ae1a..4dc4bde 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,7 +67,7 @@ AC_C_BIGENDIAN
# Checks for library functions.
# Disable progress and informational output of libtool.
-AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
+AC_SUBST([AM_LIBTOOLFLAGS], '--silent')
# Libtool interface version of libjaylink. This is not the same as the package
# version. For information about the versioning system of libtool, see:
@@ -77,10 +77,10 @@ JAYLINK_VERSION_LIB_REVISION=0
JAYLINK_VERSION_LIB_AGE=0
JAYLINK_VERSION_LIB="$JAYLINK_VERSION_LIB_CURRENT:$JAYLINK_VERSION_LIB_REVISION:$JAYLINK_VERSION_LIB_AGE"
-AC_SUBST(JAYLINK_VERSION_LIB_CURRENT)
-AC_SUBST(JAYLINK_VERSION_LIB_REVISION)
-AC_SUBST(JAYLINK_VERSION_LIB_AGE)
-AC_SUBST(JAYLINK_VERSION_LIB)
+AC_SUBST([JAYLINK_VERSION_LIB_CURRENT])
+AC_SUBST([JAYLINK_VERSION_LIB_REVISION])
+AC_SUBST([JAYLINK_VERSION_LIB_AGE])
+AC_SUBST([JAYLINK_VERSION_LIB])
AC_ARG_ENABLE([subproject-build], AS_HELP_STRING([--enable-subproject-build],
[enable sub-project build [default=no]]))
@@ -90,9 +90,8 @@ AM_CONDITIONAL([SUBPROJECT_BUILD],
# Libtool interface version is not used for sub-project build as libjaylink is
# built as libtool convenience library.
-if test "x$enable_subproject_build" != "xyes"; then
-JAYLINK_LIB_LDFLAGS="-version-info $JAYLINK_VERSION_LIB"
-fi
+AS_IF([test "x$enable_subproject_build" != "xyes"],
+ [JAYLINK_LIB_LDFLAGS="-version-info $JAYLINK_VERSION_LIB"])
AC_SUBST([JAYLINK_LIB_LDFLAGS])
@@ -101,10 +100,10 @@ JAYLINK_VERSION_PACKAGE_MINOR=jaylink_version_package_minor
JAYLINK_VERSION_PACKAGE_MICRO=jaylink_version_package_micro
JAYLINK_VERSION_PACKAGE=jaylink_version_package
-AC_SUBST(JAYLINK_VERSION_PACKAGE_MAJOR)
-AC_SUBST(JAYLINK_VERSION_PACKAGE_MINOR)
-AC_SUBST(JAYLINK_VERSION_PACKAGE_MICRO)
-AC_SUBST(JAYLINK_VERSION_PACKAGE)
+AC_SUBST([JAYLINK_VERSION_PACKAGE_MAJOR])
+AC_SUBST([JAYLINK_VERSION_PACKAGE_MINOR])
+AC_SUBST([JAYLINK_VERSION_PACKAGE_MICRO])
+AC_SUBST([JAYLINK_VERSION_PACKAGE])
# Use C99 compatible stdio functions on MinGW instead of the incompatible
# functions provided by Microsoft.
diff --git a/libjaylink/buffer.c b/libjaylink/buffer.c
index 4031a96..952f49a 100644
--- a/libjaylink/buffer.c
+++ b/libjaylink/buffer.c
@@ -38,7 +38,8 @@
* @param value Value to write into the buffer in host byte order.
* @param offset Offset of the value within the buffer in bytes.
*/
-JAYLINK_PRIV void buffer_set_u16(uint8_t *buffer, uint16_t value, size_t offset)
+JAYLINK_PRIV void buffer_set_u16(uint8_t *buffer, uint16_t value,
+ size_t offset)
{
/*
* Store the value in the buffer and swap byte order depending on the
@@ -89,7 +90,8 @@ JAYLINK_PRIV uint16_t buffer_get_u16(const uint8_t *buffer, size_t offset)
* @param value Value to write into the buffer in host byte order.
* @param offset Offset of the value within the buffer in bytes.
*/
-JAYLINK_PRIV void buffer_set_u32(uint8_t *buffer, uint32_t value, size_t offset)
+JAYLINK_PRIV void buffer_set_u32(uint8_t *buffer, uint32_t value,
+ size_t offset)
{
/*
* Store the value in the buffer and swap byte order depending on the
diff --git a/libjaylink/core.c b/libjaylink/core.c
index 9ab3b5f..a25b217 100644
--- a/libjaylink/core.c
+++ b/libjaylink/core.c
@@ -57,7 +57,7 @@ JAYLINK_API int jaylink_init(struct jaylink_context **ctx)
if (!context)
return JAYLINK_ERR_MALLOC;
- if (libusb_init(&context->usb_ctx) < 0) {
+ if (libusb_init(&context->usb_ctx) != LIBUSB_SUCCESS) {
free(context);
return JAYLINK_ERR;
}
diff --git a/libjaylink/device.c b/libjaylink/device.c
index e941a3d..36f3e03 100644
--- a/libjaylink/device.c
+++ b/libjaylink/device.c
@@ -58,7 +58,8 @@
/** @endcond */
/** @private */
-JAYLINK_PRIV struct jaylink_device *device_allocate(struct jaylink_context *ctx)
+JAYLINK_PRIV struct jaylink_device *device_allocate(
+ struct jaylink_context *ctx)
{
struct jaylink_device *dev;
struct list *list;
@@ -78,36 +79,12 @@ JAYLINK_PRIV struct jaylink_device *device_allocate(struct jaylink_context *ctx)
ctx->devs = list;
dev->ctx = ctx;
- dev->refcnt = 1;
+ dev->ref_count = 1;
dev->usb_dev = NULL;
return dev;
}
-/** @private */
-static struct jaylink_device_handle *allocate_device_handle(
- struct jaylink_device *dev)
-{
- struct jaylink_device_handle *devh;
-
- devh = malloc(sizeof(struct jaylink_device_handle));
-
- if (!devh)
- return NULL;
-
- devh->dev = jaylink_ref_device(dev);
-
- return devh;
-}
-
-/** @private */
-static void free_device_handle(struct jaylink_device_handle *devh)
-{
- jaylink_unref_device(devh->dev);
- free(devh);
-}
-
-/** @private */
static struct jaylink_device **allocate_device_list(size_t length)
{
struct jaylink_device **list;
@@ -198,12 +175,8 @@ JAYLINK_API void jaylink_free_devices(struct jaylink_device **devices,
return;
if (unref) {
- i = 0;
-
- while (devices[i]) {
+ for (i = 0; devices[i]; i++)
jaylink_unref_device(devices[i]);
- i++;
- }
}
free(devices);
@@ -281,7 +254,8 @@ JAYLINK_API int jaylink_device_get_serial_number(
*
* @since 0.1.0
*/
-JAYLINK_API int jaylink_device_get_usb_address(const struct jaylink_device *dev,
+JAYLINK_API int jaylink_device_get_usb_address(
+ const struct jaylink_device *dev,
enum jaylink_usb_address *address)
{
if (!dev || !address)
@@ -311,7 +285,7 @@ JAYLINK_API struct jaylink_device *jaylink_ref_device(
if (!dev)
return NULL;
- dev->refcnt++;
+ dev->ref_count++;
return dev;
}
@@ -330,9 +304,9 @@ JAYLINK_API void jaylink_unref_device(struct jaylink_device *dev)
if (!dev)
return;
- dev->refcnt--;
+ dev->ref_count--;
- if (dev->refcnt == 0) {
+ if (!dev->ref_count) {
ctx = dev->ctx;
log_dbg(ctx, "Device destroyed (bus:address = %03u:%03u).",
@@ -348,6 +322,27 @@ JAYLINK_API void jaylink_unref_device(struct jaylink_device *dev)
}
}
+static struct jaylink_device_handle *allocate_device_handle(
+ struct jaylink_device *dev)
+{
+ struct jaylink_device_handle *devh;
+
+ devh = malloc(sizeof(struct jaylink_device_handle));
+
+ if (!devh)
+ return NULL;
+
+ devh->dev = jaylink_ref_device(dev);
+
+ return devh;
+}
+
+static void free_device_handle(struct jaylink_device_handle *devh)
+{
+ jaylink_unref_device(devh->dev);
+ free(devh);
+}
+
/**
* Open a device.
*
@@ -381,7 +376,7 @@ JAYLINK_API int jaylink_open(struct jaylink_device *dev,
ret = transport_open(handle);
- if (ret < 0) {
+ if (ret != JAYLINK_OK) {
free_device_handle(handle);
return ret;
}
@@ -447,8 +442,9 @@ JAYLINK_API struct jaylink_device *jaylink_get_device(
*
* @since 0.1.0
*/
-JAYLINK_API int jaylink_get_firmware_version(struct jaylink_device_handle *devh,
- char **version, size_t *length)
+JAYLINK_API int jaylink_get_firmware_version(
+ struct jaylink_device_handle *devh, char **version,
+ size_t *length)
{
int ret;
struct jaylink_context *ctx;
@@ -589,7 +585,8 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
}
for (i = 0; i < num; i++)
- info[i] = buffer_get_u32((uint8_t *)info, i * sizeof(uint32_t));
+ info[i] = buffer_get_u32((uint8_t *)info,
+ i * sizeof(uint32_t));
return JAYLINK_OK;
}
@@ -612,7 +609,8 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
*
* @since 0.1.0
*/
-JAYLINK_API int jaylink_get_hardware_version(struct jaylink_device_handle *devh,
+JAYLINK_API int jaylink_get_hardware_version(
+ struct jaylink_device_handle *devh,
struct jaylink_hardware_version *version)
{
int ret;
@@ -1146,7 +1144,8 @@ JAYLINK_API int jaylink_register(struct jaylink_device_handle *devh,
ret = transport_start_read(devh, size - REG_MIN_SIZE);
if (ret != JAYLINK_OK) {
- log_err(ctx, "transport_start_read() failed: %i.", ret);
+ log_err(ctx, "transport_start_read() failed: %i.",
+ ret);
return JAYLINK_ERR;
}
@@ -1281,7 +1280,8 @@ JAYLINK_API int jaylink_unregister(struct jaylink_device_handle *devh,
ret = transport_start_read(devh, size - REG_MIN_SIZE);
if (ret != JAYLINK_OK) {
- log_err(ctx, "transport_start_read() failed: %i.", ret);
+ log_err(ctx, "transport_start_read() failed: %i.",
+ ret);
return JAYLINK_ERR;
}
diff --git a/libjaylink/discovery.c b/libjaylink/discovery.c
index 2c463dc..da20d17 100644
--- a/libjaylink/discovery.c
+++ b/libjaylink/discovery.c
@@ -133,13 +133,12 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx,
ret = libusb_get_device_descriptor(usb_dev, &desc);
- if (ret < 0) {
+ if (ret != LIBUSB_SUCCESS) {
log_warn(ctx, "Failed to get device descriptor: %s.",
libusb_error_name(ret));
return NULL;
}
- /* Check for USB Vendor ID (VID) of SEGGER. */
if (desc.idVendor != USB_VENDOR_ID)
return NULL;
@@ -183,7 +182,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx,
/* Open the device to be able to retrieve its serial number. */
ret = libusb_open(usb_dev, &usb_devh);
- if (ret < 0) {
+ if (ret != LIBUSB_SUCCESS) {
log_warn(ctx, "Failed to open device: %s.",
libusb_error_name(ret));
return NULL;
diff --git a/libjaylink/emucom.c b/libjaylink/emucom.c
index dd3145a..e70f07a 100644
--- a/libjaylink/emucom.c
+++ b/libjaylink/emucom.c
@@ -130,11 +130,8 @@ JAYLINK_API int jaylink_emucom_read(struct jaylink_device_handle *devh,
tmp = buffer_get_u32(buf, 0);
- if (tmp == EMUCOM_ERR_NOT_SUPPORTED) {
- log_err(ctx, "Channel 0x%x is not supported by the device.",
- channel);
+ if (tmp == EMUCOM_ERR_NOT_SUPPORTED)
return JAYLINK_ERR_DEV_NOT_SUPPORTED;
- }
if ((tmp & ~EMUCOM_AVAILABLE_BYTES_MASK) == EMUCOM_ERR_NOT_AVAILABLE) {
*length = tmp & EMUCOM_AVAILABLE_BYTES_MASK;
@@ -204,7 +201,6 @@ JAYLINK_API int jaylink_emucom_write(struct jaylink_device_handle *devh,
struct jaylink_context *ctx;
uint8_t buf[10];
uint32_t tmp;
- int32_t dummy;
if (!devh || !buffer || !length)
return JAYLINK_ERR_ARG;
@@ -256,15 +252,10 @@ JAYLINK_API int jaylink_emucom_write(struct jaylink_device_handle *devh,
tmp = buffer_get_u32(buf, 0);
- if (tmp == EMUCOM_ERR_NOT_SUPPORTED) {
- log_err(ctx, "Channel 0x%x is not supported by the device.",
- channel);
+ if (tmp == EMUCOM_ERR_NOT_SUPPORTED)
return JAYLINK_ERR_DEV_NOT_SUPPORTED;
- }
- dummy = tmp;
-
- if (dummy < 0) {
+ if (tmp & EMUCOM_ERR) {
log_err(ctx, "Failed to write to channel 0x%x.", channel);
return JAYLINK_ERR_DEV;
}
diff --git a/libjaylink/fileio.c b/libjaylink/fileio.c
index d1bf9c9..28d20bd 100644
--- a/libjaylink/fileio.c
+++ b/libjaylink/fileio.c
@@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stddef.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
diff --git a/libjaylink/jtag.c b/libjaylink/jtag.c
index a958214..196bd64 100644
--- a/libjaylink/jtag.c
+++ b/libjaylink/jtag.c
@@ -113,7 +113,6 @@ JAYLINK_API int jaylink_jtag_io(struct jaylink_device_handle *devh,
}
buf[0] = cmd;
- /* Dummy byte. */
buf[1] = 0x00;
buffer_set_u16(buf, length, 2);
diff --git a/libjaylink/libjaylink-internal.h b/libjaylink/libjaylink-internal.h
index 9d568df..47a24a1 100644
--- a/libjaylink/libjaylink-internal.h
+++ b/libjaylink/libjaylink-internal.h
@@ -69,7 +69,7 @@ struct jaylink_device {
/** libjaylink context. */
struct jaylink_context *ctx;
/** Number of references held on this device instance. */
- int refcnt;
+ size_t ref_count;
/** Host interface. */
enum jaylink_host_interface interface;
/** libusb device instance. */
diff --git a/libjaylink/libjaylink.h b/libjaylink/libjaylink.h
index 9ff56d3..7083127 100644
--- a/libjaylink/libjaylink.h
+++ b/libjaylink/libjaylink.h
@@ -20,6 +20,7 @@
#ifndef LIBJAYLINK_LIBJAYLINK_H
#define LIBJAYLINK_LIBJAYLINK_H
+#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
@@ -383,7 +384,8 @@ JAYLINK_API int jaylink_device_get_host_interface(
enum jaylink_host_interface *interface);
JAYLINK_API int jaylink_device_get_serial_number(
const struct jaylink_device *dev, uint32_t *serial_number);
-JAYLINK_API int jaylink_device_get_usb_address(const struct jaylink_device *dev,
+JAYLINK_API int jaylink_device_get_usb_address(
+ const struct jaylink_device *dev,
enum jaylink_usb_address *address);
JAYLINK_API struct jaylink_device *jaylink_ref_device(
struct jaylink_device *dev);
@@ -393,11 +395,13 @@ JAYLINK_API int jaylink_open(struct jaylink_device *dev,
JAYLINK_API void jaylink_close(struct jaylink_device_handle *devh);
JAYLINK_API struct jaylink_device *jaylink_get_device(
struct jaylink_device_handle *devh);
-JAYLINK_API int jaylink_get_firmware_version(struct jaylink_device_handle *devh,
- char **version, size_t *length);
+JAYLINK_API int jaylink_get_firmware_version(
+ struct jaylink_device_handle *devh, char **version,
+ size_t *length);
JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
uint32_t mask, uint32_t *info);
-JAYLINK_API int jaylink_get_hardware_version(struct jaylink_device_handle *devh,
+JAYLINK_API int jaylink_get_hardware_version(
+ struct jaylink_device_handle *devh,
struct jaylink_hardware_version *version);
JAYLINK_API int jaylink_get_hardware_status(struct jaylink_device_handle *devh,
struct jaylink_hardware_status *status);
diff --git a/libjaylink/swd.c b/libjaylink/swd.c
index 2b9aed1..458298b 100644
--- a/libjaylink/swd.c
+++ b/libjaylink/swd.c
@@ -93,7 +93,6 @@ JAYLINK_API int jaylink_swd_io(struct jaylink_device_handle *devh,
}
buf[0] = CMD_SWD_IO;
- /* Dummy byte. */
buf[1] = 0x00;
buffer_set_u16(buf, length, 2);
diff --git a/libjaylink/swo.c b/libjaylink/swo.c
index 5d72226..12ea097 100644
--- a/libjaylink/swo.c
+++ b/libjaylink/swo.c
@@ -274,7 +274,8 @@ JAYLINK_API int jaylink_swo_read(struct jaylink_device_handle *devh,
ret = transport_start_read(devh, tmp);
if (ret != JAYLINK_OK) {
- log_err(ctx, "transport_start_read() failed: %i.", ret);
+ log_err(ctx, "transport_start_read() failed: %i.",
+ ret);
return ret;
}
diff --git a/libjaylink/transport.c b/libjaylink/transport.c
index db50738..b7f7cb4 100644
--- a/libjaylink/transport.c
+++ b/libjaylink/transport.c
@@ -18,7 +18,6 @@
*/
#include <stdlib.h>
-#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
@@ -180,7 +179,7 @@ JAYLINK_PRIV int transport_open(struct jaylink_device_handle *devh)
ret = initialize_handle(devh);
if (ret != JAYLINK_OK) {
- log_err(ctx, "Initialize device handle failed.");
+ log_err(ctx, "Failed to initialize device handle.");
return ret;
}
@@ -390,47 +389,35 @@ JAYLINK_PRIV int transport_start_write_read(struct jaylink_device_handle *devh,
return JAYLINK_OK;
}
-static int usb_recv(struct jaylink_device_handle *devh, uint8_t *buffer,
- size_t *length)
+static bool adjust_buffer(struct jaylink_device_handle *devh, size_t size)
{
- int ret;
struct jaylink_context *ctx;
- unsigned int tries;
- int transferred;
+ size_t num_chunks;
+ uint8_t *buffer;
ctx = devh->dev->ctx;
- tries = NUM_TIMEOUTS;
- transferred = 0;
- while (tries > 0 && !transferred) {
- /* Always request CHUNK_SIZE bytes from the device. */
- ret = libusb_bulk_transfer(devh->usb_devh, devh->endpoint_in,
- (unsigned char *)buffer, CHUNK_SIZE, &transferred,
- USB_TIMEOUT);
+ /* Adjust buffer size to a multiple of CHUNK_SIZE bytes. */
+ num_chunks = size / CHUNK_SIZE;
- if (ret == LIBUSB_ERROR_TIMEOUT) {
- log_warn(ctx, "Failed to receive data from "
- "device: %s.", libusb_error_name(ret));
- tries--;
- continue;
- } else if (ret != LIBUSB_SUCCESS) {
- log_err(ctx, "Failed to receive data from "
- "device: %s.", libusb_error_name(ret));
- return JAYLINK_ERR;
- }
+ if (size % CHUNK_SIZE > 0)
+ num_chunks++;
- log_dbg(ctx, "Received %i bytes from device.", transferred);
- }
+ size = num_chunks * CHUNK_SIZE;
+ buffer = realloc(devh->buffer, size);
- /* Ignore a possible timeout if at least one byte was received. */
- if (transferred > 0) {
- *length = transferred;
- return JAYLINK_OK;
+ if (!buffer) {
+ log_err(ctx, "Failed to adjust buffer size to %zu bytes.",
+ size);
+ return false;
}
- log_err(ctx, "Receiving data from device timed out.");
+ devh->buffer = buffer;
+ devh->buffer_size = size;
- return JAYLINK_ERR_TIMEOUT;
+ log_dbg(ctx, "Adjusted buffer size to %zu bytes.", size);
+
+ return true;
}
static int usb_send(struct jaylink_device_handle *devh, const uint8_t *buffer,
@@ -476,37 +463,6 @@ static int usb_send(struct jaylink_device_handle *devh, const uint8_t *buffer,
return JAYLINK_ERR_TIMEOUT;
}
-static bool adjust_buffer(struct jaylink_device_handle *devh, size_t size)
-{
- struct jaylink_context *ctx;
- size_t num_chunks;
- uint8_t *buffer;
-
- ctx = devh->dev->ctx;
-
- /* Adjust buffer size to a multiple of CHUNK_SIZE bytes. */
- num_chunks = size / CHUNK_SIZE;
-
- if (size % CHUNK_SIZE > 0)
- num_chunks++;
-
- size = num_chunks * CHUNK_SIZE;
- buffer = realloc(devh->buffer, size);
-
- if (!buffer) {
- log_err(ctx, "Failed to adjust buffer size to %zu bytes.",
- size);
- return false;
- }
-
- devh->buffer = buffer;
- devh->buffer_size = size;
-
- log_dbg(ctx, "Adjusted buffer size to %zu bytes.", size);
-
- return true;
-}
-
/**
* Write data to a device.
*
@@ -614,6 +570,49 @@ JAYLINK_PRIV int transport_write(struct jaylink_device_handle *devh,
return usb_send(devh, buffer, length);
}
+static int usb_recv(struct jaylink_device_handle *devh, uint8_t *buffer,
+ size_t *length)
+{
+ int ret;
+ struct jaylink_context *ctx;
+ unsigned int tries;
+ int transferred;
+
+ ctx = devh->dev->ctx;
+ tries = NUM_TIMEOUTS;
+ transferred = 0;
+
+ while (tries > 0 && !transferred) {
+ /* Always request CHUNK_SIZE bytes from the device. */
+ ret = libusb_bulk_transfer(devh->usb_devh, devh->endpoint_in,
+ (unsigned char *)buffer, CHUNK_SIZE, &transferred,
+ USB_TIMEOUT);
+
+ if (ret == LIBUSB_ERROR_TIMEOUT) {
+ log_warn(ctx, "Failed to receive data from device: "
+ "%s.", libusb_error_name(ret));
+ tries--;
+ continue;
+ } else if (ret != LIBUSB_SUCCESS) {
+ log_err(ctx, "Failed to receive data from device: %s.",
+ libusb_error_name(ret));
+ return JAYLINK_ERR;
+ }
+
+ log_dbg(ctx, "Received %i bytes from device.", transferred);
+ }
+
+ /* Ignore a possible timeout if at least one byte was received. */
+ if (transferred > 0) {
+ *length = transferred;
+ return JAYLINK_OK;
+ }
+
+ log_err(ctx, "Receiving data from device timed out.");
+
+ return JAYLINK_ERR_TIMEOUT;
+}
+
/**
* Read data from a device.
*
@@ -660,7 +659,7 @@ JAYLINK_PRIV int transport_read(struct jaylink_device_handle *devh,
return JAYLINK_OK;
}
- if (devh->bytes_available) {
+ if (devh->bytes_available > 0) {
memcpy(buffer, devh->buffer + devh->read_pos,
devh->bytes_available);