kopia lustrzana https://gitlab.com/sane-project/backends
epson2: fixed timeout and scanner crash on WP-4540 series (and others)
rodzic
3babe5de40
commit
db31fdd1e3
|
@ -28,25 +28,32 @@
|
||||||
|
|
||||||
#include "sane/sanei_debug.h"
|
#include "sane/sanei_debug.h"
|
||||||
|
|
||||||
int
|
static int
|
||||||
sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted,
|
sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, ssize_t wanted,
|
||||||
SANE_Status * status)
|
SANE_Status *status)
|
||||||
{
|
{
|
||||||
size_t size, read = 0;
|
int ready, read = -1;
|
||||||
|
fd_set readable;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_sec = 10;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
FD_ZERO(&readable);
|
||||||
|
FD_SET(s->fd, &readable);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
*status = SANE_STATUS_GOOD;
|
*status = SANE_STATUS_GOOD;
|
||||||
|
|
||||||
while (read < wanted) {
|
if (read < wanted) {
|
||||||
size = sanei_tcp_read(s->fd, buf + read, wanted - read);
|
|
||||||
|
|
||||||
if (size == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
read += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (read < wanted)
|
|
||||||
*status = SANE_STATUS_IO_ERROR;
|
*status = SANE_STATUS_IO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +109,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted,
|
||||||
if (size == wanted) {
|
if (size == wanted) {
|
||||||
|
|
||||||
DBG(15, "%s: full read\n", __func__);
|
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) {
|
if (s->netbuf) {
|
||||||
free(s->netbuf);
|
free(s->netbuf);
|
||||||
|
@ -111,7 +119,6 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, ssize_t wanted,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read < 0) {
|
if (read < 0) {
|
||||||
*status = SANE_STATUS_IO_ERROR;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,6 @@ extern int sanei_epson_net_read(struct Epson_Scanner *s, unsigned char *buf, ssi
|
||||||
extern int sanei_epson_net_write(struct Epson_Scanner *s, unsigned int cmd, const unsigned char *buf,
|
extern int sanei_epson_net_write(struct Epson_Scanner *s, unsigned int cmd, const unsigned char *buf,
|
||||||
size_t buf_size, size_t reply_len,
|
size_t buf_size, size_t reply_len,
|
||||||
SANE_Status *status);
|
SANE_Status *status);
|
||||||
extern int
|
|
||||||
sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted,
|
|
||||||
SANE_Status * status);
|
|
||||||
extern SANE_Status sanei_epson_net_lock(struct Epson_Scanner *s);
|
extern SANE_Status sanei_epson_net_lock(struct Epson_Scanner *s);
|
||||||
extern SANE_Status sanei_epson_net_unlock(struct Epson_Scanner *s);
|
extern SANE_Status sanei_epson_net_unlock(struct Epson_Scanner *s);
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue