3777 |
else |
else |
3778 |
seconds = NILP (process) ? -1 : 0; |
seconds = NILP (process) ? -1 : 0; |
3779 |
|
|
|
if (NILP (process)) |
|
|
XSETFASTINT (process, 0); |
|
|
|
|
3780 |
return |
return |
3781 |
(wait_reading_process_input (seconds, useconds, process, |
(wait_reading_process_input (seconds, useconds, 0, 0, |
3782 |
|
Qnil, |
3783 |
|
!NILP (process) ? XPROCESS (process) : NULL, |
3784 |
NILP (just_this_one) ? 0 : |
NILP (just_this_one) ? 0 : |
3785 |
!INTEGERP (just_this_one) ? -1 : -2) |
!INTEGERP (just_this_one) ? 1 : -1) |
3786 |
? Qt : Qnil); |
? Qt : Qnil); |
3787 |
} |
} |
3788 |
|
|
4009 |
1 to return when input is available, or |
1 to return when input is available, or |
4010 |
-1 meaning caller will actually read the input, so don't throw to |
-1 meaning caller will actually read the input, so don't throw to |
4011 |
the quit handler, or |
the quit handler, or |
4012 |
a cons cell, meaning wait until its car is non-nil |
|
4013 |
(and gobble terminal input into the buffer if any arrives), or |
DO_DISPLAY != 0 means redisplay should be done to show subprocess |
|
a process object, meaning wait until something arrives from that |
|
|
process. The return value is true iff we read some input from |
|
|
that process. |
|
|
|
|
|
If READ_KBD is a process object, DO_DISPLAY < 0 means handle only |
|
|
output from that process (suspending output from other processes) |
|
|
and DO_DISPLAY == -2 specifically means don't run any timers either. |
|
|
Otherwise, != 0 means redisplay should be done to show subprocess |
|
4014 |
output that arrives. |
output that arrives. |
4015 |
|
|
4016 |
If READ_KBD is a pointer to a struct Lisp_Process, then the |
If WAIT_FOR_CELL is a cons cell, wait until its car is non-nil |
4017 |
function returns true iff we received input from that process |
(and gobble terminal input into the buffer if any arrives). |
4018 |
before the timeout elapsed. |
|
4019 |
|
If WAIT_PROC is specified, wait until something arrives from that |
4020 |
|
process. The return value is true iff we read some input from |
4021 |
|
that process. |
4022 |
|
|
4023 |
|
If JUST_WAIT_PROC is non-nil, handle only output from WAIT_PROC |
4024 |
|
(suspending output from other processes). A negative value |
4025 |
|
means don't run any timers either. |
4026 |
|
|
4027 |
|
If WAIT_PROC is specified, then the function returns true iff we |
4028 |
|
received input from that process before the timeout elapsed. |
4029 |
Otherwise, return true iff we received input from any process. */ |
Otherwise, return true iff we received input from any process. */ |
4030 |
|
|
4031 |
int |
int |
4032 |
wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) |
wait_reading_process_input (time_limit, microsecs, read_kbd, do_display, |
4033 |
int time_limit, microsecs; |
wait_for_cell, wait_proc, just_wait_proc) |
4034 |
Lisp_Object read_kbd; |
int time_limit, microsecs, read_kbd, do_display; |
4035 |
int do_display; |
Lisp_Object wait_for_cell; |
4036 |
|
struct Lisp_Process *wait_proc; |
4037 |
|
int just_wait_proc; |
4038 |
{ |
{ |
4039 |
register int channel, nfds; |
register int channel, nfds; |
4040 |
SELECT_TYPE Available; |
SELECT_TYPE Available; |
4044 |
Lisp_Object proc; |
Lisp_Object proc; |
4045 |
EMACS_TIME timeout, end_time; |
EMACS_TIME timeout, end_time; |
4046 |
int wait_channel = -1; |
int wait_channel = -1; |
|
struct Lisp_Process *wait_proc = 0; |
|
|
int just_wait_proc = 0; |
|
4047 |
int got_some_input = 0; |
int got_some_input = 0; |
4048 |
/* Either nil or a cons cell, the car of which is of interest and |
/* Either nil or a cons cell, the car of which is of interest and |
4049 |
may be changed outside of this routine. */ |
may be changed outside of this routine. */ |
|
Lisp_Object wait_for_cell = Qnil; |
|
4050 |
int saved_waiting_for_user_input_p = waiting_for_user_input_p; |
int saved_waiting_for_user_input_p = waiting_for_user_input_p; |
4051 |
|
|
4052 |
FD_ZERO (&Available); |
FD_ZERO (&Available); |
4053 |
FD_ZERO (&Connecting); |
FD_ZERO (&Connecting); |
4054 |
|
|
4055 |
/* If read_kbd is a process to watch, set wait_proc and wait_channel |
/* If wait_proc is a process to watch, set wait_channel accordingly. */ |
4056 |
accordingly. */ |
if (wait_proc != NULL) |
4057 |
if (PROCESSP (read_kbd)) |
wait_channel = XINT (wait_proc->infd); |
|
{ |
|
|
wait_proc = XPROCESS (read_kbd); |
|
|
wait_channel = XINT (wait_proc->infd); |
|
|
XSETFASTINT (read_kbd, 0); |
|
|
if (do_display < 0) |
|
|
{ |
|
|
just_wait_proc = do_display; |
|
|
do_display = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
/* If waiting for non-nil in a cell, record where. */ |
|
|
if (CONSP (read_kbd)) |
|
|
{ |
|
|
wait_for_cell = read_kbd; |
|
|
XSETFASTINT (read_kbd, 0); |
|
|
} |
|
4058 |
|
|
4059 |
waiting_for_user_input_p = XINT (read_kbd); |
waiting_for_user_input_p = read_kbd; |
4060 |
|
|
4061 |
/* Since we may need to wait several times, |
/* Since we may need to wait several times, |
4062 |
compute the absolute time to return at. */ |
compute the absolute time to return at. */ |
4084 |
/* If calling from keyboard input, do not quit |
/* If calling from keyboard input, do not quit |
4085 |
since we want to return C-g as an input character. |
since we want to return C-g as an input character. |
4086 |
Otherwise, do pending quit if requested. */ |
Otherwise, do pending quit if requested. */ |
4087 |
if (XINT (read_kbd) >= 0) |
if (read_kbd >= 0) |
4088 |
QUIT; |
QUIT; |
4089 |
#ifdef SYNC_INPUT |
#ifdef SYNC_INPUT |
4090 |
else if (interrupt_input_pending) |
else if (interrupt_input_pending) |
4122 |
the wait is supposed to be short, |
the wait is supposed to be short, |
4123 |
and those callers cannot handle running arbitrary Lisp code here. */ |
and those callers cannot handle running arbitrary Lisp code here. */ |
4124 |
if (NILP (wait_for_cell) |
if (NILP (wait_for_cell) |
4125 |
&& just_wait_proc != -2) |
&& just_wait_proc >= 0) |
4126 |
{ |
{ |
4127 |
EMACS_TIME timer_delay; |
EMACS_TIME timer_delay; |
4128 |
|
|
4150 |
while (!detect_input_pending ()); |
while (!detect_input_pending ()); |
4151 |
|
|
4152 |
/* If there is unread keyboard input, also return. */ |
/* If there is unread keyboard input, also return. */ |
4153 |
if (XINT (read_kbd) != 0 |
if (read_kbd != 0 |
4154 |
&& requeued_events_pending_p ()) |
&& requeued_events_pending_p ()) |
4155 |
break; |
break; |
4156 |
|
|
4178 |
It is important that we do this before checking for process |
It is important that we do this before checking for process |
4179 |
activity. If we get a SIGCHLD after the explicit checks for |
activity. If we get a SIGCHLD after the explicit checks for |
4180 |
process activity, timeout is the only way we will know. */ |
process activity, timeout is the only way we will know. */ |
4181 |
if (XINT (read_kbd) < 0) |
if (read_kbd < 0) |
4182 |
set_waiting_for_input (&timeout); |
set_waiting_for_input (&timeout); |
4183 |
|
|
4184 |
/* If status of something has changed, and no input is |
/* If status of something has changed, and no input is |
4258 |
|
|
4259 |
/* Wait till there is something to do */ |
/* Wait till there is something to do */ |
4260 |
|
|
4261 |
if (just_wait_proc) |
if (wait_proc && just_wait_proc) |
4262 |
{ |
{ |
4263 |
|
if (XINT (wait_proc->infd) < 0) /* Terminated */ |
4264 |
|
break; |
4265 |
FD_SET (XINT (wait_proc->infd), &Available); |
FD_SET (XINT (wait_proc->infd), &Available); |
4266 |
check_connect = check_delay = 0; |
check_connect = check_delay = 0; |
4267 |
} |
} |
4272 |
} |
} |
4273 |
else |
else |
4274 |
{ |
{ |
4275 |
if (! XINT (read_kbd)) |
if (! read_kbd) |
4276 |
Available = non_keyboard_wait_mask; |
Available = non_keyboard_wait_mask; |
4277 |
else |
else |
4278 |
Available = input_wait_mask; |
Available = input_wait_mask; |
4289 |
{ |
{ |
4290 |
clear_waiting_for_input (); |
clear_waiting_for_input (); |
4291 |
redisplay_preserve_echo_area (11); |
redisplay_preserve_echo_area (11); |
4292 |
if (XINT (read_kbd) < 0) |
if (read_kbd < 0) |
4293 |
set_waiting_for_input (&timeout); |
set_waiting_for_input (&timeout); |
4294 |
} |
} |
4295 |
|
|
4296 |
no_avail = 0; |
no_avail = 0; |
4297 |
if (XINT (read_kbd) && detect_input_pending ()) |
if (read_kbd && detect_input_pending ()) |
4298 |
{ |
{ |
4299 |
nfds = 0; |
nfds = 0; |
4300 |
no_avail = 1; |
no_avail = 1; |
4414 |
And on hpux, since we turn off polling in wait_reading_process_input, |
And on hpux, since we turn off polling in wait_reading_process_input, |
4415 |
it might never get read at all if we don't spend much time |
it might never get read at all if we don't spend much time |
4416 |
outside of wait_reading_process_input. */ |
outside of wait_reading_process_input. */ |
4417 |
if (XINT (read_kbd) && interrupt_input |
if (read_kbd && interrupt_input |
4418 |
&& keyboard_bit_set (&Available) |
&& keyboard_bit_set (&Available) |
4419 |
&& input_polling_used ()) |
&& input_polling_used ()) |
4420 |
kill (getpid (), SIGALRM); |
kill (getpid (), SIGALRM); |
4424 |
/* If there is any, return immediately |
/* If there is any, return immediately |
4425 |
to give it higher priority than subprocesses */ |
to give it higher priority than subprocesses */ |
4426 |
|
|
4427 |
if (XINT (read_kbd) != 0) |
if (read_kbd != 0) |
4428 |
{ |
{ |
4429 |
int old_timers_run = timers_run; |
int old_timers_run = timers_run; |
4430 |
struct buffer *old_buffer = current_buffer; |
struct buffer *old_buffer = current_buffer; |
4449 |
} |
} |
4450 |
|
|
4451 |
/* If there is unread keyboard input, also return. */ |
/* If there is unread keyboard input, also return. */ |
4452 |
if (XINT (read_kbd) != 0 |
if (read_kbd != 0 |
4453 |
&& requeued_events_pending_p ()) |
&& requeued_events_pending_p ()) |
4454 |
break; |
break; |
4455 |
|
|
4460 |
That would causes delays in pasting selections, for example. |
That would causes delays in pasting selections, for example. |
4461 |
|
|
4462 |
(We used to do this only if wait_for_cell.) */ |
(We used to do this only if wait_for_cell.) */ |
4463 |
if (XINT (read_kbd) == 0 && detect_input_pending ()) |
if (read_kbd == 0 && detect_input_pending ()) |
4464 |
{ |
{ |
4465 |
swallow_events (do_display); |
swallow_events (do_display); |
4466 |
#if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */ |
#if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */ |
4479 |
In that case, there really is no input and no SIGIO, |
In that case, there really is no input and no SIGIO, |
4480 |
but select says there is input. */ |
but select says there is input. */ |
4481 |
|
|
4482 |
if (XINT (read_kbd) && interrupt_input |
if (read_kbd && interrupt_input |
4483 |
&& keyboard_bit_set (&Available) && ! noninteractive) |
&& keyboard_bit_set (&Available) && ! noninteractive) |
4484 |
kill (getpid (), SIGIO); |
kill (getpid (), SIGIO); |
4485 |
#endif |
#endif |
4489 |
|
|
4490 |
/* If checking input just got us a size-change event from X, |
/* If checking input just got us a size-change event from X, |
4491 |
obey it now if we should. */ |
obey it now if we should. */ |
4492 |
if (XINT (read_kbd) || ! NILP (wait_for_cell)) |
if (read_kbd || ! NILP (wait_for_cell)) |
4493 |
do_pending_window_change (0); |
do_pending_window_change (0); |
4494 |
|
|
4495 |
/* Check for data from a process. */ |
/* Check for data from a process. */ |
4664 |
/* If calling from keyboard input, do not quit |
/* If calling from keyboard input, do not quit |
4665 |
since we want to return C-g as an input character. |
since we want to return C-g as an input character. |
4666 |
Otherwise, do pending quit if requested. */ |
Otherwise, do pending quit if requested. */ |
4667 |
if (XINT (read_kbd) >= 0) |
if (read_kbd >= 0) |
4668 |
{ |
{ |
4669 |
/* Prevent input_pending from remaining set if we quit. */ |
/* Prevent input_pending from remaining set if we quit. */ |
4670 |
clear_input_pending (); |
clear_input_pending (); |
5311 |
that may allow the program |
that may allow the program |
5312 |
to finish doing output and read more. */ |
to finish doing output and read more. */ |
5313 |
{ |
{ |
|
Lisp_Object zero; |
|
5314 |
int offset = 0; |
int offset = 0; |
5315 |
|
|
5316 |
#ifdef BROKEN_PTY_READ_AFTER_EAGAIN |
#ifdef BROKEN_PTY_READ_AFTER_EAGAIN |
5345 |
else if (STRINGP (object)) |
else if (STRINGP (object)) |
5346 |
offset = buf - SDATA (object); |
offset = buf - SDATA (object); |
5347 |
|
|
|
XSETFASTINT (zero, 0); |
|
5348 |
#ifdef EMACS_HAS_USECS |
#ifdef EMACS_HAS_USECS |
5349 |
wait_reading_process_input (0, 20000, zero, 0); |
wait_reading_process_input (0, 20000, 0, 0, Qnil, NULL, 0); |
5350 |
#else |
#else |
5351 |
wait_reading_process_input (1, 0, zero, 0); |
wait_reading_process_input (1, 0, 0, 0, Qnil, NULL, 0); |
5352 |
#endif |
#endif |
5353 |
|
|
5354 |
if (BUFFERP (object)) |
if (BUFFERP (object)) |
6870 |
1 to return when input is available, or |
1 to return when input is available, or |
6871 |
-1 means caller will actually read the input, so don't throw to |
-1 means caller will actually read the input, so don't throw to |
6872 |
the quit handler. |
the quit handler. |
6873 |
a cons cell, meaning wait until its car is non-nil |
|
6874 |
(and gobble terminal input into the buffer if any arrives), or |
see full version for other parameters. We know that wait_proc will |
6875 |
We know that read_kbd will never be a Lisp_Process, since |
always be NULL, since `subprocesses' isn't defined. |
|
`subprocesses' isn't defined. |
|
6876 |
|
|
6877 |
do_display != 0 means redisplay should be done to show subprocess |
do_display != 0 means redisplay should be done to show subprocess |
6878 |
output that arrives. |
output that arrives. |
6880 |
Return true iff we received input from any process. */ |
Return true iff we received input from any process. */ |
6881 |
|
|
6882 |
int |
int |
6883 |
wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) |
wait_reading_process_input (time_limit, microsecs, read_kbd, do_display, |
6884 |
int time_limit, microsecs; |
wait_for_cell, wait_proc, just_wait_proc) |
6885 |
Lisp_Object read_kbd; |
int time_limit, microsecs, read_kbd, do_display; |
6886 |
int do_display; |
Lisp_Object wait_for_cell; |
6887 |
|
struct Lisp_Process *wait_proc; |
6888 |
|
int just_wait_proc; |
6889 |
{ |
{ |
6890 |
register int nfds; |
register int nfds; |
6891 |
EMACS_TIME end_time, timeout; |
EMACS_TIME end_time, timeout; |
6892 |
SELECT_TYPE waitchannels; |
SELECT_TYPE waitchannels; |
6893 |
int xerrno; |
int xerrno; |
|
/* Either nil or a cons cell, the car of which is of interest and |
|
|
may be changed outside of this routine. */ |
|
|
Lisp_Object wait_for_cell; |
|
|
|
|
|
wait_for_cell = Qnil; |
|
|
|
|
|
/* If waiting for non-nil in a cell, record where. */ |
|
|
if (CONSP (read_kbd)) |
|
|
{ |
|
|
wait_for_cell = read_kbd; |
|
|
XSETFASTINT (read_kbd, 0); |
|
|
} |
|
6894 |
|
|
6895 |
/* What does time_limit really mean? */ |
/* What does time_limit really mean? */ |
6896 |
if (time_limit || microsecs) |
if (time_limit || microsecs) |
6913 |
/* If calling from keyboard input, do not quit |
/* If calling from keyboard input, do not quit |
6914 |
since we want to return C-g as an input character. |
since we want to return C-g as an input character. |
6915 |
Otherwise, do pending quit if requested. */ |
Otherwise, do pending quit if requested. */ |
6916 |
if (XINT (read_kbd) >= 0) |
if (read_kbd >= 0) |
6917 |
QUIT; |
QUIT; |
6918 |
|
|
6919 |
/* Exit now if the cell we're waiting for became non-nil. */ |
/* Exit now if the cell we're waiting for became non-nil. */ |
6964 |
while (!detect_input_pending ()); |
while (!detect_input_pending ()); |
6965 |
|
|
6966 |
/* If there is unread keyboard input, also return. */ |
/* If there is unread keyboard input, also return. */ |
6967 |
if (XINT (read_kbd) != 0 |
if (read_kbd != 0 |
6968 |
&& requeued_events_pending_p ()) |
&& requeued_events_pending_p ()) |
6969 |
break; |
break; |
6970 |
|
|
6982 |
|
|
6983 |
/* Cause C-g and alarm signals to take immediate action, |
/* Cause C-g and alarm signals to take immediate action, |
6984 |
and cause input available signals to zero out timeout. */ |
and cause input available signals to zero out timeout. */ |
6985 |
if (XINT (read_kbd) < 0) |
if (read_kbd < 0) |
6986 |
set_waiting_for_input (&timeout); |
set_waiting_for_input (&timeout); |
6987 |
|
|
6988 |
/* Wait till there is something to do. */ |
/* Wait till there is something to do. */ |
6989 |
|
|
6990 |
if (! XINT (read_kbd) && NILP (wait_for_cell)) |
if (! read_kbd && NILP (wait_for_cell)) |
6991 |
FD_ZERO (&waitchannels); |
FD_ZERO (&waitchannels); |
6992 |
else |
else |
6993 |
FD_SET (0, &waitchannels); |
FD_SET (0, &waitchannels); |
6998 |
{ |
{ |
6999 |
clear_waiting_for_input (); |
clear_waiting_for_input (); |
7000 |
redisplay_preserve_echo_area (15); |
redisplay_preserve_echo_area (15); |
7001 |
if (XINT (read_kbd) < 0) |
if (read_kbd < 0) |
7002 |
set_waiting_for_input (&timeout); |
set_waiting_for_input (&timeout); |
7003 |
} |
} |
7004 |
|
|
7005 |
if (XINT (read_kbd) && detect_input_pending ()) |
if (read_kbd && detect_input_pending ()) |
7006 |
{ |
{ |
7007 |
nfds = 0; |
nfds = 0; |
7008 |
FD_ZERO (&waitchannels); |
FD_ZERO (&waitchannels); |
7038 |
kill (getpid (), SIGIO); |
kill (getpid (), SIGIO); |
7039 |
#endif |
#endif |
7040 |
#ifdef SIGIO |
#ifdef SIGIO |
7041 |
if (XINT (read_kbd) && interrupt_input && (waitchannels & 1)) |
if (read_kbd && interrupt_input && (waitchannels & 1)) |
7042 |
kill (getpid (), SIGIO); |
kill (getpid (), SIGIO); |
7043 |
#endif |
#endif |
7044 |
|
|
7045 |
/* Check for keyboard input */ |
/* Check for keyboard input */ |
7046 |
|
|
7047 |
if ((XINT (read_kbd) != 0) |
if (read_kbd |
7048 |
&& detect_input_pending_run_timers (do_display)) |
&& detect_input_pending_run_timers (do_display)) |
7049 |
{ |
{ |
7050 |
swallow_events (do_display); |
swallow_events (do_display); |
7053 |
} |
} |
7054 |
|
|
7055 |
/* If there is unread keyboard input, also return. */ |
/* If there is unread keyboard input, also return. */ |
7056 |
if (XINT (read_kbd) != 0 |
if (read_kbd |
7057 |
&& requeued_events_pending_p ()) |
&& requeued_events_pending_p ()) |
7058 |
break; |
break; |
7059 |
|
|