--- sane-backends-1.0.30/sanei/sanei_tcp.c 2020-05-17 06:54:18.000000000 -0500
+++ sane-backends-1.0.30/sanei/sanei_tcp.c 2020-06-10 14:10:06.980398975 -0500
@@ -44,6 +44,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <time.h>
#ifndef SSIZE_MAX
#define SSIZE_MAX LONG_MAX
@@ -128,6 +130,7 @@ sanei_tcp_read(int fd, u_char * buf, siz
{
size_t bytes_recv = 0;
ssize_t rc = 1;
+ int retry = 5;
if (count > SSIZE_MAX) {
errno = EINVAL;
@@ -137,9 +139,21 @@ sanei_tcp_read(int fd, u_char * buf, siz
while (bytes_recv < count && rc > 0)
{
rc = recv(fd, buf+bytes_recv, count-bytes_recv, 0);
+ DBG(1, "%s: bytes received %d\n", __FUNCTION__, rc);
if (rc > 0)
bytes_recv += rc;
-
+ else {
+ if ( errno == EAGAIN && retry-- ) {
+ DBG(1, "%s: waiting %d\n", __FUNCTION__, retry);
+ /* wait for max 1s */
+ struct timespec req;
+ struct timespec rem;
+ req.tv_sec = 0;
+ req.tv_nsec= 100000000;
+ nanosleep(&req, &rem);
+ rc = 1;
+ }
+ }
}
return bytes_recv;
}