USBTransfer* fPendingTransfer= (USBTransfer*) fTransfers.RemoveItem((int32)0);
fTransfersLock.Unlock();
fPendingTransfer->Do(fRawFD);
- write(fEventPipes[1],&fPendingTransfer,sizeof(fPendingTransfer));
+ usbi_signal_transfer_completion(fPendingTransfer->UsbiTransfer());
}
}
fTransfersLock.Unlock();
if(removed)
{
- write(fEventPipes[1],&transfer,sizeof(transfer));
+ usbi_signal_transfer_completion(transfer->UsbiTransfer());
}
return LIBUSB_SUCCESS;
}
usbi_err(NULL,"failed to open device");
return;
}
- pipe(fEventPipes);
- fcntl(fEventPipes[1], F_SETFD, O_NONBLOCK);
fTransfersSem = create_sem(0, "Transfers Queue Sem");
fTransfersThread = spawn_thread(TransfersThread,"Transfer Worker",B_NORMAL_PRIORITY, this);
resume_thread(fTransfersThread);
if(fClaimedInterfaces&(1<<i))
ReleaseInterface(i);
}
- if(fEventPipes[1]>0)
- close(fEventPipes[1]);
- if(fEventPipes[0]>0)
- close(fEventPipes[0]);
delete_sem(fTransfersSem);
if(fTransfersThread>0)
wait_for_thread(fTransfersThread, NULL);
}
-int
-USBDeviceHandle::EventPipe(int index) const
-{
- return fEventPipes[index];
-}
-
int
USBDeviceHandle::ClaimInterface(int inumber)
{
return LIBUSB_ERROR_NO_DEVICE;
}
*((USBDeviceHandle**)dev_handle->os_priv)=handle;
- return usbi_add_pollfd(HANDLE_CTX(dev_handle),handle->EventPipe(0), POLLIN);
+ return LIBUSB_SUCCESS;
}
static void
USBDeviceHandle * handle=*((USBDeviceHandle**)dev_handle->os_priv);
if(handle==NULL)
return;
- usbi_remove_pollfd(HANDLE_CTX(dev_handle),handle->EventPipe(0));
delete handle;
*((USBDeviceHandle**)dev_handle->os_priv)=NULL;
}
}
static int
-haiku_handle_events(struct libusb_context* ctx, struct pollfd* fds, nfds_t nfds, int num_ready)
+haiku_handle_transfer_completion(struct usbi_transfer * itransfer)
{
- USBTransfer *transfer;
- for(int i=0;i<nfds && num_ready>0;i++)
+ USBTransfer* transfer=*((USBTransfer**)usbi_transfer_get_os_priv(itransfer));
+
+ usbi_mutex_lock(&itransfer->lock);
+ if(transfer->IsCancelled())
{
- struct pollfd *pollfd = &fds[i];
- if(!pollfd->revents)
- continue;
-
- num_ready--;
- read(pollfd->fd, &transfer, sizeof(transfer));
- struct usbi_transfer* itransfer=transfer->UsbiTransfer();
- usbi_mutex_lock(&itransfer->lock);
- if(transfer->IsCancelled())
- {
- delete transfer;
- *((USBTransfer**)usbi_transfer_get_os_priv(itransfer))=NULL;
- usbi_mutex_unlock(&itransfer->lock);
- if (itransfer->transferred < 0)
- itransfer->transferred = 0;
- usbi_handle_transfer_cancellation(transfer->UsbiTransfer());
- continue;
- }
- libusb_transfer_status status = LIBUSB_TRANSFER_COMPLETED;
- if(itransfer->transferred < 0)
- {
- usbi_err(ITRANSFER_CTX(itransfer),"error in transfer");
- status = LIBUSB_TRANSFER_ERROR;
- itransfer->transferred=0;
- }
delete transfer;
*((USBTransfer**)usbi_transfer_get_os_priv(itransfer))=NULL;
usbi_mutex_unlock(&itransfer->lock);
- usbi_handle_transfer_completion(itransfer,status);
+ if (itransfer->transferred < 0)
+ itransfer->transferred = 0;
+ return usbi_handle_transfer_cancellation(itransfer);
}
- return LIBUSB_SUCCESS;
+ libusb_transfer_status status = LIBUSB_TRANSFER_COMPLETED;
+ if(itransfer->transferred < 0)
+ {
+ usbi_err(ITRANSFER_CTX(itransfer), "error in transfer");
+ status = LIBUSB_TRANSFER_ERROR;
+ itransfer->transferred=0;
+ }
+ delete transfer;
+ *((USBTransfer**)usbi_transfer_get_os_priv(itransfer))=NULL;
+ usbi_mutex_unlock(&itransfer->lock);
+ return usbi_handle_transfer_completion(itransfer, status);
}
-
static int
haiku_clock_gettime(int clkid, struct timespec *tp)
{
/*.cancel_transfer =*/ haiku_cancel_transfer,
/*.clear_transfer_priv =*/ haiku_clear_transfer_priv,
- /*.handle_events =*/ haiku_handle_events,
- /*.handle_transfer_completion =*/ NULL,
+ /*.handle_events =*/ NULL,
+ /*.handle_transfer_completion =*/ haiku_handle_transfer_completion,
/*.clock_gettime =*/ haiku_clock_gettime,