summaryrefslogtreecommitdiff
path: root/libusb/os/poll_windows.c
diff options
context:
space:
mode:
Diffstat (limited to 'libusb/os/poll_windows.c')
-rw-r--r--libusb/os/poll_windows.c66
1 files changed, 44 insertions, 22 deletions
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c
index 02e7584..5102fd3 100644
--- a/libusb/os/poll_windows.c
+++ b/libusb/os/poll_windows.c
@@ -76,12 +76,6 @@
// which should give the app an opportunity to resubmit a new fd set.
//#define DYNAMIC_FDS
-#if defined(DEBUG_POLL_WINDOWS)
-#define poll_dbg usbi_dbg
-#else
-#define poll_dbg(...)
-#endif
-
#if defined(_PREFAST_)
#pragma warning(disable:28719)
#endif
@@ -303,7 +297,9 @@ __inline void _init_read_marker(int index)
}
} else {
// We got some sync I/O. We'll pretend it's async and set overlapped manually
- poll_dbg("marker readout completed before exit!");
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("marker readout completed before exit!");
+#endif
if (!HasOverlappedIoCompleted(poll_fd[index].overlapped)) {
usbi_warn(NULL, "completed I/O still flagged as pending");
poll_fd[index].overlapped->Internal = 0;
@@ -352,7 +348,9 @@ int usbi_pipe(int filedes[2])
goto out1;
}
filedes[0] = _open_osfhandle((intptr_t)handle[0], _O_RDONLY);
- poll_dbg("filedes[0] = %d", filedes[0]);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("filedes[0] = %d", filedes[0]);
+#endif
// Write end of the pipe
handle[1] = CreateFileA(pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
@@ -362,7 +360,9 @@ int usbi_pipe(int filedes[2])
goto out2;
}
filedes[1] = _open_osfhandle((intptr_t)handle[1], _O_WRONLY);
- poll_dbg("filedes[1] = %d", filedes[1]);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("filedes[1] = %d", filedes[1]);
+#endif
// Create an OVERLAPPED for each end
overlapped0->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -694,12 +694,16 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
goto poll_exit;
}
- poll_dbg("fd[%d]=%d (overlapped = %p) got events %04X", i, poll_fd[index].fd, poll_fd[index].overlapped, fds[i].events);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("fd[%d]=%d (overlapped = %p) got events %04X", i, poll_fd[index].fd, poll_fd[index].overlapped, fds[i].events);
+#endif
// The following macro only works if overlapped I/O was reported pending
if ( (HasOverlappedIoCompleted(poll_fd[index].overlapped))
|| (poll_fd[index].completed_synchronously) ) {
- poll_dbg(" completed");
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg(" completed");
+#endif
// checks above should ensure this works:
fds[i].revents = fds[i].events;
triggered++;
@@ -737,7 +741,9 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
}
}
usbi_mutex_unlock(&new_fd_mutex);
- poll_dbg("dynamic_fds: added %d extra handles", nb_extra_handles);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("dynamic_fds: added %d extra handles", nb_extra_handles);
+#endif
#endif
// If nothing was triggered, wait on all fds that require it
@@ -747,11 +753,13 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
handles_to_wait_on[nb_handles_to_wait_on++] = fd_update;
nb_extra_handles++;
#endif
+#if defined(DEBUG_POLL_WINDOWS)
if (timeout < 0) {
- poll_dbg("starting infinite wait for %d handles...", (int)nb_handles_to_wait_on);
+ usbi_dbg("starting infinite wait for %d handles...", (int)nb_handles_to_wait_on);
} else {
- poll_dbg("starting %d ms wait for %d handles...", timeout, (int)nb_handles_to_wait_on);
+ usbi_dbg("starting %d ms wait for %d handles...", timeout, (int)nb_handles_to_wait_on);
}
+#endif
ret = WaitForMultipleObjects(nb_handles_to_wait_on, handles_to_wait_on,
FALSE, (timeout<0)?INFINITE:(DWORD)timeout);
object_index = ret-WAIT_OBJECT_0;
@@ -759,16 +767,20 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
#if defined(DYNAMIC_FDS)
if ((DWORD)object_index >= (nb_handles_to_wait_on-nb_extra_handles)) {
// Detected fd update => flag a poll interruption
+#if defined(DEBUG_POLL_WINDOWS)
if ((DWORD)object_index == (nb_handles_to_wait_on-1))
- poll_dbg(" dynamic_fds: fd_update event");
+ usbi_dbg(" dynamic_fds: fd_update event");
else
- poll_dbg(" dynamic_fds: new fd I/O event");
+ usbi_dbg(" dynamic_fds: new fd I/O event");
+#endif
errno = EINTR;
triggered = -1;
goto poll_exit;
}
#endif
- poll_dbg(" completed after wait");
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg(" completed after wait");
+#endif
i = handle_to_index[object_index];
index = _fd_to_index_and_lock(fds[i].fd);
fds[i].revents = fds[i].events;
@@ -777,7 +789,9 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
LeaveCriticalSection(&_poll_fd[index].mutex);
}
} else if (ret == WAIT_TIMEOUT) {
- poll_dbg(" timed out");
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg(" timed out");
+#endif
triggered = 0; // 0 = timeout
} else {
errno = EIO;
@@ -867,7 +881,9 @@ ssize_t usbi_write(int fd, const void *buf, size_t count)
cancel_io(index);
}
- poll_dbg("writing %d bytes to fd=%d", count, poll_fd[index].fd);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("writing %d bytes to fd=%d", count, poll_fd[index].fd);
+#endif
reset_overlapped(poll_fd[index].overlapped);
if (!WriteFile(poll_fd[index].handle, buf, (DWORD)count, &wr_count, poll_fd[index].overlapped)) {
@@ -960,7 +976,9 @@ ssize_t usbi_read(int fd, void *buf, size_t count)
}
}
- poll_dbg("count = %d, rd_count(marker) = %d", count, (int)rd_count);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("count = %d, rd_count(marker) = %d", count, (int)rd_count);
+#endif
// We should have our marker by now
if (rd_count != 1) {
@@ -992,10 +1010,14 @@ ssize_t usbi_read(int fd, void *buf, size_t count)
}
// If ReadFile completed synchronously, we're fine too
- poll_dbg("rd_count(supplementary ) = %d", (int)rd_count);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("rd_count(supplementary ) = %d", (int)rd_count);
+#endif
if ((rd_count+1) != count) {
- poll_dbg("wanted %d-1, got %d", count, (int)rd_count);
+#if defined(DEBUG_POLL_WINDOWS)
+ usbi_dbg("wanted %d-1, got %d", count, (int)rd_count);
+#endif
errno = EIO;
goto out;
}