Lines Matching refs:h
296 static int usb_bulk_write(usb_handle* h, const void* data, int len) { in usb_bulk_write() argument
297 std::unique_lock<std::mutex> lock(h->mutex); in usb_bulk_write()
300 usbdevfs_urb* urb = &h->urb_out; in usb_bulk_write()
303 urb->endpoint = h->ep_out; in usb_bulk_write()
308 if (h->dead) { in usb_bulk_write()
313 if (TEMP_FAILURE_RETRY(ioctl(h->fd, USBDEVFS_SUBMITURB, urb)) == -1) { in usb_bulk_write()
317 h->urb_out_busy = true; in usb_bulk_write()
320 if (h->cv.wait_until(lock, now + 5s) == std::cv_status::timeout || h->dead) { in usb_bulk_write()
325 if (!h->urb_out_busy) { in usb_bulk_write()
335 static int usb_bulk_read(usb_handle* h, void* data, int len) { in usb_bulk_read() argument
336 std::unique_lock<std::mutex> lock(h->mutex); in usb_bulk_read()
339 usbdevfs_urb* urb = &h->urb_in; in usb_bulk_read()
342 urb->endpoint = h->ep_in; in usb_bulk_read()
347 if (h->dead) { in usb_bulk_read()
352 if (TEMP_FAILURE_RETRY(ioctl(h->fd, USBDEVFS_SUBMITURB, urb)) == -1) { in usb_bulk_read()
356 h->urb_in_busy = true; in usb_bulk_read()
359 h->reaper_thread = pthread_self(); in usb_bulk_read()
360 int fd = h->fd; in usb_bulk_read()
369 h->reaper_thread = 0; in usb_bulk_read()
370 if (h->dead) { in usb_bulk_read()
384 if (out == &h->urb_in) { in usb_bulk_read()
386 h->urb_in_busy = false; in usb_bulk_read()
393 if (out == &h->urb_out) { in usb_bulk_read()
395 h->urb_out_busy = false; in usb_bulk_read()
396 h->cv.notify_all(); in usb_bulk_read()
402 int usb_write(usb_handle *h, const void *_data, int len) in usb_write() argument
407 int n = usb_bulk_write(h, data, len); in usb_write()
413 if (h->zero_mask && !(len & h->zero_mask)) { in usb_write()
416 return usb_bulk_write(h, _data, 0); in usb_write()
423 int usb_read(usb_handle *h, void *_data, int len) in usb_read() argument
432 D("[ usb read %d fd = %d], path=%s", xfer, h->fd, h->path.c_str()); in usb_read()
433 n = usb_bulk_read(h, data, xfer); in usb_read()
434 D("[ usb read %d ] = %d, path=%s", xfer, n, h->path.c_str()); in usb_read()
436 if((errno == ETIMEDOUT) && (h->fd != -1)) { in usb_read()
457 void usb_kick(usb_handle* h) { in usb_kick() argument
458 std::lock_guard<std::mutex> lock(h->mutex); in usb_kick()
459 D("[ kicking %p (fd = %d) ]", h, h->fd); in usb_kick()
460 if (!h->dead) { in usb_kick()
461 h->dead = true; in usb_kick()
463 if (h->writeable) { in usb_kick()
468 if (h->reaper_thread) { in usb_kick()
469 pthread_kill(h->reaper_thread, SIGALRM); in usb_kick()
477 ioctl(h->fd, USBDEVFS_DISCARDURB, &h->urb_in); in usb_kick()
478 ioctl(h->fd, USBDEVFS_DISCARDURB, &h->urb_out); in usb_kick()
479 h->urb_in.status = -ENODEV; in usb_kick()
480 h->urb_out.status = -ENODEV; in usb_kick()
481 h->urb_in_busy = false; in usb_kick()
482 h->urb_out_busy = false; in usb_kick()
483 h->cv.notify_all(); in usb_kick()
485 unregister_usb_transport(h); in usb_kick()
490 int usb_close(usb_handle* h) { in usb_close() argument
492 g_usb_handles.remove(h); in usb_close()
494 D("-- usb close %p (fd = %d) --", h, h->fd); in usb_close()
496 delete h; in usb_close()