From 9b8ccb99fb2196003449b199004d98eba84c2407 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 8 Jul 2010 13:55:09 +0200 Subject: [PATCH] Increase the packet size if more data is immediately available. --- src/uwatec_smart.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index b4bd692..8a2814e 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -409,11 +409,20 @@ uwatec_smart_device_dump (device_t *abstract, dc_buffer_t *buffer) unsigned int nbytes = 0; while (nbytes < length) { - unsigned int len = length - nbytes; - if (len > 32) - len = 32; + // Set the minimum packet size. + unsigned int len = 32; + + // Increase the packet size if more data is immediately available. + int available = irda_socket_available (device->socket); + if (available > len) + len = available; + + // Limit the packet size to the total size. + if (nbytes + len > length) + len = length - nbytes; + int n = irda_socket_read (device->socket, data + nbytes, len); - if (n < 0) { + if (n != len) { WARNING ("Failed to receive the answer."); return EXITCODE (n); }