comparison src/mac.c @ 48740:b45c19284d24

sys_select: Call mac_check_for_quit_char every second while blocking sys_read: Use sys_select to test for input first before calling read to allow sys_select to test for quit_char.
author Steven Tamm <steventamm@mac.com>
date Sun, 08 Dec 2002 05:58:34 +0000
parents 080b4586492b
children 0360bdd5a70b
comparison
equal deleted inserted replaced
48739:9f54273b7ff1 48740:b45c19284d24
2749 2749
2750 #ifdef MAC_OSX 2750 #ifdef MAC_OSX
2751 #undef select 2751 #undef select
2752 2752
2753 extern int inhibit_window_system; 2753 extern int inhibit_window_system;
2754 extern int noninteractive;
2754 2755
2755 /* When Emacs is started from the Finder, SELECT always immediately 2756 /* When Emacs is started from the Finder, SELECT always immediately
2756 returns as if input is present when file descriptor 0 is polled for 2757 returns as if input is present when file descriptor 0 is polled for
2757 input. Strangely, when Emacs is run as a GUI application from the 2758 input. Strangely, when Emacs is run as a GUI application from the
2758 command line, it blocks in the same situation. This `wrapper' of 2759 command line, it blocks in the same situation. This `wrapper' of
2765 SELECT_TYPE *efds; 2766 SELECT_TYPE *efds;
2766 struct timeval *timeout; 2767 struct timeval *timeout;
2767 { 2768 {
2768 if (!inhibit_window_system && rfds && FD_ISSET (0, rfds)) 2769 if (!inhibit_window_system && rfds && FD_ISSET (0, rfds))
2769 return 1; 2770 return 1;
2770 else 2771 else if (inhibit_window_system || noninteractive)
2771 return select (n, rfds, wfds, efds, timeout); 2772 return select(n, rfds, wfds, efds, timeout);
2773 else
2774 {
2775 EMACS_TIME end_time, now;
2776
2777 EMACS_GET_TIME (end_time);
2778 if (timeout)
2779 EMACS_ADD_TIME (end_time, end_time, *timeout);
2780
2781 do
2782 {
2783 int r;
2784 EMACS_TIME one_second;
2785
2786 EMACS_SET_SECS (one_second, 1);
2787 EMACS_SET_USECS (one_second, 0);
2788
2789 if ((r = select (n, rfds, wfds, efds, &one_second)) > 0)
2790 return r;
2791
2792 mac_check_for_quit_char();
2793
2794 EMACS_GET_TIME (now);
2795 EMACS_SUB_TIME (now, end_time, now);
2796 }
2797 while (!timeout || !EMACS_TIME_NEG_P (now));
2798
2799 return 0;
2800 }
2801 }
2802
2803 #undef read
2804 int sys_read (fds, buf, nbyte)
2805 int fds;
2806 char *buf;
2807 unsigned int nbyte;
2808 {
2809 SELECT_TYPE rfds;
2810 EMACS_TIME one_second;
2811 int r;
2812
2813 /* Use select to block on IO while still checking for quit_char */
2814 if (!inhibit_window_system && !noninteractive)
2815 {
2816 FD_ZERO (&rfds);
2817 FD_SET (fds, &rfds);
2818 if (sys_select (fds+1, &rfds, 0, 0, NULL) < 0)
2819 return -1;
2820 }
2821
2822 return read (fds, buf, nbyte);
2772 } 2823 }
2773 2824
2774 2825
2775 /* Set up environment variables so that Emacs can correctly find its 2826 /* Set up environment variables so that Emacs can correctly find its
2776 support files when packaged as an application bundle. Directories 2827 support files when packaged as an application bundle. Directories