From 8324a9a3e08413423c8ade7fb02db7ace0637c43 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Sun, 26 Jan 2014 00:11:15 +0100 Subject: [PATCH] Fix issue 447: Apparently some drivers only emit SANE_STATUS_EOF once, and SANE_STATUS_IO_ERROR after that. The code however assumed that the driver keeps emitting SANE_STATUS_EOF. This commit fixes this. --- Sane/_sane.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Sane/_sane.c b/Sane/_sane.c index 1c62610be..2ebcb1834 100644 --- a/Sane/_sane.c +++ b/Sane/_sane.c @@ -916,10 +916,13 @@ SaneDev_snap(SaneDevObject *self, PyObject *args) call which returns SANE_STATUS_EOF in order to start a new frame. */ - do { - st = sane_read(self->h, buffer, READSIZE, &len); - } - while (st == SANE_STATUS_GOOD); + if (st != SANE_STATUS_EOF) + { + do { + st = sane_read(self->h, buffer, READSIZE, &len); + } + while (st == SANE_STATUS_GOOD); + } if (st != SANE_STATUS_EOF) { Py_BLOCK_THREADS @@ -937,10 +940,13 @@ SaneDev_snap(SaneDevObject *self, PyObject *args) } } /* enforce SANE_STATUS_EOF. Can be necessary for ADF scans for some backends */ - do { - st = sane_read(self->h, buffer, READSIZE, &len); - } - while (st == SANE_STATUS_GOOD); + if (st != SANE_STATUS_EOF) + { + do { + st = sane_read(self->h, buffer, READSIZE, &len); + } + while (st == SANE_STATUS_GOOD); + } if (st != SANE_STATUS_EOF) { sane_cancel(self->h);