This patch allows the "wait for the lamp to warm up" loop (which can
run for up to 90 seconds) to be interrupted by a control-C, rather
than hanging the scan until the loop times out.

commit 5c978f8f5ca13abd664efc41ccc205fa77f847c0
Author: Dave Platt <[email protected]>
Date:   Tue Nov 22 19:47:05 2016 -0800

    avision: abort "wait for light" loop if interrupted
    
    Adds a "cancelled" flag to the Avision device structure, cleared
    in sane_start() and set in sane_cancel().  Test this flag in
    wait_4_light() and bail out of the 90-second "wait for the
    light to warm up" loop if the scan is cancelled.

diff --git a/backend/avision.c b/backend/avision.c
index 146125c..b08db57 100644
--- a/backend/avision.c
+++ b/backend/avision.c
@@ -2753,6 +2753,11 @@ wait_4_light (Avision_Scanner* s)
   set_triple (rcmd.transferlen, size);
   
   for (try = 0; try < 90; ++ try) {
+
+    if (s->cancelled) {
+      DBG (3, "wait_4_light: cancelled\n");
+      return SANE_STATUS_CANCELLED;
+    }
     
     DBG (5, "wait_4_light: read bytes %lu\n", (u_long) size);
     status = avision_cmd (&s->av_con, &rcmd, sizeof (rcmd), 0, 0, &result, &size);
@@ -6215,6 +6220,7 @@ do_cancel (Avision_Scanner* s)
   s->prepared = s->scanning = SANE_FALSE;
   s->duplex_rear_valid = SANE_FALSE;
   s->page = 0;
+  s->cancelled = 1;
   
   if (s->reader_pid != -1) {
     int exit_status;
@@ -8313,6 +8319,9 @@ sane_start (SANE_Handle handle)
   /* Make sure there is no scan running!!! */
   if (s->scanning)
     return SANE_STATUS_DEVICE_BUSY;
+
+  /* Clear cancellation status */
+  s->cancelled = 0;
  
   /* Make sure we have a current parameter set. Some of the
      parameters will be overwritten below, but that's OK. */
diff --git a/backend/avision.h b/backend/avision.h
index 2122e09..b26907f 100644
--- a/backend/avision.h
+++ b/backend/avision.h
@@ -444,6 +444,7 @@ typedef struct Avision_Scanner
   SANE_Bool prepared;		/* first page marker */
   SANE_Bool scanning;           /* scan in progress */
   unsigned int page;            /* page counter, 0: uninitialized, 1: scanning 1st page, ... */
+  int cancelled;
 
   SANE_Parameters params;       /* scan window */
   Avision_Dimensions avdimen;   /* scan window - detailed internals */
-- 
sane-devel mailing list: [email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
             to [email protected]

Reply via email to