summaryrefslogtreecommitdiff
path: root/backend/epson2_net.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2015-10-08 12:32:49 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2015-10-08 12:32:49 +0200
commitcfd27ef2ad8b005fd47ab41ef29b71d9e3d48201 (patch)
tree56cb8849a5df91b19b72fd4f48c79c343cd9bc5e /backend/epson2_net.c
parentba8d09abe681600aad991f4a75e904615b7ed29f (diff)
Imported Upstream version 1.0.25upstream/1.0.25
Diffstat (limited to 'backend/epson2_net.c')
-rw-r--r--backend/epson2_net.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/backend/epson2_net.c b/backend/epson2_net.c
index c7b4873..911ce62 100644
--- a/backend/epson2_net.c
+++ b/backend/epson2_net.c
@@ -15,6 +15,10 @@
#include "sane/config.h"
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
#include "sane/sane.h"
#include "sane/saneopts.h"
#include "sane/sanei_tcp.h"
@@ -28,25 +32,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;
-
- while (read < wanted) {
- size = sanei_tcp_read(s->fd, buf + read, wanted - read);
+ tv.tv_sec = 10;
+ tv.tv_usec = 0;
- if (size == 0)
- break;
+ FD_ZERO(&readable);
+ FD_SET(s->fd, &readable);
- 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 +91,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 +112,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 +122,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 +129,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;
}