diff options
| author | Richard M. Stallman | 1994-10-25 09:48:44 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-10-25 09:48:44 +0000 |
| commit | a69281ffda6967bd2e3901fd72b319bbd276c1fe (patch) | |
| tree | f1417dfccdb413de4e9eebd8ec6a55379d4cf2ff /src/process.c | |
| parent | 61bd0e9ccd7510ec0dc5641347caaf0c7714483e (diff) | |
| download | emacs-a69281ffda6967bd2e3901fd72b319bbd276c1fe.tar.gz emacs-a69281ffda6967bd2e3901fd72b319bbd276c1fe.zip | |
Handle multiple keyboard input descriptors.
(non_keyboard_wait_mask): New variable.
(Fset_process_filter): Update non_keyboard_wait_mask
(create_process, Fopen_network_stream, deactivate_process):
(init_process, sigchld_handler): Likewise.
(wait_reading_process_input): Maybe use non_keyboard_wait_mask.
(add_keyboard_wait_descriptor):
Renamed from change_keyboard_wait_descriptor.
Clear the old descriptor's bit only the first call.
(delete_keyboard_wait_descriptor): New function.
(keyboard_bit_set): New function.
(wait_reading_process_input): Use keyboard_bit_set.
Start the loop over process descs from 0, and explicitly
ignore non-process input descs.
(init_process): Don't init keyboard_descriptor.
(keyboard_descriptor): Variable deleted.
(add_keyboard_wait_descriptor): Don't set keyboard_descriptor.
(delete_keyboard_wait_descriptor): New function.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 112 |
1 files changed, 86 insertions, 26 deletions
diff --git a/src/process.c b/src/process.c index e2c9f2e8787..2ac2a811410 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -222,15 +222,19 @@ static int update_tick; | |||
| 222 | #define POLL_FOR_INPUT | 222 | #define POLL_FOR_INPUT |
| 223 | #endif | 223 | #endif |
| 224 | 224 | ||
| 225 | /* Mask of bits indicating the descriptors that we wait for input on */ | 225 | /* Mask of bits indicating the descriptors that we wait for input on. */ |
| 226 | 226 | ||
| 227 | static SELECT_TYPE input_wait_mask; | 227 | static SELECT_TYPE input_wait_mask; |
| 228 | 228 | ||
| 229 | /* Mask that excludes keyboard input descriptor (s). */ | ||
| 230 | |||
| 231 | static SELECT_TYPE non_keyboard_wait_mask; | ||
| 232 | |||
| 229 | /* The largest descriptor currently in use for a process object. */ | 233 | /* The largest descriptor currently in use for a process object. */ |
| 230 | static int max_process_desc; | 234 | static int max_process_desc; |
| 231 | 235 | ||
| 232 | /* Descriptor to use for keyboard input. */ | 236 | /* The largest descriptor currently in use for keyboard input. */ |
| 233 | static int keyboard_descriptor; | 237 | static int max_keyboard_desc; |
| 234 | 238 | ||
| 235 | /* Nonzero means delete a process right away if it exits. */ | 239 | /* Nonzero means delete a process right away if it exits. */ |
| 236 | static int delete_exited_processes; | 240 | static int delete_exited_processes; |
| @@ -764,9 +768,15 @@ If the process has a filter, its buffer is not used for output.") | |||
| 764 | { | 768 | { |
| 765 | CHECK_PROCESS (proc, 0); | 769 | CHECK_PROCESS (proc, 0); |
| 766 | if (EQ (filter, Qt)) | 770 | if (EQ (filter, Qt)) |
| 767 | FD_CLR (XINT (XPROCESS (proc)->infd), &input_wait_mask); | 771 | { |
| 772 | FD_CLR (XINT (XPROCESS (proc)->infd), &input_wait_mask); | ||
| 773 | FD_CLR (XINT (XPROCESS (proc)->infd), &non_keyboard_wait_mask); | ||
| 774 | } | ||
| 768 | else if (EQ (XPROCESS (proc)->filter, Qt)) | 775 | else if (EQ (XPROCESS (proc)->filter, Qt)) |
| 769 | FD_SET (XINT (XPROCESS (proc)->infd), &input_wait_mask); | 776 | { |
| 777 | FD_SET (XINT (XPROCESS (proc)->infd), &input_wait_mask); | ||
| 778 | FD_SET (XINT (XPROCESS (proc)->infd), &non_keyboard_wait_mask); | ||
| 779 | } | ||
| 770 | XPROCESS (proc)->filter = filter; | 780 | XPROCESS (proc)->filter = filter; |
| 771 | return filter; | 781 | return filter; |
| 772 | } | 782 | } |
| @@ -1277,6 +1287,7 @@ create_process (process, new_argv, current_dir) | |||
| 1277 | #endif /* SIGCHLD */ | 1287 | #endif /* SIGCHLD */ |
| 1278 | 1288 | ||
| 1279 | FD_SET (inchannel, &input_wait_mask); | 1289 | FD_SET (inchannel, &input_wait_mask); |
| 1290 | FD_SET (inchannel, &non_keyboard_wait_mask); | ||
| 1280 | if (inchannel > max_process_desc) | 1291 | if (inchannel > max_process_desc) |
| 1281 | max_process_desc = inchannel; | 1292 | max_process_desc = inchannel; |
| 1282 | 1293 | ||
| @@ -1663,6 +1674,7 @@ Fourth arg SERVICE is name of the service desired, or an integer\n\ | |||
| 1663 | XSETINT (XPROCESS (proc)->outfd, outch); | 1674 | XSETINT (XPROCESS (proc)->outfd, outch); |
| 1664 | XPROCESS (proc)->status = Qrun; | 1675 | XPROCESS (proc)->status = Qrun; |
| 1665 | FD_SET (inch, &input_wait_mask); | 1676 | FD_SET (inch, &input_wait_mask); |
| 1677 | FD_SET (inch, &non_keyboard_wait_mask); | ||
| 1666 | if (inch > max_process_desc) | 1678 | if (inch > max_process_desc) |
| 1667 | max_process_desc = inch; | 1679 | max_process_desc = inch; |
| 1668 | 1680 | ||
| @@ -1702,6 +1714,7 @@ deactivate_process (proc) | |||
| 1702 | XSETINT (p->outfd, -1); | 1714 | XSETINT (p->outfd, -1); |
| 1703 | chan_process[inchannel] = Qnil; | 1715 | chan_process[inchannel] = Qnil; |
| 1704 | FD_CLR (inchannel, &input_wait_mask); | 1716 | FD_CLR (inchannel, &input_wait_mask); |
| 1717 | FD_CLR (inchannel, &non_keyboard_wait_mask); | ||
| 1705 | if (inchannel == max_process_desc) | 1718 | if (inchannel == max_process_desc) |
| 1706 | { | 1719 | { |
| 1707 | int i; | 1720 | int i; |
| @@ -1968,9 +1981,10 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 1968 | 1981 | ||
| 1969 | /* Wait till there is something to do */ | 1982 | /* Wait till there is something to do */ |
| 1970 | 1983 | ||
| 1971 | Available = input_wait_mask; | ||
| 1972 | if (! XINT (read_kbd) && wait_for_cell == 0) | 1984 | if (! XINT (read_kbd) && wait_for_cell == 0) |
| 1973 | FD_CLR (keyboard_descriptor, &Available); | 1985 | Available = non_keyboard_wait_mask; |
| 1986 | else | ||
| 1987 | Available = input_wait_mask; | ||
| 1974 | 1988 | ||
| 1975 | /* If frame size has changed or the window is newly mapped, | 1989 | /* If frame size has changed or the window is newly mapped, |
| 1976 | redisplay now, before we start to wait. There is a race | 1990 | redisplay now, before we start to wait. There is a race |
| @@ -2036,7 +2050,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 2036 | error("select error: %s", strerror (xerrno)); | 2050 | error("select error: %s", strerror (xerrno)); |
| 2037 | } | 2051 | } |
| 2038 | #if defined(sun) && !defined(USG5_4) | 2052 | #if defined(sun) && !defined(USG5_4) |
| 2039 | else if (nfds > 0 && FD_ISSET (keyboard_descriptor, &Available) | 2053 | else if (nfds > 0 && keyboard_bit_set (&Available) |
| 2040 | && interrupt_input) | 2054 | && interrupt_input) |
| 2041 | /* System sometimes fails to deliver SIGIO. | 2055 | /* System sometimes fails to deliver SIGIO. |
| 2042 | 2056 | ||
| @@ -2073,7 +2087,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 2073 | but select says there is input. */ | 2087 | but select says there is input. */ |
| 2074 | 2088 | ||
| 2075 | if (XINT (read_kbd) && interrupt_input | 2089 | if (XINT (read_kbd) && interrupt_input |
| 2076 | && (FD_ISSET (keyboard_descriptor, &Available))) | 2090 | && (keyboard_bit_set (&Available))) |
| 2077 | kill (0, SIGIO); | 2091 | kill (0, SIGIO); |
| 2078 | #endif | 2092 | #endif |
| 2079 | 2093 | ||
| @@ -2088,10 +2102,10 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) | |||
| 2088 | /* Check for data from a process. */ | 2102 | /* Check for data from a process. */ |
| 2089 | /* Really FIRST_PROC_DESC should be 0 on Unix, | 2103 | /* Really FIRST_PROC_DESC should be 0 on Unix, |
| 2090 | but this is safer in the short run. */ | 2104 | but this is safer in the short run. */ |
| 2091 | for (channel = keyboard_descriptor == 0 ? FIRST_PROC_DESC : 0; | 2105 | for (channel = 0; channel <= max_process_desc; channel++) |
| 2092 | channel <= max_process_desc; channel++) | ||
| 2093 | { | 2106 | { |
| 2094 | if (FD_ISSET (channel, &Available)) | 2107 | if (FD_ISSET (channel, &Available) |
| 2108 | && FD_ISSET (channel, &non_keyboard_wait_mask)) | ||
| 2095 | { | 2109 | { |
| 2096 | int nread; | 2110 | int nread; |
| 2097 | 2111 | ||
| @@ -3058,7 +3072,10 @@ sigchld_handler (signo) | |||
| 3058 | /* If process has terminated, stop waiting for its output. */ | 3072 | /* If process has terminated, stop waiting for its output. */ |
| 3059 | if (WIFSIGNALED (w) || WIFEXITED (w)) | 3073 | if (WIFSIGNALED (w) || WIFEXITED (w)) |
| 3060 | if (XINT (p->infd) >= 0) | 3074 | if (XINT (p->infd) >= 0) |
| 3061 | FD_CLR (XINT (p->infd), &input_wait_mask); | 3075 | { |
| 3076 | FD_CLR (XINT (p->infd), &input_wait_mask); | ||
| 3077 | FD_CLR (XINT (p->infd), &non_keyboard_wait_mask); | ||
| 3078 | } | ||
| 3062 | 3079 | ||
| 3063 | /* Tell wait_reading_process_input that it needs to wake up and | 3080 | /* Tell wait_reading_process_input that it needs to wake up and |
| 3064 | look around. */ | 3081 | look around. */ |
| @@ -3279,6 +3296,60 @@ status_notify () | |||
| 3279 | UNGCPRO; | 3296 | UNGCPRO; |
| 3280 | } | 3297 | } |
| 3281 | 3298 | ||
| 3299 | /* The first time this is called, assume keyboard input comes from DESC | ||
| 3300 | instead of from where we used to expect it. | ||
| 3301 | Subsequent calls mean assume input keyboard can come from DESC | ||
| 3302 | in addition to other places. */ | ||
| 3303 | |||
| 3304 | static int add_keyboard_wait_descriptor_called_flag; | ||
| 3305 | |||
| 3306 | void | ||
| 3307 | add_keyboard_wait_descriptor (desc) | ||
| 3308 | int desc; | ||
| 3309 | { | ||
| 3310 | if (! add_keyboard_wait_descriptor_called_flag) | ||
| 3311 | FD_CLR (0, &input_wait_mask); | ||
| 3312 | add_keyboard_wait_descriptor_called_flag = 1; | ||
| 3313 | FD_SET (desc, &input_wait_mask); | ||
| 3314 | if (desc > max_keyboard_desc) | ||
| 3315 | max_keyboard_desc = desc; | ||
| 3316 | } | ||
| 3317 | |||
| 3318 | /* From now on, do not expect DESC to give keyboard input. */ | ||
| 3319 | |||
| 3320 | void | ||
| 3321 | delete_keyboard_wait_descriptor (desc) | ||
| 3322 | int desc; | ||
| 3323 | { | ||
| 3324 | int fd; | ||
| 3325 | int lim = max_keyboard_desc; | ||
| 3326 | |||
| 3327 | FD_CLR (desc, &input_wait_mask); | ||
| 3328 | |||
| 3329 | if (desc == max_keyboard_desc) | ||
| 3330 | for (fd = 0; fd < lim; fd++) | ||
| 3331 | if (FD_ISSET (fd, &input_wait_mask) | ||
| 3332 | && !FD_ISSET (fd, &non_keyboard_wait_mask)) | ||
| 3333 | max_keyboard_desc = fd; | ||
| 3334 | } | ||
| 3335 | |||
| 3336 | /* Return nonzero if *MASK has a bit set | ||
| 3337 | that corresponds to one of the keyboard input descriptors. */ | ||
| 3338 | |||
| 3339 | int | ||
| 3340 | keyboard_bit_set (mask) | ||
| 3341 | SELECT_TYPE *mask; | ||
| 3342 | { | ||
| 3343 | int fd; | ||
| 3344 | |||
| 3345 | for (fd = 0; fd < max_keyboard_desc; fd++) | ||
| 3346 | if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask) | ||
| 3347 | && !FD_ISSET (fd, &non_keyboard_wait_mask)) | ||
| 3348 | return 1; | ||
| 3349 | |||
| 3350 | return 0; | ||
| 3351 | } | ||
| 3352 | |||
| 3282 | init_process () | 3353 | init_process () |
| 3283 | { | 3354 | { |
| 3284 | register int i; | 3355 | register int i; |
| @@ -3291,10 +3362,10 @@ init_process () | |||
| 3291 | #endif | 3362 | #endif |
| 3292 | 3363 | ||
| 3293 | FD_ZERO (&input_wait_mask); | 3364 | FD_ZERO (&input_wait_mask); |
| 3365 | FD_ZERO (&non_keyboard_wait_mask); | ||
| 3294 | max_process_desc = 0; | 3366 | max_process_desc = 0; |
| 3295 | 3367 | ||
| 3296 | keyboard_descriptor = 0; | 3368 | FD_SET (0, &input_wait_mask); |
| 3297 | FD_SET (keyboard_descriptor, &input_wait_mask); | ||
| 3298 | 3369 | ||
| 3299 | Vprocess_alist = Qnil; | 3370 | Vprocess_alist = Qnil; |
| 3300 | for (i = 0; i < MAXDESC; i++) | 3371 | for (i = 0; i < MAXDESC; i++) |
| @@ -3304,17 +3375,6 @@ init_process () | |||
| 3304 | } | 3375 | } |
| 3305 | } | 3376 | } |
| 3306 | 3377 | ||
| 3307 | /* From now on, assume keyboard input comes from descriptor DESC. */ | ||
| 3308 | |||
| 3309 | void | ||
| 3310 | change_keyboard_wait_descriptor (desc) | ||
| 3311 | int desc; | ||
| 3312 | { | ||
| 3313 | FD_CLR (keyboard_descriptor, &input_wait_mask); | ||
| 3314 | keyboard_descriptor = desc; | ||
| 3315 | FD_SET (keyboard_descriptor, &input_wait_mask); | ||
| 3316 | } | ||
| 3317 | |||
| 3318 | syms_of_process () | 3378 | syms_of_process () |
| 3319 | { | 3379 | { |
| 3320 | #ifdef HAVE_SOCKETS | 3380 | #ifdef HAVE_SOCKETS |