From b2802d98d4486d6afc585062f4ca02fddf829dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 2 Jan 2015 20:06:30 +0100 Subject: Release 1.0.25+git20150102-1 --- backend/epson2_net.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'backend/epson2_net.c') diff --git a/backend/epson2_net.c b/backend/epson2_net.c index c7b4873..178b519 100644 --- a/backend/epson2_net.c +++ b/backend/epson2_net.c @@ -28,25 +28,32 @@ #include "sane/sanei_debug.h" -int -sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted, - SANE_Status * status) +static int +sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, + SANE_Status *status) { - size_t size, read = 0; + int ready, read = -1; + fd_set readable; + struct timeval tv; - *status = SANE_STATUS_GOOD; + tv.tv_sec = 10; + tv.tv_usec = 0; - while (read < wanted) { - size = sanei_tcp_read(s->fd, buf + read, wanted - read); + FD_ZERO(&readable); + FD_SET(s->fd, &readable); - if (size == 0) - break; - - read += size; + ready = select(s->fd + 1, &readable, NULL, NULL, &tv); + if (ready > 0) { + read = sanei_tcp_read(s->fd, buf, wanted); + } else { + DBG(15, "%s: select failed: %d\n", __func__, ready); } - if (read < wanted) + *status = SANE_STATUS_GOOD; + + if (read < wanted) { *status = SANE_STATUS_IO_ERROR; + } return read; } @@ -80,9 +87,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, } /* receive net header */ - size = sanei_tcp_read(s->fd, header, 12); + size = sanei_epson_net_read_raw(s, header, 12, status); if (size != 12) { - *status = SANE_STATUS_IO_ERROR; return 0; } @@ -102,7 +108,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, if (size == wanted) { DBG(15, "%s: full read\n", __func__); - read = sanei_tcp_read(s->fd, buf, size); + + read = sanei_epson_net_read_raw(s, buf, size, status); if (s->netbuf) { free(s->netbuf); @@ -111,7 +118,6 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, } if (read < 0) { - *status = SANE_STATUS_IO_ERROR; return 0; } @@ -119,9 +125,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted, } else { DBG(23, "%s: partial read\n", __func__); - read = sanei_tcp_read(s->fd, s->netbuf, size); + read = sanei_epson_net_read_raw(s, s->netbuf, size, status); if (read != size) { - *status = SANE_STATUS_IO_ERROR; return 0; } -- cgit v1.2.3