On Tue, Sep 11, 2012 at 8:45 PM, John Chen <john...@gmail.com> wrote:

> Hi,
> My app needs be able  to read & write (to different enpoint) at same time,
> and my code is not working. but if I change the call to Synchronous
> , everything works fine, could any one tell me what I did wrong here?
> thx
>
> CallBackData* userdata=new CallBackData();
> userdata->ExitTransfer=false;
> int err =0;
> libusb_transfer* transfer =libusb_alloc_transfer(0);
>  if (!transfer)
>  {
>    err=-ENOMEM;
>    return NULL;
>  }
>  libusb_fill_bulk_transfer
> (transfer,m_handle,endpoint,reinterpret_cast<unsigned char*>
> (pbBuffer),
> c_uiLength,LibUSBDevice::WriteCallback,userdata,ITP_TRANSFER_TIMEOUT);
>
>  if (!err)
>  {
>    err = libusb_claim_interface(this->m_handle, 0);
>    err=libusb_submit_transfer(transfer);
>    while (!userdata->ExitTransfer)
>   {
>       //I also added Lock here for the whole block here and
> to serialize the call to
>       //libusb_handle_events_timeout_completed, but it still does not work.
>        struct timeval tv = { 1, 0 };
>        int completed =0;
>
>       err = libusb_handle_events_timeout_completed(NULL, &tv,&completed );
>  }
> }
>
>
What exactly is the problem with the code?

Could it be that userdata is getting destroyed in the callback, so the
!userdata->ExitTransfer check causes your program to crash? What does your
callback look like?

David
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to