]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Only terminate session after all transfers have been aborted
authorJoel Holdsworth <redacted>
Sat, 24 Mar 2012 10:04:36 +0000 (10:04 +0000)
committerJoel Holdsworth <redacted>
Sat, 24 Mar 2012 10:09:28 +0000 (10:09 +0000)
hardware/fx2lafw/fx2lafw.c
hardware/fx2lafw/fx2lafw.h

index ffc89c4eb110da51bb3b35ee29b51f9841f0f2ac..7f0c6734fd5246d2dddd2eb54b6fd3e324073ed4 100644 (file)
@@ -573,15 +573,25 @@ static int receive_data(int fd, int revents, void *cb_data)
 }
 
 static void abort_acquisition(struct context *ctx)
+{
+       ctx->num_samples = -1;
+}
+
+void finish_acquisition(struct context *ctx)
 {
        struct sr_datafeed_packet packet;
+       int i;
 
+       /* Terminate session */
        packet.type = SR_DF_END;
        sr_session_send(ctx->session_dev_id, &packet);
 
-       ctx->num_samples = -1;
-
-       /* TODO: Need to cancel and free any queued up transfers. */
+       /* Remove fds from polling */
+       const struct libusb_pollfd **const lupfd =
+               libusb_get_pollfds(usb_context);
+       for (i = 0; lupfd[i]; i++)
+               sr_source_remove(lupfd[i]->fd);
+       free(lupfd); /* NOT g_free()! */
 }
 
 static void receive_transfer(struct libusb_transfer *transfer)
@@ -601,6 +611,11 @@ static void receive_transfer(struct libusb_transfer *transfer)
        if (ctx->num_samples == -1) {
                if (transfer)
                        libusb_free_transfer(transfer);
+
+               ctx->submitted_transfers--;
+               if (ctx->submitted_transfers == 0)
+                       finish_acquisition(ctx);
+
                return;
        }
 
@@ -761,6 +776,8 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
                        g_free(buf);
                        return SR_ERR;
                }
+
+               ctx->submitted_transfers++;
                size = 4096;
        }
 
index 310a55d217b88e67226f744a8e77e51f54d7de86..48b6c441d5626bcf58691d52946ac50c03855f03 100644 (file)
@@ -66,6 +66,7 @@ struct context {
        uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
 
        int num_samples;
+       int submitted_transfers;
 
        void *session_dev_id;