Lines Matching +full:transfer +full:- +full:function
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
58 if (pollfd->entry.tqe_prev != NULL) in libusb10_add_pollfd()
64 pollfd->pdev = pdev; in libusb10_add_pollfd()
65 pollfd->pollfd.fd = fd; in libusb10_add_pollfd()
66 pollfd->pollfd.events = events; in libusb10_add_pollfd()
69 TAILQ_INSERT_TAIL(&ctx->pollfds, pollfd, entry); in libusb10_add_pollfd()
72 if (ctx->fd_added_cb) in libusb10_add_pollfd()
73 ctx->fd_added_cb(fd, events, ctx->fd_cb_user_data); in libusb10_add_pollfd()
82 if (pollfd->entry.tqe_prev == NULL) in libusb10_remove_pollfd()
86 TAILQ_REMOVE(&ctx->pollfds, pollfd, entry); in libusb10_remove_pollfd()
87 pollfd->entry.tqe_prev = NULL; in libusb10_remove_pollfd()
90 if (ctx->fd_removed_cb) in libusb10_remove_pollfd()
91 ctx->fd_removed_cb(pollfd->pollfd.fd, ctx->fd_cb_user_data); in libusb10_remove_pollfd()
94 /* This function must be called locked */
114 TAILQ_FOREACH(pfd, &ctx->pollfds, entry) in libusb10_handle_events_sub()
125 TAILQ_FOREACH(pfd, &ctx->pollfds, entry) { in libusb10_handle_events_sub()
126 fds[i].fd = pfd->pollfd.fd; in libusb10_handle_events_sub()
127 fds[i].events = pfd->pollfd.events; in libusb10_handle_events_sub()
129 ppdev[i] = pfd->pdev; in libusb10_handle_events_sub()
130 if (pfd->pdev != NULL) in libusb10_handle_events_sub()
131 libusb_get_device(pfd->pdev)->refcnt++; in libusb10_handle_events_sub()
136 timeout = -1; in libusb10_handle_events_sub()
138 timeout = (tv->tv_sec * 1000) + ((tv->tv_usec + 999) / 1000); in libusb10_handle_events_sub()
144 if ((err == -1) && (errno == EINTR)) in libusb10_handle_events_sub()
175 if (ppdev[i]->is_opened) in libusb10_handle_events_sub()
176 dev->device_is_gone = 1; in libusb10_handle_events_sub()
179 libusb10_remove_pollfd(dev->ctx, &dev->dev_poll); in libusb10_handle_events_sub()
203 while ((sxfer = TAILQ_FIRST(&ctx->tr_done))) { in libusb10_handle_events_sub()
206 TAILQ_REMOVE(&ctx->tr_done, sxfer, entry); in libusb10_handle_events_sub()
207 sxfer->entry.tqe_prev = NULL; in libusb10_handle_events_sub()
209 ctx->tr_done_ref++; in libusb10_handle_events_sub()
216 /* Allow the callback to free the transfer itself. */ in libusb10_handle_events_sub()
217 flags = uxfer->flags; in libusb10_handle_events_sub()
219 if (uxfer->callback != NULL) in libusb10_handle_events_sub()
220 (uxfer->callback) (uxfer); in libusb10_handle_events_sub()
222 /* Check if the USB transfer should be automatically freed. */ in libusb10_handle_events_sub()
228 ctx->tr_done_ref--; in libusb10_handle_events_sub()
229 ctx->tr_done_gen++; in libusb10_handle_events_sub()
233 pthread_cond_broadcast(&ctx->ctx_cond); in libusb10_handle_events_sub()
253 err = (ctx->ctx_handler != NO_THREAD); in libusb_try_lock_events()
257 ctx->ctx_handler = pthread_self(); in libusb_try_lock_events()
267 if (ctx->ctx_handler == NO_THREAD) in libusb_lock_events()
268 ctx->ctx_handler = pthread_self(); in libusb_lock_events()
275 if (ctx->ctx_handler == pthread_self()) { in libusb_unlock_events()
276 ctx->ctx_handler = NO_THREAD; in libusb_unlock_events()
277 pthread_cond_broadcast(&ctx->ctx_cond); in libusb_unlock_events()
286 return (ctx->ctx_handler == pthread_self()); in libusb_event_handling_ok()
293 return (ctx->ctx_handler != NO_THREAD); in libusb_event_handler_active()
320 pthread_cond_wait(&ctx->ctx_cond, in libusb_wait_for_event()
321 &ctx->ctx_lock); in libusb_wait_for_event()
323 if (ctx->ctx_handler == NO_THREAD) in libusb_wait_for_event()
324 ctx->ctx_handler = pthread_self(); in libusb_wait_for_event()
335 ts.tv_sec += tv->tv_sec; in libusb_wait_for_event()
336 ts.tv_nsec += tv->tv_usec * 1000; in libusb_wait_for_event()
338 ts.tv_nsec -= 1000000000; in libusb_wait_for_event()
341 err = pthread_cond_timedwait(&ctx->ctx_cond, in libusb_wait_for_event()
342 &ctx->ctx_lock, &ts); in libusb_wait_for_event()
344 if (ctx->ctx_handler == NO_THREAD) in libusb_wait_for_event()
345 ctx->ctx_handler = pthread_self(); in libusb_wait_for_event()
432 ctx->fd_added_cb = added_cb; in libusb_set_pollfd_notifiers()
433 ctx->fd_removed_cb = removed_cb; in libusb_set_pollfd_notifiers()
434 ctx->fd_cb_user_data = user_data; in libusb_set_pollfd_notifiers()
449 TAILQ_FOREACH(pollfd, &ctx->pollfds, entry) in libusb_get_pollfds()
457 TAILQ_FOREACH(pollfd, &ctx->pollfds, entry) in libusb_get_pollfds()
458 ret[i++] = &pollfd->pollfd; in libusb_get_pollfds()
511 ctx = libusb_get_device(devh)->ctx; in libusb10_get_context_by_device_handle()
519 libusb10_do_transfer_cb(struct libusb_transfer *transfer) in libusb10_do_transfer_cb() argument
524 ctx = libusb10_get_context_by_device_handle(transfer->dev_handle); in libusb10_do_transfer_cb()
528 pdone = transfer->user_data; in libusb10_do_transfer_cb()
533 * TODO: Replace the following function. Allocating and freeing on a
534 * per-transfer basis is slow. --HPS
556 ctx = libusb_get_device(devh)->ctx; in libusb10_do_transfer()
558 xfer->dev_handle = devh; in libusb10_do_transfer()
559 xfer->endpoint = endpoint; in libusb10_do_transfer()
560 xfer->type = type; in libusb10_do_transfer()
561 xfer->timeout = timeout; in libusb10_do_transfer()
562 xfer->buffer = data; in libusb10_do_transfer()
563 xfer->length = length; in libusb10_do_transfer()
564 xfer->user_data = (void *)&done; in libusb10_do_transfer()
565 xfer->callback = libusb10_do_transfer_cb; in libusb10_do_transfer()
579 *transferred = xfer->actual_length; in libusb10_do_transfer()
581 switch (xfer->status) { in libusb10_do_transfer()
645 libusb_get_iso_packet_buffer(struct libusb_transfer *transfer, uint32_t off) in libusb_get_iso_packet_buffer() argument
650 if (transfer->num_iso_packets < 0) in libusb_get_iso_packet_buffer()
653 if (off >= (uint32_t)transfer->num_iso_packets) in libusb_get_iso_packet_buffer()
656 ptr = transfer->buffer; in libusb_get_iso_packet_buffer()
661 ptr += transfer->iso_packet_desc[n].length; in libusb_get_iso_packet_buffer()
667 libusb_get_iso_packet_buffer_simple(struct libusb_transfer *transfer, uint32_t off) in libusb_get_iso_packet_buffer_simple() argument
671 if (transfer->num_iso_packets < 0) in libusb_get_iso_packet_buffer_simple()
674 if (off >= (uint32_t)transfer->num_iso_packets) in libusb_get_iso_packet_buffer_simple()
677 ptr = transfer->buffer; in libusb_get_iso_packet_buffer_simple()
681 ptr += transfer->iso_packet_desc[0].length * off; in libusb_get_iso_packet_buffer_simple()
687 libusb_set_iso_packet_lengths(struct libusb_transfer *transfer, uint32_t length) in libusb_set_iso_packet_lengths() argument
691 if (transfer->num_iso_packets < 0) in libusb_set_iso_packet_lengths()
694 for (n = 0; n != transfer->num_iso_packets; n++) in libusb_set_iso_packet_lengths()
695 transfer->iso_packet_desc[n].length = length; in libusb_set_iso_packet_lengths()
699 libusb_control_transfer_get_data(struct libusb_transfer *transfer) in libusb_control_transfer_get_data() argument
701 if (transfer->buffer == NULL) in libusb_control_transfer_get_data()
704 return (transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE); in libusb_control_transfer_get_data()
708 libusb_control_transfer_get_setup(struct libusb_transfer *transfer) in libusb_control_transfer_get_setup() argument
710 return ((struct libusb_control_setup *)transfer->buffer); in libusb_control_transfer_get_setup()
721 req->bmRequestType = bmRequestType; in libusb_fill_control_setup()
722 req->bRequest = bRequest; in libusb_fill_control_setup()
723 req->wValue = htole16(wValue); in libusb_fill_control_setup()
724 req->wIndex = htole16(wIndex); in libusb_fill_control_setup()
725 req->wLength = htole16(wLength); in libusb_fill_control_setup()
729 libusb_fill_control_transfer(struct libusb_transfer *transfer, in libusb_fill_control_transfer() argument
736 transfer->dev_handle = devh; in libusb_fill_control_transfer()
737 transfer->endpoint = 0; in libusb_fill_control_transfer()
738 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL; in libusb_fill_control_transfer()
739 transfer->timeout = timeout; in libusb_fill_control_transfer()
740 transfer->buffer = buf; in libusb_fill_control_transfer()
742 transfer->length = LIBUSB_CONTROL_SETUP_SIZE in libusb_fill_control_transfer()
743 + le16toh(setup->wLength); in libusb_fill_control_transfer()
745 transfer->length = 0; in libusb_fill_control_transfer()
746 transfer->user_data = user_data; in libusb_fill_control_transfer()
747 transfer->callback = callback; in libusb_fill_control_transfer()
752 libusb_fill_bulk_transfer(struct libusb_transfer *transfer, in libusb_fill_bulk_transfer() argument
757 transfer->dev_handle = devh; in libusb_fill_bulk_transfer()
758 transfer->endpoint = endpoint; in libusb_fill_bulk_transfer()
759 transfer->type = LIBUSB_TRANSFER_TYPE_BULK; in libusb_fill_bulk_transfer()
760 transfer->timeout = timeout; in libusb_fill_bulk_transfer()
761 transfer->buffer = buf; in libusb_fill_bulk_transfer()
762 transfer->length = length; in libusb_fill_bulk_transfer()
763 transfer->user_data = user_data; in libusb_fill_bulk_transfer()
764 transfer->callback = callback; in libusb_fill_bulk_transfer()
768 libusb_fill_interrupt_transfer(struct libusb_transfer *transfer, in libusb_fill_interrupt_transfer() argument
773 transfer->dev_handle = devh; in libusb_fill_interrupt_transfer()
774 transfer->endpoint = endpoint; in libusb_fill_interrupt_transfer()
775 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT; in libusb_fill_interrupt_transfer()
776 transfer->timeout = timeout; in libusb_fill_interrupt_transfer()
777 transfer->buffer = buf; in libusb_fill_interrupt_transfer()
778 transfer->length = length; in libusb_fill_interrupt_transfer()
779 transfer->user_data = user_data; in libusb_fill_interrupt_transfer()
780 transfer->callback = callback; in libusb_fill_interrupt_transfer()
784 libusb_fill_iso_transfer(struct libusb_transfer *transfer, in libusb_fill_iso_transfer() argument
789 transfer->dev_handle = devh; in libusb_fill_iso_transfer()
790 transfer->endpoint = endpoint; in libusb_fill_iso_transfer()
791 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS; in libusb_fill_iso_transfer()
792 transfer->timeout = timeout; in libusb_fill_iso_transfer()
793 transfer->buffer = buf; in libusb_fill_iso_transfer()
794 transfer->length = length; in libusb_fill_iso_transfer()
795 transfer->num_iso_packets = npacket; in libusb_fill_iso_transfer()
796 transfer->user_data = user_data; in libusb_fill_iso_transfer()
797 transfer->callback = callback; in libusb_fill_iso_transfer()
817 libusb_transfer_set_stream_id(struct libusb_transfer *transfer, uint32_t stream_id) in libusb_transfer_set_stream_id() argument
821 if (transfer == NULL) in libusb_transfer_set_stream_id()
825 ((uint8_t *)transfer) - sizeof(*sxfer)); in libusb_transfer_set_stream_id()
828 sxfer->stream_id = stream_id; in libusb_transfer_set_stream_id()
832 libusb_transfer_get_stream_id(struct libusb_transfer *transfer) in libusb_transfer_get_stream_id() argument
836 if (transfer == NULL) in libusb_transfer_get_stream_id()
840 ((uint8_t *)transfer) - sizeof(*sxfer)); in libusb_transfer_get_stream_id()
843 return (sxfer->stream_id); in libusb_transfer_get_stream_id()