Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-24 Thread Peer Stritzinger
Hi

On Fri, Jul 23, 2010 at 7:21 PM, Hans Petter Selasky  wrote:
> Should work, but it might be that the second poll, when you try to process the
> events, don't work like expected. After any event on the two fd's you should
> call "libusb_handle_events_locked()" using a "tv = NULL".

Rewrote the program to use poll instead of select (which does fit
libusb better even if I like select better generally)
nothing else changed only poll instead of select.

=> Works like a charm

So to sum it up: select + libusb seems not to work, poll + libusb works however.

So is this a general FreeBSD select vs. poll issue or just with the USB stack?

How can I help debug this further?

Regards
Peer Stritzinger
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Peer Stritzinger
On Fri, Jul 23, 2010 at 7:21 PM, Hans Petter Selasky  wrote:

> Should work, but it might be that the second poll, when you try to process the
> events, don't work like expected. After any event on the two fd's you should
> call "libusb_handle_events_locked()" using a "tv = NULL".

With libusb_handle_events_locked() instead of
libusb_handle_events_timeout() there is no improvement ...

It looks like if there is a IN alread pending on the bus when program
runs the first select call returns the filedesc correctly but after
this nothing triggers the second select.  At least most of the time it
looks like IN transfers that are received during the second select are
somehow swallowed unhandled.

If there is no IN pending on the bus the first select also returns but
libusb_handle_events_locked() doesn't call a callback, then the second
select also fails.

Regards
-- Peer
Could it be that after the poll() in lib_usb_handle_events_*() libusb
or the usb stack is somewhat in a corrupt state?
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Peer Stritzinger
Hi,

On Fri, Jul 23, 2010 at 7:21 PM, Hans Petter Selasky  wrote:

> Should work, but it might be that the second poll, when you try to process the
> events, don't work like expected. After any event on the two fd's you should
> call "libusb_handle_events_locked()" using a "tv = NULL".

Added some debug printing to make watching these easier:

active config: num_interfaces: 1
interface 0: num_altsetting: 1
if_desc 0: n_ep=4 if_nr=0
max packet on 3.2.6 = 512
setup_usb_fds: read 3
setup_usb_fds: read 6
setup_usb_fds: write 6
setup_usb_fds: nfds 6
calling select ...
returned 1  -> so select returns once (always as it looks)
check_usb_fds: found desc 3 in readfds
calling libusb_handle_events_timeout
transfer_completed: actual_len: 52-> and also gets a transfer from
the usb (this resubmits the IN transfer)
setup_usb_fds: read 3
setup_usb_fds: read 6
setup_usb_fds: write 6
setup_usb_fds: nfds 6
calling select ...-> but here it hangs until a signal

The code that did output this still using libusb_handle_events_timeout()

  rv = libusb_submit_transfer(tr);
  assert(rv == 0);

  sp.pollfds = libusb_get_pollfds(ctx);

  while (1)
{
  timeout_pending = libusb_get_next_timeout(ctx, &timeout);
  setup_usb_fds (&sp);
  printf("calling select ...\n");
  rv = select(sp.nfds, &sp.readfds, &sp.writefds, &sp.exceptfds,
 (timeout_pending) ? &timeout : NULL);
  printf("returned %d\n", rv);
  assert (rv >= 0 || errno == EINTR);

  if (rv == 0 || (rv > 0 && check_usb_fds (&sp)))
{
  printf ("calling libusb_handle_events_timeout\n");
  libusb_handle_events_timeout(ctx, NULL);
}
}

 -- Peer
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Peer Stritzinger
Hi,

On Fri, Jul 23, 2010 at 7:21 PM, Hans Petter Selasky  wrote:
>
> Should work, but it might be that the second poll, when you try to process the
> events, don't work like expected. After any event on the two fd's you should
> call "libusb_handle_events_locked()" using a "tv = NULL".

I was calling libusb_handle_events_timeout(ctx, NULL), does this make
an difference (only running single threaded)

-- Peer
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Hans Petter Selasky
On Friday 23 July 2010 19:12:46 Peer Stritzinger wrote:
> Hi,
> 
> On Fri, Jul 23, 2010 at 4:57 PM, Hans Petter Selasky  
wrote:
> > What are the polling flags you are using?
> 
> Do you mean the libusb_pollfd entries?
> 
> They are:
> 
> {fd = 0x7, events = 0x1}
> {fd = 0xc, events = 0x45}
> 
> I translate these into select(2) params like this:
> 
> nfds = 0xc, readfds = {__fds_bits = {0x1080, 0x0 }},
>   writefds = {__fds_bits = {0x1000, 0x0 }}, exceptfds = {
> __fds_bits = {0x0 }},
> 
> And call select with timeout = NULL (since libusb_get_next_timeout returned
> 0)

Should work, but it might be that the second poll, when you try to process the 
events, don't work like expected. After any event on the two fd's you should 
call "libusb_handle_events_locked()" using a "tv = NULL".

--HPS
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Peer Stritzinger
Hi,

On Fri, Jul 23, 2010 at 4:57 PM, Hans Petter Selasky  wrote:
>
> What are the polling flags you are using?

Do you mean the libusb_pollfd entries?

They are:

{fd = 0x7, events = 0x1}
{fd = 0xc, events = 0x45}

I translate these into select(2) params like this:

nfds = 0xc, readfds = {__fds_bits = {0x1080, 0x0 }},
  writefds = {__fds_bits = {0x1000, 0x0 }}, exceptfds = {
__fds_bits = {0x0 }},

And call select with timeout = NULL (since libusb_get_next_timeout returned 0)

Regards
-- Peer
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


Re: FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Hans Petter Selasky
On Friday 23 July 2010 15:36:14 Peer Stritzinger wrote:
> Hi,
> 
> I'm using libusb to talk to a generic device (thats being also
> developed by me), synchronous works fine now.
> 
> Asynchronous mode with blocking libusb_handle_events() works also.
> 
> Now I'm trying to also talk to non USB file descriptors.  For this I'm
> using select(2), filling the sets from libusb_get_pollfds() results.
> 
> Somehow the select call never returns (no timeouts), if It gets some
> external trigger (like stopping in the debugger can continuing) it
> returns and has plausible return values.
> 
> Looking into libusb I find that it uses poll(2) internally.
> 
> Is select(2) supposed to work with libusb fd'?
> 
> Should I rather use poll(2)?  (I do like select more -- more BSDish).
> 

What are the polling flags you are using?

--HPS
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"


FreeBSD 8: libusb async mode + select(2) = nogo?

2010-07-23 Thread Peer Stritzinger
Hi,

I'm using libusb to talk to a generic device (thats being also
developed by me), synchronous works fine now.

Asynchronous mode with blocking libusb_handle_events() works also.

Now I'm trying to also talk to non USB file descriptors.  For this I'm
using select(2), filling the sets from libusb_get_pollfds() results.

Somehow the select call never returns (no timeouts), if It gets some
external trigger (like stopping in the debugger can continuing) it
returns and has plausible return values.

Looking into libusb I find that it uses poll(2) internally.

Is select(2) supposed to work with libusb fd'?

Should I rather use poll(2)?  (I do like select more -- more BSDish).

Best regards
Peer Stritzinger
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"