diff options
| author | Po Lu | 2023-07-12 16:45:24 +0800 |
|---|---|---|
| committer | Po Lu | 2023-07-12 16:45:24 +0800 |
| commit | 3e6eaa3cb2eea00d83561458d8eb1e24b77d28cb (patch) | |
| tree | 5628788df613a7a49d90bc28c703ea1a6de53f74 /src/android.c | |
| parent | 7a6c7bac6a775a8175edd583018f990625630b17 (diff) | |
| download | emacs-3e6eaa3cb2eea00d83561458d8eb1e24b77d28cb.tar.gz emacs-3e6eaa3cb2eea00d83561458d8eb1e24b77d28cb.zip | |
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.
Diffstat (limited to 'src/android.c')
| -rw-r--r-- | src/android.c | 54 |
1 files 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) | |||
| 349 | int rc; | 349 | int rc; |
| 350 | #if __ANDROID_API__ < 16 | 350 | #if __ANDROID_API__ < 16 |
| 351 | int nfds; | 351 | int nfds; |
| 352 | fd_set readfds, writefds; | 352 | fd_set readfds; |
| 353 | char byte; | 353 | char byte; |
| 354 | #else | 354 | #else |
| 355 | sigset_t signals, waitset; | 355 | sigset_t signals, waitset; |
| @@ -386,18 +386,30 @@ android_run_select_thread (void *data) | |||
| 386 | nfds = select_pipe[0] + 1; | 386 | nfds = select_pipe[0] + 1; |
| 387 | FD_SET (select_pipe[0], &readfds); | 387 | FD_SET (select_pipe[0], &readfds); |
| 388 | 388 | ||
| 389 | rc = pselect (nfds, &readfds, &writefds, | 389 | rc = pselect (nfds, &readfds, |
| 390 | android_pselect_writefds, | ||
| 390 | android_pselect_exceptfds, | 391 | android_pselect_exceptfds, |
| 391 | android_pselect_timeout, | 392 | android_pselect_timeout, |
| 392 | NULL); | 393 | NULL); |
| 393 | 394 | ||
| 394 | /* Subtract 1 from rc if writefds contains the select pipe. */ | 395 | /* Subtract 1 from rc if readfds contains the select pipe, and |
| 395 | if (FD_ISSET (select_pipe[0], &writefds)) | 396 | also remove it from that set. */ |
| 396 | rc -= 1; | 397 | |
| 398 | if (rc != -1 && FD_ISSET (select_pipe[0], &readfds)) | ||
| 399 | { | ||
| 400 | rc -= 1; | ||
| 401 | FD_CLR (fd, &readfds); | ||
| 402 | |||
| 403 | /* If no file descriptors aside from the select pipe are | ||
| 404 | ready, then pretend that an error has occurred. */ | ||
| 405 | if (!rc) | ||
| 406 | rc = -1; | ||
| 407 | } | ||
| 408 | |||
| 409 | /* Save the read file descriptor set back again. */ | ||
| 397 | 410 | ||
| 398 | /* Save the writefds back again. */ | 411 | if (android_pselect_readfds) |
| 399 | if (android_pselect_writefds) | 412 | *android_pselect_readfds = readfds; |
| 400 | *android_pselect_writefds = writefds; | ||
| 401 | 413 | ||
| 402 | android_pselect_rc = rc; | 414 | android_pselect_rc = rc; |
| 403 | pthread_mutex_unlock (&event_queue.select_mutex); | 415 | pthread_mutex_unlock (&event_queue.select_mutex); |
| @@ -795,13 +807,33 @@ android_select (int nfds, fd_set *readfds, fd_set *writefds, | |||
| 795 | nfds_return = 1; | 807 | nfds_return = 1; |
| 796 | pthread_mutex_unlock (&event_queue.mutex); | 808 | pthread_mutex_unlock (&event_queue.mutex); |
| 797 | 809 | ||
| 798 | /* Add the return value of pselect. */ | 810 | /* Add the return value of pselect if it has also found ready file |
| 811 | descriptors. */ | ||
| 812 | |||
| 799 | if (android_pselect_rc >= 0) | 813 | if (android_pselect_rc >= 0) |
| 800 | nfds_return += android_pselect_rc; | 814 | nfds_return += android_pselect_rc; |
| 801 | 815 | else if (!nfds_return) | |
| 802 | if (!nfds_return && android_pselect_rc < 0) | 816 | /* If pselect was interrupted and nfds_return is 0 (meaning that |
| 817 | no events have been read), indicate that an error has taken | ||
| 818 | place. */ | ||
| 803 | nfds_return = android_pselect_rc; | 819 | nfds_return = android_pselect_rc; |
| 804 | 820 | ||
| 821 | if ((android_pselect_rc < 0) && nfds_return >= 0) | ||
| 822 | { | ||
| 823 | /* Clear the file descriptor sets if events will be delivered | ||
| 824 | but no file descriptors have become ready to prevent the | ||
| 825 | caller from misinterpreting a non-zero return value. */ | ||
| 826 | |||
| 827 | if (readfds) | ||
| 828 | FD_ZERO (readfds); | ||
| 829 | |||
| 830 | if (writefds) | ||
| 831 | FD_ZERO (writefds); | ||
| 832 | |||
| 833 | if (exceptfds) | ||
| 834 | FD_ZERO (exceptfds); | ||
| 835 | } | ||
| 836 | |||
| 805 | /* This is to shut up process.c when pselect gets EINTR. */ | 837 | /* This is to shut up process.c when pselect gets EINTR. */ |
| 806 | if (nfds_return < 0) | 838 | if (nfds_return < 0) |
| 807 | errno = EINTR; | 839 | errno = EINTR; |