Mercurial > emacs
comparison src/process.c @ 650:39f0e62a8511
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Tue, 19 May 1992 05:22:52 +0000 |
parents | 70b112526394 |
children | 681c352bbf30 |
comparison
equal
deleted
inserted
replaced
649:61deba7b73b6 | 650:39f0e62a8511 |
---|---|
1585 seconds = -1; | 1585 seconds = -1; |
1586 else | 1586 else |
1587 seconds = 0; | 1587 seconds = 0; |
1588 } | 1588 } |
1589 | 1589 |
1590 if (NILP (proc)) | |
1591 XFASTINT (proc) = 0; | |
1592 | |
1590 return | 1593 return |
1591 (wait_reading_process_input (seconds, useconds, | 1594 (wait_reading_process_input (seconds, useconds, proc, 0) |
1592 (NILP (proc) | |
1593 ? XPROCESS (get_process (proc)) : 0), 0) | |
1594 ? Qt : Qnil); | 1595 ? Qt : Qnil); |
1595 } | 1596 } |
1596 | 1597 |
1597 /* This variable is different from waiting_for_input in keyboard.c. | 1598 /* This variable is different from waiting_for_input in keyboard.c. |
1598 It is used to communicate to a lisp process-filter/sentinel (via the | 1599 It is used to communicate to a lisp process-filter/sentinel (via the |
1608 time_limit is: | 1609 time_limit is: |
1609 timeout in seconds, or | 1610 timeout in seconds, or |
1610 zero for no limit, or | 1611 zero for no limit, or |
1611 -1 means gobble data immediately available but don't wait for any. | 1612 -1 means gobble data immediately available but don't wait for any. |
1612 | 1613 |
1613 read_kbd is: | 1614 read_kbd is a lisp value: |
1614 0 to ignore keyboard input, or | 1615 0 to ignore keyboard input, or |
1615 1 to return when input is available, or | 1616 1 to return when input is available, or |
1616 -1 means caller will actually read the input, so don't throw to | 1617 -1 means caller will actually read the input, so don't throw to |
1617 the quit handler, or | 1618 the quit handler, or |
1618 a pointer to a struct Lisp_Process, meaning wait until something | 1619 a process object, meaning wait until something arrives from that |
1619 arrives from that process. The return value is true iff we read | 1620 process. The return value is true iff we read some input from |
1620 some input from that process. | 1621 that process. |
1621 | 1622 |
1622 do_display != 0 means redisplay should be done to show subprocess | 1623 do_display != 0 means redisplay should be done to show subprocess |
1623 output that arrives. | 1624 output that arrives. |
1624 | 1625 |
1625 If read_kbd is a pointer to a struct Lisp_Process, then the | 1626 If read_kbd is a pointer to a struct Lisp_Process, then the |
1626 function returns true iff we received input from that process | 1627 function returns true iff we received input from that process |
1627 before the timeout elapsed. | 1628 before the timeout elapsed. |
1628 Otherwise, return true iff we recieved input from any process. */ | 1629 Otherwise, return true iff we recieved input from any process. */ |
1629 | 1630 |
1630 wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | 1631 wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) |
1631 int time_limit, microsecs, read_kbd, do_display; | 1632 int time_limit, microsecs; |
1633 Lisp_Object read_kbd; | |
1634 int do_display; | |
1632 { | 1635 { |
1633 register int channel, nfds, m; | 1636 register int channel, nfds, m; |
1634 static SELECT_TYPE Available; | 1637 static SELECT_TYPE Available; |
1635 int xerrno; | 1638 int xerrno; |
1636 Lisp_Object proc; | 1639 Lisp_Object proc; |
1640 struct Lisp_Process *wait_proc = 0; | 1643 struct Lisp_Process *wait_proc = 0; |
1641 int got_some_input = 0; | 1644 int got_some_input = 0; |
1642 | 1645 |
1643 FD_ZERO (&Available); | 1646 FD_ZERO (&Available); |
1644 | 1647 |
1645 /* Detect when read_kbd is really the address of a Lisp_Process. */ | 1648 /* If read_kbd is a process to watch, set wait_proc and wait_channel |
1646 if (read_kbd > 10 || read_kbd < -1) | 1649 accordingly. */ |
1647 { | 1650 if (XTYPE (read_kbd) == Lisp_Process) |
1648 wait_proc = (struct Lisp_Process *) read_kbd; | 1651 { |
1652 wait_proc = XPROCESS (read_kbd); | |
1649 wait_channel = XFASTINT (wait_proc->infd); | 1653 wait_channel = XFASTINT (wait_proc->infd); |
1650 read_kbd = 0; | 1654 XFASTINT (read_kbd) = 0; |
1651 } | 1655 } |
1652 | 1656 |
1653 waiting_for_user_input_p = read_kbd; | 1657 waiting_for_user_input_p = XINT (read_kbd); |
1654 | 1658 |
1655 /* Since we may need to wait several times, | 1659 /* Since we may need to wait several times, |
1656 compute the absolute time to return at. */ | 1660 compute the absolute time to return at. */ |
1657 if (time_limit || microsecs) | 1661 if (time_limit || microsecs) |
1658 { | 1662 { |
1664 while (1) | 1668 while (1) |
1665 { | 1669 { |
1666 /* If calling from keyboard input, do not quit | 1670 /* If calling from keyboard input, do not quit |
1667 since we want to return C-g as an input character. | 1671 since we want to return C-g as an input character. |
1668 Otherwise, do pending quit if requested. */ | 1672 Otherwise, do pending quit if requested. */ |
1669 if (read_kbd >= 0) | 1673 if (XINT (read_kbd) >= 0) |
1670 QUIT; | 1674 QUIT; |
1671 | 1675 |
1672 /* If status of something has changed, and no input is available, | 1676 /* If status of something has changed, and no input is available, |
1673 notify the user of the change right away */ | 1677 notify the user of the change right away */ |
1674 if (update_tick != process_tick && do_display) | 1678 if (update_tick != process_tick && do_display) |
1708 EMACS_SET_SECS_USECS (timeout, 100000, 0); | 1712 EMACS_SET_SECS_USECS (timeout, 100000, 0); |
1709 } | 1713 } |
1710 | 1714 |
1711 /* Cause C-g and alarm signals to take immediate action, | 1715 /* Cause C-g and alarm signals to take immediate action, |
1712 and cause input available signals to zero out timeout */ | 1716 and cause input available signals to zero out timeout */ |
1713 if (read_kbd < 0) | 1717 if (XINT (read_kbd) < 0) |
1714 set_waiting_for_input (&timeout); | 1718 set_waiting_for_input (&timeout); |
1715 | 1719 |
1716 /* Wait till there is something to do */ | 1720 /* Wait till there is something to do */ |
1717 | 1721 |
1718 Available = input_wait_mask; | 1722 Available = input_wait_mask; |
1719 if (!read_kbd) | 1723 if (! XINT (read_kbd)) |
1720 FD_CLR (0, &Available); | 1724 FD_CLR (0, &Available); |
1721 | 1725 |
1722 /* If screen size has changed or the window is newly mapped, | 1726 /* If screen size has changed or the window is newly mapped, |
1723 redisplay now, before we start to wait. There is a race | 1727 redisplay now, before we start to wait. There is a race |
1724 condition here; if a SIGIO arrives between now and the select | 1728 condition here; if a SIGIO arrives between now and the select |
1725 and indicates that a screen is trashed, we lose. */ | 1729 and indicates that a screen is trashed, we lose. */ |
1726 if (screen_garbaged) | 1730 if (screen_garbaged) |
1727 redisplay_preserve_echo_area (); | 1731 redisplay_preserve_echo_area (); |
1728 | 1732 |
1729 if (read_kbd && detect_input_pending ()) | 1733 if (XINT (read_kbd) && detect_input_pending ()) |
1730 nfds = 0; | 1734 nfds = 0; |
1731 else | 1735 else |
1732 nfds = select (MAXDESC, &Available, 0, 0, &timeout); | 1736 nfds = select (MAXDESC, &Available, 0, 0, &timeout); |
1733 | 1737 |
1734 xerrno = errno; | 1738 xerrno = errno; |
1777 | 1781 |
1778 /* Check for keyboard input */ | 1782 /* Check for keyboard input */ |
1779 /* If there is any, return immediately | 1783 /* If there is any, return immediately |
1780 to give it higher priority than subprocesses */ | 1784 to give it higher priority than subprocesses */ |
1781 | 1785 |
1782 if (read_kbd && detect_input_pending ()) | 1786 if (XINT (read_kbd) && detect_input_pending ()) |
1783 break; | 1787 break; |
1784 | 1788 |
1785 #ifdef SIGIO | 1789 #ifdef SIGIO |
1786 /* If we think we have keyboard input waiting, but didn't get SIGIO | 1790 /* If we think we have keyboard input waiting, but didn't get SIGIO |
1787 go read it. This can happen with X on BSD after logging out. | 1791 go read it. This can happen with X on BSD after logging out. |
1788 In that case, there really is no input and no SIGIO, | 1792 In that case, there really is no input and no SIGIO, |
1789 but select says there is input. */ | 1793 but select says there is input. */ |
1790 | 1794 |
1791 /* | 1795 /* |
1792 if (read_kbd && interrupt_input && (Available & fileno (stdin))) | 1796 if (XINT (read_kbd) && interrupt_input && (Available & fileno (stdin))) |
1793 */ | 1797 */ |
1794 if (read_kbd && interrupt_input && (FD_ISSET (fileno (stdin), &Available))) | 1798 if (XINT (read_kbd) && interrupt_input && (FD_ISSET (fileno (stdin), &Available))) |
1795 kill (0, SIGIO); | 1799 kill (0, SIGIO); |
1796 #endif | 1800 #endif |
1797 | 1801 |
1798 #ifdef vipc | 1802 #ifdef vipc |
1799 /* Check for connection from other process */ | 1803 /* Check for connection from other process */ |
1808 if (! wait_proc) | 1812 if (! wait_proc) |
1809 got_some_input |= nfds > 0; | 1813 got_some_input |= nfds > 0; |
1810 | 1814 |
1811 /* If checking input just got us a size-change event from X, | 1815 /* If checking input just got us a size-change event from X, |
1812 obey it now if we should. */ | 1816 obey it now if we should. */ |
1813 if (read_kbd) | 1817 if (XINT (read_kbd)) |
1814 do_pending_window_change (); | 1818 do_pending_window_change (); |
1815 | 1819 |
1816 /* Check for data from a process or a command channel */ | 1820 /* Check for data from a process or a command channel */ |
1817 for (channel = FIRST_PROC_DESC; channel < MAXDESC; channel++) | 1821 for (channel = FIRST_PROC_DESC; channel < MAXDESC; channel++) |
1818 { | 1822 { |
1919 } /* end while exit conditions not met */ | 1923 } /* end while exit conditions not met */ |
1920 | 1924 |
1921 /* If calling from keyboard input, do not quit | 1925 /* If calling from keyboard input, do not quit |
1922 since we want to return C-g as an input character. | 1926 since we want to return C-g as an input character. |
1923 Otherwise, do pending quit if requested. */ | 1927 Otherwise, do pending quit if requested. */ |
1924 if (read_kbd >= 0) | 1928 if (XINT (read_kbd) >= 0) |
1925 { | 1929 { |
1926 /* Prevent input_pending from remaining set if we quit. */ | 1930 /* Prevent input_pending from remaining set if we quit. */ |
1927 clear_input_pending (); | 1931 clear_input_pending (); |
1928 QUIT; | 1932 QUIT; |
1929 } | 1933 } |
2132 buf += rv; | 2136 buf += rv; |
2133 len -= rv; | 2137 len -= rv; |
2134 /* Allow input from processes between bursts of sending. | 2138 /* Allow input from processes between bursts of sending. |
2135 Otherwise things may get stopped up. */ | 2139 Otherwise things may get stopped up. */ |
2136 if (len > 0) | 2140 if (len > 0) |
2137 wait_reading_process_input (-1, 0, 0, 0); | 2141 { |
2142 Lisp_Object zero; | |
2143 | |
2144 XFASTINT (zero) = 0; | |
2145 wait_reading_process_input (-1, 0, zero, 0); | |
2146 } | |
2138 } | 2147 } |
2139 #endif | 2148 #endif |
2140 else | 2149 else |
2141 { | 2150 { |
2142 XPROCESS (proc)->raw_status_low = Qnil; | 2151 XPROCESS (proc)->raw_status_low = Qnil; |
2899 time_limit is: | 2908 time_limit is: |
2900 timeout in seconds, or | 2909 timeout in seconds, or |
2901 zero for no limit, or | 2910 zero for no limit, or |
2902 -1 means gobble data immediately available but don't wait for any. | 2911 -1 means gobble data immediately available but don't wait for any. |
2903 | 2912 |
2904 read_kbd is: | 2913 read_kbd is a Lisp_Object: |
2905 0 to ignore keyboard input, or | 2914 0 to ignore keyboard input, or |
2906 1 to return when input is available, or | 2915 1 to return when input is available, or |
2907 -1 means caller will actually read the input, so don't throw to | 2916 -1 means caller will actually read the input, so don't throw to |
2908 the quit handler. | 2917 the quit handler. |
2909 We know that read_kbd will never be a Lisp_Process, since | 2918 We know that read_kbd will never be a Lisp_Process, since |
2910 `subprocesses' isn't defined. | 2919 `subprocesses' isn't defined. |
2911 | 2920 |
2912 do_display != 0 means redisplay should be done to show subprocess | 2921 do_display != 0 means redisplay should be done to show subprocess |
2913 output that arrives. This version of the function ignores it. | 2922 output that arrives. This version of the function ignores it. |
2914 | 2923 |
2915 If read_kbd is a pointer to a struct Lisp_Process, then the | 2924 Return true iff we recieved input from any process. */ |
2916 function returns true iff we received input from that process | |
2917 before the timeout elapsed. | |
2918 Otherwise, return true iff we recieved input from any process. */ | |
2919 | 2925 |
2920 int | 2926 int |
2921 wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | 2927 wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) |
2922 int time_limit, microsecs, read_kbd, do_display; | 2928 int time_limit, microsecs; |
2929 Lisp_Object read_kbd; | |
2930 int do_display; | |
2923 { | 2931 { |
2924 EMACS_TIME end_time, timeout, *timeout_p; | 2932 EMACS_TIME end_time, timeout, *timeout_p; |
2925 int waitchannels; | 2933 int waitchannels; |
2926 | 2934 |
2927 /* What does time_limit really mean? */ | 2935 /* What does time_limit really mean? */ |
2950 | 2958 |
2951 for (;;) | 2959 for (;;) |
2952 { | 2960 { |
2953 int nfds; | 2961 int nfds; |
2954 | 2962 |
2955 waitchannels = read_kbd ? 1 : 0; | 2963 waitchannels = XINT (read_kbd) ? 1 : 0; |
2956 | 2964 |
2957 /* If calling from keyboard input, do not quit | 2965 /* If calling from keyboard input, do not quit |
2958 since we want to return C-g as an input character. | 2966 since we want to return C-g as an input character. |
2959 Otherwise, do pending quit if requested. */ | 2967 Otherwise, do pending quit if requested. */ |
2960 if (read_kbd >= 0) | 2968 if (XINT (read_kbd) >= 0) |
2961 QUIT; | 2969 QUIT; |
2962 | 2970 |
2963 if (timeout_p) | 2971 if (timeout_p) |
2964 { | 2972 { |
2965 EMACS_GET_TIME (*timeout_p); | 2973 EMACS_GET_TIME (*timeout_p); |
2968 break; | 2976 break; |
2969 } | 2977 } |
2970 | 2978 |
2971 /* Cause C-g and alarm signals to take immediate action, | 2979 /* Cause C-g and alarm signals to take immediate action, |
2972 and cause input available signals to zero out timeout. */ | 2980 and cause input available signals to zero out timeout. */ |
2973 if (read_kbd < 0) | 2981 if (XINT (read_kbd) < 0) |
2974 set_waiting_for_input (&timeout); | 2982 set_waiting_for_input (&timeout); |
2975 | 2983 |
2976 /* If a screen has been newly mapped and needs updating, | 2984 /* If a screen has been newly mapped and needs updating, |
2977 reprocess its display stuff. */ | 2985 reprocess its display stuff. */ |
2978 if (screen_garbaged) | 2986 if (screen_garbaged) |
2979 redisplay_preserve_echo_area (); | 2987 redisplay_preserve_echo_area (); |
2980 | 2988 |
2981 if (read_kbd && detect_input_pending ()) | 2989 if (XINT (read_kbd) && detect_input_pending ()) |
2982 nfds = 0; | 2990 nfds = 0; |
2983 else | 2991 else |
2984 nfds = select (1, &waitchannels, 0, 0, timeout_p); | 2992 nfds = select (1, &waitchannels, 0, 0, timeout_p); |
2985 | 2993 |
2986 /* Make C-g and alarm signals set flags again */ | 2994 /* Make C-g and alarm signals set flags again */ |
2999 #ifdef sun | 3007 #ifdef sun |
3000 else if (nfds > 0 && (waitchannels & 1) && interrupt_input) | 3008 else if (nfds > 0 && (waitchannels & 1) && interrupt_input) |
3001 /* System sometimes fails to deliver SIGIO. */ | 3009 /* System sometimes fails to deliver SIGIO. */ |
3002 kill (getpid (), SIGIO); | 3010 kill (getpid (), SIGIO); |
3003 #endif | 3011 #endif |
3004 if (read_kbd && interrupt_input && (waitchannels & 1)) | 3012 if (XINT (read_kbd) && interrupt_input && (waitchannels & 1)) |
3005 kill (0, SIGIO); | 3013 kill (0, SIGIO); |
3006 | 3014 |
3007 /* If we have timed out (nfds == 0) or found some input (nfds > 0), | 3015 /* If we have timed out (nfds == 0) or found some input (nfds > 0), |
3008 we should exit. */ | 3016 we should exit. */ |
3009 if (nfds >= 0) | 3017 if (nfds >= 0) |