diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-07-15 11:25:39 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-07-15 11:25:39 +0200 |
commit | 1edb02101a9306fc711cd422ed507d18165b1691 (patch) | |
tree | bd2d48a139bfbe869f4f49359b63097931a45e7b /backend/epson2-io.c | |
parent | 2ca8a81bd0d99fe4d75c229d0e988d8ef710285f (diff) |
move from support/1.0.27 to feature/1.0.27
Diffstat (limited to 'backend/epson2-io.c')
-rw-r--r-- | backend/epson2-io.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/backend/epson2-io.c b/backend/epson2-io.c index 4477963..9d23e2a 100644 --- a/backend/epson2-io.c +++ b/backend/epson2-io.c @@ -113,32 +113,37 @@ ssize_t e2_recv(Epson_Scanner *s, void *buf, ssize_t buf_size, SANE_Status *status) { - ssize_t n = 0; + ssize_t n = buf_size; /* network interface needs to read header back even data is 0.*/ DBG(15, "%s: size = %ld, buf = %p\n", __func__, (long) buf_size, buf); + *status = SANE_STATUS_GOOD; if (s->hw->connection == SANE_EPSON_NET) { n = sanei_epson_net_read(s, buf, buf_size, status); } else if (s->hw->connection == SANE_EPSON_SCSI) { - n = sanei_epson2_scsi_read(s->fd, buf, buf_size, status); + if (buf_size) + n = sanei_epson2_scsi_read(s->fd, buf, buf_size, status); } else if (s->hw->connection == SANE_EPSON_PIO) { - if (buf_size == - (n = sanei_pio_read(s->fd, buf, (size_t) buf_size))) - *status = SANE_STATUS_GOOD; - else - *status = SANE_STATUS_INVAL; + if (buf_size) { + if (buf_size == + (n = sanei_pio_read(s->fd, buf, (size_t) buf_size))) + *status = SANE_STATUS_GOOD; + else + *status = SANE_STATUS_INVAL; + } } else if (s->hw->connection == SANE_EPSON_USB) { /* !!! only report an error if we don't read anything */ - n = buf_size; /* buf_size gets overwritten */ - *status = - sanei_usb_read_bulk(s->fd, (SANE_Byte *) buf, - (size_t *) & n); - r_cmd_count += (n + 63) / 64; /* add # of packets, rounding up */ - DBG(20, "%s: cmd count, r = %d, w = %d\n", - __func__, r_cmd_count, w_cmd_count); - - if (n > 0) - *status = SANE_STATUS_GOOD; + if (n) { + *status = + sanei_usb_read_bulk(s->fd, (SANE_Byte *) buf, + (size_t *) & n); + r_cmd_count += (n + 63) / 64; /* add # of packets, rounding up */ + DBG(20, "%s: cmd count, r = %d, w = %d\n", + __func__, r_cmd_count, w_cmd_count); + + if (n > 0) + *status = SANE_STATUS_GOOD; + } } if (n < buf_size) { @@ -170,18 +175,23 @@ e2_txrx(Epson_Scanner * s, unsigned char *txbuf, size_t txlen, unsigned char *rxbuf, size_t rxlen) { SANE_Status status; + size_t done; - e2_send(s, txbuf, txlen, rxlen, &status); + done = e2_send(s, txbuf, txlen, rxlen, &status); if (status != SANE_STATUS_GOOD) { DBG(1, "%s: tx err, %s\n", __func__, sane_strstatus(status)); return status; } + if (done != txlen) { + DBG(1, "%s: tx err, short write\n", __func__); + return SANE_STATUS_IO_ERROR; + } e2_recv(s, rxbuf, rxlen, &status); if (status != SANE_STATUS_GOOD) { DBG(1, "%s: rx err, %s\n", __func__, sane_strstatus(status)); } - + DBG(1, "%s: eds_recv status, %s\n", __func__, sane_strstatus(status)); return status; } |