[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 3e6eaa3cb2e: Update Android port
|
From: |
Po Lu |
|
Subject: |
feature/android 3e6eaa3cb2e: Update Android port |
|
Date: |
Wed, 12 Jul 2023 04:45:38 -0400 (EDT) |
branch: feature/android
commit 3e6eaa3cb2eea00d83561458d8eb1e24b77d28cb
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Update Android port
* src/android.c (android_run_select_thread): Correctly return
the set of ready read and write descriptors on __ANDROID_API__ <
16 systems.
(android_select): Clear the set of ready file descriptors if
events from the event queue are present despite pselect failing.
---
src/android.c | 54 +++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 43 insertions(+), 11 deletions(-)
diff --git a/src/android.c b/src/android.c
index 4e9897f4648..065f90b3463 100644
--- a/src/android.c
+++ b/src/android.c
@@ -349,7 +349,7 @@ android_run_select_thread (void *data)
int rc;
#if __ANDROID_API__ < 16
int nfds;
- fd_set readfds, writefds;
+ fd_set readfds;
char byte;
#else
sigset_t signals, waitset;
@@ -386,18 +386,30 @@ android_run_select_thread (void *data)
nfds = select_pipe[0] + 1;
FD_SET (select_pipe[0], &readfds);
- rc = pselect (nfds, &readfds, &writefds,
+ rc = pselect (nfds, &readfds,
+ android_pselect_writefds,
android_pselect_exceptfds,
android_pselect_timeout,
NULL);
- /* Subtract 1 from rc if writefds contains the select pipe. */
- if (FD_ISSET (select_pipe[0], &writefds))
- rc -= 1;
+ /* Subtract 1 from rc if readfds contains the select pipe, and
+ also remove it from that set. */
+
+ if (rc != -1 && FD_ISSET (select_pipe[0], &readfds))
+ {
+ rc -= 1;
+ FD_CLR (fd, &readfds);
+
+ /* If no file descriptors aside from the select pipe are
+ ready, then pretend that an error has occurred. */
+ if (!rc)
+ rc = -1;
+ }
+
+ /* Save the read file descriptor set back again. */
- /* Save the writefds back again. */
- if (android_pselect_writefds)
- *android_pselect_writefds = writefds;
+ if (android_pselect_readfds)
+ *android_pselect_readfds = readfds;
android_pselect_rc = rc;
pthread_mutex_unlock (&event_queue.select_mutex);
@@ -795,13 +807,33 @@ android_select (int nfds, fd_set *readfds, fd_set
*writefds,
nfds_return = 1;
pthread_mutex_unlock (&event_queue.mutex);
- /* Add the return value of pselect. */
+ /* Add the return value of pselect if it has also found ready file
+ descriptors. */
+
if (android_pselect_rc >= 0)
nfds_return += android_pselect_rc;
-
- if (!nfds_return && android_pselect_rc < 0)
+ else if (!nfds_return)
+ /* If pselect was interrupted and nfds_return is 0 (meaning that
+ no events have been read), indicate that an error has taken
+ place. */
nfds_return = android_pselect_rc;
+ if ((android_pselect_rc < 0) && nfds_return >= 0)
+ {
+ /* Clear the file descriptor sets if events will be delivered
+ but no file descriptors have become ready to prevent the
+ caller from misinterpreting a non-zero return value. */
+
+ if (readfds)
+ FD_ZERO (readfds);
+
+ if (writefds)
+ FD_ZERO (writefds);
+
+ if (exceptfds)
+ FD_ZERO (exceptfds);
+ }
+
/* This is to shut up process.c when pselect gets EINTR. */
if (nfds_return < 0)
errno = EINTR;
| [Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/android 3e6eaa3cb2e: Update Android port,
Po Lu <=