Update AUTHORS and fix code indent
[libftdi] / src / ftdi.c
index 9b20c37..b42ba14 100644 (file)
@@ -1236,10 +1236,6 @@ int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size)
     return offset;
 }
 
-#ifdef LIBFTDI_LINUX_ASYNC_MODE
-#ifdef USB_CLASS_PTP
-#error LIBFTDI_LINUX_ASYNC_MODE is not compatible with libusb-compat-0.1!
-#endif
 static void ftdi_read_data_cb(struct libusb_transfer *transfer)
 {
     struct ftdi_transfer_control *tc = (struct ftdi_transfer_control *) transfer->user_data;
@@ -1326,9 +1322,9 @@ static void ftdi_write_data_cb(struct libusb_transfer *transfer)
 {
     struct ftdi_transfer_control *tc = (struct ftdi_transfer_control *) transfer->user_data;
     struct ftdi_context *ftdi = tc->ftdi;
-
-    tc->offset = transfer->actual_length;
-
+    
+    tc->offset += transfer->actual_length;
+    
     if (tc->offset == tc->size)
     {
         tc->completed = 1;
@@ -1354,8 +1350,7 @@ static void ftdi_write_data_cb(struct libusb_transfer *transfer)
     Writes data to the chip. Does not wait for completion of the transfer
     nor does it make sure that the transfer was successful.
 
-    Use libusb 1.0 Asynchronous API.
-    Only available if compiled with --with-async-mode.
+    Use libusb 1.0 asynchronous API.
 
     \param ftdi pointer to ftdi_context
     \param buf Buffer with the data
@@ -1393,7 +1388,9 @@ struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi,
     else
       write_size = ftdi->writebuffer_chunksize;
 
-    libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->in_ep, buf, write_size, ftdi_write_data_cb, tc, ftdi->usb_write_timeout);
+    libusb_fill_bulk_transfer(transfer, ftdi->usb_dev, ftdi->in_ep, buf,
+                              write_size, ftdi_write_data_cb, tc,
+                              ftdi->usb_write_timeout);
     transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
 
     ret = libusb_submit_transfer(transfer);
@@ -1413,8 +1410,7 @@ struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi,
     Reads data from the chip. Does not wait for completion of the transfer
     nor does it make sure that the transfer was successful.
 
-    Use libusb 1.0 Asynchronous API.
-    Only available if compiled with --with-async-mode.
+    Use libusb 1.0 asynchronous API.
 
     \param ftdi pointer to ftdi_context
     \param buf Buffer with the data
@@ -1495,8 +1491,7 @@ struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context *ftdi, u
 /**
     Wait for completion of the transfer.
 
-    Use libusb 1.0 Asynchronous API.
-    Only available if compiled with --with-async-mode.
+    Use libusb 1.0 asynchronous API.
 
     \param tc pointer to ftdi_transfer_control
 
@@ -1521,23 +1516,25 @@ int ftdi_transfer_data_done(struct ftdi_transfer_control *tc)
                     break;
             libusb_free_transfer(tc->transfer);
             free (tc);
-            tc = NULL;
             return ret;
         }
     }
 
-    if (tc->transfer->status == LIBUSB_TRANSFER_COMPLETED)
-        ret = tc->offset;
-    else
-        ret = -1;
-
-    libusb_free_transfer(tc->transfer);
+    ret = tc->offset;
+    /**
+     * tc->transfer could be NULL if "(size <= ftdi->readbuffer_remaining)"
+     * at ftdi_read_data_submit(). Therefore, we need to check it here.
+     **/
+    if (tc->transfer)
+    {
+        if (tc->transfer->status != LIBUSB_TRANSFER_COMPLETED)
+            ret = -1;
+        libusb_free_transfer(tc->transfer);
+    }
     free(tc);
     return ret;
 }
 
-#endif // LIBFTDI_LINUX_ASYNC_MODE
-
 /**
     Configure write buffer chunk size.
     Default is 4096.