summaryrefslogtreecommitdiff
path: root/libusb/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'libusb/io.c')
-rw-r--r--libusb/io.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/libusb/io.c b/libusb/io.c
index 39285e7..90590ef 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -582,6 +582,10 @@ while (user_has_not_requested_exit)
*
* \section pollmain The more advanced option
*
+ * \note This functionality is currently only available on Unix-like platforms.
+ * On Windows, libusb_get_pollfds() simply returns NULL. Exposing event sources
+ * on Windows will require some further thought and design.
+ *
* In more advanced applications, you will already have a main loop which
* is monitoring other event sources: network sockets, X11 events, mouse
* movements, etc. Through exposing a set of file descriptors, libusb is
@@ -1177,7 +1181,9 @@ out:
* \param iso_packets number of isochronous packet descriptors to allocate
* \returns a newly allocated transfer, or NULL on error
*/
-API_EXPORTED struct libusb_transfer* LIBUSB_CALL libusb_alloc_transfer(int iso_packets)
+DEFAULT_VISIBILITY
+struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(
+ int iso_packets)
{
size_t os_alloc_size = usbi_backend->transfer_priv_size
+ (usbi_backend->add_iso_packet_size * iso_packets);
@@ -1212,7 +1218,7 @@ API_EXPORTED struct libusb_transfer* LIBUSB_CALL libusb_alloc_transfer(int iso_p
*
* \param transfer the transfer to free
*/
-API_EXPORTED void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer)
+void API_EXPORTED libusb_free_transfer(struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer;
if (!transfer)
@@ -1236,7 +1242,7 @@ API_EXPORTED void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *trans
* \returns LIBUSB_ERROR_BUSY if the transfer has already been submitted.
* \returns another LIBUSB_ERROR code on other failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer)
+int API_EXPORTED libusb_submit_transfer(struct libusb_transfer *transfer)
{
struct libusb_context *ctx = TRANSFER_CTX(transfer);
struct usbi_transfer *itransfer =
@@ -1292,7 +1298,7 @@ out:
* cancelled.
* \returns a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer)
+int API_EXPORTED libusb_cancel_transfer(struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer =
__LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
@@ -1464,7 +1470,7 @@ int usbi_handle_transfer_cancellation(struct usbi_transfer *transfer)
* \returns 1 if the lock was not obtained (i.e. another thread holds the lock)
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx)
+int API_EXPORTED libusb_try_lock_events(libusb_context *ctx)
{
int r;
USBI_GET_CONTEXT(ctx);
@@ -1505,7 +1511,7 @@ API_EXPORTED int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_lock_events(libusb_context *ctx)
+void API_EXPORTED libusb_lock_events(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_mutex_lock(&ctx->events_lock);
@@ -1520,7 +1526,7 @@ API_EXPORTED void LIBUSB_CALL libusb_lock_events(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx)
+void API_EXPORTED libusb_unlock_events(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
ctx->event_handler_active = 0;
@@ -1555,7 +1561,7 @@ API_EXPORTED void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx)
* \returns 0 if this thread must give up the events lock
* \see \ref fullstory "Multi-threaded I/O: the full story"
*/
-API_EXPORTED int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx)
+int API_EXPORTED libusb_event_handling_ok(libusb_context *ctx)
{
int r;
USBI_GET_CONTEXT(ctx);
@@ -1583,7 +1589,7 @@ API_EXPORTED int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx)
* \returns 0 if there are no threads currently handling events
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx)
+int API_EXPORTED libusb_event_handler_active(libusb_context *ctx)
{
int r;
USBI_GET_CONTEXT(ctx);
@@ -1620,7 +1626,7 @@ API_EXPORTED int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx)
+void API_EXPORTED libusb_lock_event_waiters(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_mutex_lock(&ctx->event_waiters_lock);
@@ -1631,7 +1637,7 @@ API_EXPORTED void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx)
* \param ctx the context to operate on, or NULL for the default context
* \see \ref mtasync
*/
-API_EXPORTED void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx)
+void API_EXPORTED libusb_unlock_event_waiters(libusb_context *ctx)
{
USBI_GET_CONTEXT(ctx);
usbi_mutex_unlock(&ctx->event_waiters_lock);
@@ -1662,7 +1668,7 @@ API_EXPORTED void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx)
* \returns 1 if the timeout expired
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
+int API_EXPORTED libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
{
struct timespec timeout;
int r;
@@ -1942,7 +1948,7 @@ static int get_next_timeout(libusb_context *ctx, struct timeval *tv,
* non-blocking mode
* \returns 0 on success, or a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
+int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
struct timeval *tv)
{
int r;
@@ -1996,7 +2002,7 @@ retry:
* \param ctx the context to operate on, or NULL for the default context
* \returns 0 on success, or a LIBUSB_ERROR code on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_handle_events(libusb_context *ctx)
+int API_EXPORTED libusb_handle_events(libusb_context *ctx)
{
struct timeval tv;
tv.tv_sec = 60;
@@ -2021,7 +2027,7 @@ API_EXPORTED int LIBUSB_CALL libusb_handle_events(libusb_context *ctx)
* \returns 0 on success, or a LIBUSB_ERROR code on failure
* \see \ref mtasync
*/
-API_EXPORTED int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
+int API_EXPORTED libusb_handle_events_locked(libusb_context *ctx,
struct timeval *tv)
{
int r;
@@ -2065,7 +2071,7 @@ API_EXPORTED int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
* or through regular activity on the file descriptors.
* \see \ref pollmain "Polling libusb file descriptors for event handling"
*/
-API_EXPORTED int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx)
+int API_EXPORTED libusb_pollfds_handle_timeouts(libusb_context *ctx)
{
#if defined(USBI_OS_HANDLES_TIMEOUT)
return 1;
@@ -2105,7 +2111,7 @@ API_EXPORTED int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx)
* \returns 0 if there are no pending timeouts, 1 if a timeout was returned,
* or LIBUSB_ERROR_OTHER on failure
*/
-API_EXPORTED int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
+int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx,
struct timeval *tv)
{
#ifndef USBI_OS_HANDLES_TIMEOUT
@@ -2191,7 +2197,7 @@ API_EXPORTED int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
* \param user_data User data to be passed back to callbacks (useful for
* passing context information)
*/
-API_EXPORTED void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
+void API_EXPORTED libusb_set_pollfd_notifiers(libusb_context *ctx,
libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
void *user_data)
{
@@ -2256,11 +2262,16 @@ void usbi_remove_pollfd(struct libusb_context *ctx, int fd)
* The returned list is NULL-terminated and should be freed with free() when
* done. The actual list contents must not be touched.
*
+ * As file descriptors are a Unix-specific concept, this function is not
+ * available on Windows and will always return NULL.
+ *
* \param ctx the context to operate on, or NULL for the default context
- * \returns a NULL-terminated list of libusb_pollfd structures, or NULL on
- * error
+ * \returns a NULL-terminated list of libusb_pollfd structures
+ * \returns NULL on error
+ * \returns NULL on platforms where the functionality is not available
*/
-API_EXPORTED const struct libusb_pollfd** LIBUSB_CALL libusb_get_pollfds(
+DEFAULT_VISIBILITY
+const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
libusb_context *ctx)
{
#ifndef OS_WINDOWS
@@ -2286,8 +2297,6 @@ out:
usbi_mutex_unlock(&ctx->pollfds_lock);
return (const struct libusb_pollfd **) ret;
#else
- usbi_err(ctx, "external polling of libusb's internal descriptors "\
- "is not yet supported on Windows platforms");
return NULL;
#endif
}
@@ -2334,4 +2343,3 @@ void usbi_handle_disconnect(struct libusb_device_handle *handle)
}
}
-