aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c203
1 files changed, 131 insertions, 72 deletions
diff --git a/src/process.c b/src/process.c
index ef086914704..6ff8f472c26 100644
--- a/src/process.c
+++ b/src/process.c
@@ -294,9 +294,9 @@ static SELECT_TYPE non_keyboard_wait_mask;
294 294
295static SELECT_TYPE non_process_wait_mask; 295static SELECT_TYPE non_process_wait_mask;
296 296
297/* Mask for the gpm mouse input descriptor. */ 297/* Mask for selecting for write. */
298 298
299static SELECT_TYPE gpm_wait_mask; 299static SELECT_TYPE write_mask;
300 300
301#ifdef NON_BLOCKING_CONNECT 301#ifdef NON_BLOCKING_CONNECT
302/* Mask of bits indicating the descriptors that we wait for connect to 302/* Mask of bits indicating the descriptors that we wait for connect to
@@ -316,11 +316,8 @@ static int num_pending_connects;
316/* The largest descriptor currently in use for a process object. */ 316/* The largest descriptor currently in use for a process object. */
317static int max_process_desc; 317static int max_process_desc;
318 318
319/* The largest descriptor currently in use for keyboard input. */ 319/* The largest descriptor currently in use for input. */
320static int max_keyboard_desc; 320static int max_input_desc;
321
322/* The largest descriptor currently in use for gpm mouse input. */
323static int max_gpm_desc;
324 321
325/* Indexed by descriptor, gives the process (if any) for that descriptor */ 322/* Indexed by descriptor, gives the process (if any) for that descriptor */
326Lisp_Object chan_process[MAXDESC]; 323Lisp_Object chan_process[MAXDESC];
@@ -366,6 +363,90 @@ static int pty_max_bytes;
366static char pty_name[24]; 363static char pty_name[24];
367#endif 364#endif
368 365
366
367struct fd_callback_data
368{
369 fd_callback func;
370 void *data;
371#define FOR_READ 1
372#define FOR_WRITE 2
373 int condition; /* mask of the defines above. */
374} fd_callback_info[MAXDESC];
375
376
377/* Add a file descriptor FD to be monitored for when read is possible.
378 When read is possible, call FUNC with argument DATA. */
379
380void
381add_read_fd (int fd, fd_callback func, void *data)
382{
383 xassert (fd < MAXDESC);
384 add_keyboard_wait_descriptor (fd);
385
386 fd_callback_info[fd].func = func;
387 fd_callback_info[fd].data = data;
388 fd_callback_info[fd].condition |= FOR_READ;
389}
390
391/* Stop monitoring file descriptor FD for when read is possible. */
392
393void
394delete_read_fd (int fd)
395{
396 xassert (fd < MAXDESC);
397 delete_keyboard_wait_descriptor (fd);
398
399 fd_callback_info[fd].condition &= ~FOR_READ;
400 if (fd_callback_info[fd].condition == 0)
401 {
402 fd_callback_info[fd].func = 0;
403 fd_callback_info[fd].data = 0;
404 }
405}
406
407/* Add a file descriptor FD to be monitored for when write is possible.
408 When write is possible, call FUNC with argument DATA. */
409
410void
411add_write_fd (int fd, fd_callback func, void *data)
412{
413 xassert (fd < MAXDESC);
414 FD_SET (fd, &write_mask);
415 if (fd > max_input_desc)
416 max_input_desc = fd;
417
418 fd_callback_info[fd].func = func;
419 fd_callback_info[fd].data = data;
420 fd_callback_info[fd].condition |= FOR_WRITE;
421}
422
423/* Stop monitoring file descriptor FD for when write is possible. */
424
425void
426delete_write_fd (int fd)
427{
428 int lim = max_input_desc;
429
430 xassert (fd < MAXDESC);
431 FD_CLR (fd, &write_mask);
432 fd_callback_info[fd].condition &= ~FOR_WRITE;
433 if (fd_callback_info[fd].condition == 0)
434 {
435 fd_callback_info[fd].func = 0;
436 fd_callback_info[fd].data = 0;
437
438 if (fd == max_input_desc)
439 for (fd = lim; fd >= 0; fd--)
440 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
441 {
442 max_input_desc = fd;
443 break;
444 }
445
446 }
447}
448
449
369/* Compute the Lisp form of the process status, p->status, from 450/* Compute the Lisp form of the process status, p->status, from
370 the numeric status that was returned by `wait'. */ 451 the numeric status that was returned by `wait'. */
371 452
@@ -3620,6 +3701,7 @@ usage: (make-network-process &rest ARGS) */)
3620 if (!FD_ISSET (inch, &connect_wait_mask)) 3701 if (!FD_ISSET (inch, &connect_wait_mask))
3621 { 3702 {
3622 FD_SET (inch, &connect_wait_mask); 3703 FD_SET (inch, &connect_wait_mask);
3704 FD_SET (inch, &write_mask);
3623 num_pending_connects++; 3705 num_pending_connects++;
3624 } 3706 }
3625 } 3707 }
@@ -4023,6 +4105,7 @@ deactivate_process (Lisp_Object proc)
4023 if (FD_ISSET (inchannel, &connect_wait_mask)) 4105 if (FD_ISSET (inchannel, &connect_wait_mask))
4024 { 4106 {
4025 FD_CLR (inchannel, &connect_wait_mask); 4107 FD_CLR (inchannel, &connect_wait_mask);
4108 FD_CLR (inchannel, &write_mask);
4026 if (--num_pending_connects < 0) 4109 if (--num_pending_connects < 0)
4027 abort (); 4110 abort ();
4028 } 4111 }
@@ -4401,10 +4484,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4401{ 4484{
4402 register int channel, nfds; 4485 register int channel, nfds;
4403 SELECT_TYPE Available; 4486 SELECT_TYPE Available;
4404#ifdef NON_BLOCKING_CONNECT 4487 SELECT_TYPE Writeok;
4405 SELECT_TYPE Connecting; 4488 int check_write;
4406 int check_connect;
4407#endif
4408 int check_delay, no_avail; 4489 int check_delay, no_avail;
4409 int xerrno; 4490 int xerrno;
4410 Lisp_Object proc; 4491 Lisp_Object proc;
@@ -4414,9 +4495,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4414 int count = SPECPDL_INDEX (); 4495 int count = SPECPDL_INDEX ();
4415 4496
4416 FD_ZERO (&Available); 4497 FD_ZERO (&Available);
4417#ifdef NON_BLOCKING_CONNECT 4498 FD_ZERO (&Writeok);
4418 FD_ZERO (&Connecting);
4419#endif
4420 4499
4421 if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit) 4500 if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit)
4422 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit))) 4501 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit)))
@@ -4552,19 +4631,16 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4552 if (update_tick != process_tick) 4631 if (update_tick != process_tick)
4553 { 4632 {
4554 SELECT_TYPE Atemp; 4633 SELECT_TYPE Atemp;
4555#ifdef NON_BLOCKING_CONNECT
4556 SELECT_TYPE Ctemp; 4634 SELECT_TYPE Ctemp;
4557#endif
4558 4635
4559 if (kbd_on_hold_p ()) 4636 if (kbd_on_hold_p ())
4560 FD_ZERO (&Atemp); 4637 FD_ZERO (&Atemp);
4561 else 4638 else
4562 Atemp = input_wait_mask; 4639 Atemp = input_wait_mask;
4563 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); 4640 Ctemp = write_mask;
4564 4641
4565 EMACS_SET_SECS_USECS (timeout, 0, 0); 4642 EMACS_SET_SECS_USECS (timeout, 0, 0);
4566 if ((select (max (max (max_process_desc, max_keyboard_desc), 4643 if ((select (max (max_process_desc, max_input_desc) + 1,
4567 max_gpm_desc) + 1,
4568 &Atemp, 4644 &Atemp,
4569#ifdef NON_BLOCKING_CONNECT 4645#ifdef NON_BLOCKING_CONNECT
4570 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), 4646 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0),
@@ -4635,13 +4711,13 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4635 break; 4711 break;
4636 FD_SET (wait_proc->infd, &Available); 4712 FD_SET (wait_proc->infd, &Available);
4637 check_delay = 0; 4713 check_delay = 0;
4638 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4714 check_write = 0;
4639 } 4715 }
4640 else if (!NILP (wait_for_cell)) 4716 else if (!NILP (wait_for_cell))
4641 { 4717 {
4642 Available = non_process_wait_mask; 4718 Available = non_process_wait_mask;
4643 check_delay = 0; 4719 check_delay = 0;
4644 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4720 check_write = 0;
4645 } 4721 }
4646 else 4722 else
4647 { 4723 {
@@ -4649,7 +4725,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4649 Available = non_keyboard_wait_mask; 4725 Available = non_keyboard_wait_mask;
4650 else 4726 else
4651 Available = input_wait_mask; 4727 Available = input_wait_mask;
4652 IF_NON_BLOCKING_CONNECT (check_connect = (num_pending_connects > 0)); 4728 Writeok = write_mask;
4729 check_write = 1;
4653 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; 4730 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count;
4654 } 4731 }
4655 4732
@@ -4674,10 +4751,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4674 } 4751 }
4675 else 4752 else
4676 { 4753 {
4677#ifdef NON_BLOCKING_CONNECT
4678 if (check_connect)
4679 Connecting = connect_wait_mask;
4680#endif
4681 4754
4682#ifdef ADAPTIVE_READ_BUFFERING 4755#ifdef ADAPTIVE_READ_BUFFERING
4683 /* Set the timeout for adaptive read buffering if any 4756 /* Set the timeout for adaptive read buffering if any
@@ -4719,15 +4792,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4719#else 4792#else
4720 nfds = select 4793 nfds = select
4721#endif 4794#endif
4722 (max (max (max_process_desc, max_keyboard_desc), 4795 (max (max_process_desc, max_input_desc) + 1,
4723 max_gpm_desc) + 1, 4796 &Available,
4724 &Available, 4797 (check_write ? &Writeok : (SELECT_TYPE *)0),
4725#ifdef NON_BLOCKING_CONNECT 4798 (SELECT_TYPE *)0, &timeout);
4726 (check_connect ? &Connecting : (SELECT_TYPE *)0),
4727#else
4728 (SELECT_TYPE *)0,
4729#endif
4730 (SELECT_TYPE *)0, &timeout);
4731 } 4799 }
4732 4800
4733 xerrno = errno; 4801 xerrno = errno;
@@ -4767,7 +4835,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4767 if (no_avail) 4835 if (no_avail)
4768 { 4836 {
4769 FD_ZERO (&Available); 4837 FD_ZERO (&Available);
4770 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4838 check_write = 0;
4771 } 4839 }
4772 4840
4773#if 0 /* When polling is used, interrupt_input is 0, 4841#if 0 /* When polling is used, interrupt_input is 0,
@@ -4863,12 +4931,26 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4863 if (no_avail || nfds == 0) 4931 if (no_avail || nfds == 0)
4864 continue; 4932 continue;
4865 4933
4934 for (channel = 0; channel <= max_input_desc; ++channel)
4935 {
4936 struct fd_callback_data *d = &fd_callback_info[channel];
4937 if (FD_ISSET (channel, &Available)
4938 && d->func != 0
4939 && (d->condition & FOR_READ) != 0)
4940 d->func (channel, d->data, 1);
4941 if (FD_ISSET (channel, &write_mask)
4942 && d->func != 0
4943 && (d->condition & FOR_WRITE) != 0)
4944 d->func (channel, d->data, 0);
4945 }
4946
4866 /* Really FIRST_PROC_DESC should be 0 on Unix, 4947 /* Really FIRST_PROC_DESC should be 0 on Unix,
4867 but this is safer in the short run. */ 4948 but this is safer in the short run. */
4868 for (channel = 0; channel <= max_process_desc; channel++) 4949 for (channel = 0; channel <= max_process_desc; channel++)
4869 { 4950 {
4870 if (FD_ISSET (channel, &Available) 4951 if (FD_ISSET (channel, &Available)
4871 && FD_ISSET (channel, &non_keyboard_wait_mask)) 4952 && FD_ISSET (channel, &non_keyboard_wait_mask)
4953 && !FD_ISSET (channel, &non_process_wait_mask))
4872 { 4954 {
4873 int nread; 4955 int nread;
4874 4956
@@ -4973,7 +5055,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4973 } 5055 }
4974 } 5056 }
4975#ifdef NON_BLOCKING_CONNECT 5057#ifdef NON_BLOCKING_CONNECT
4976 if (check_connect && FD_ISSET (channel, &Connecting) 5058 if (FD_ISSET (channel, &Writeok)
4977 && FD_ISSET (channel, &connect_wait_mask)) 5059 && FD_ISSET (channel, &connect_wait_mask))
4978 { 5060 {
4979 struct Lisp_Process *p; 5061 struct Lisp_Process *p;
@@ -6745,35 +6827,16 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6745 6827
6746 6828
6747 6829
6748static int add_gpm_wait_descriptor_called_flag;
6749
6750void 6830void
6751add_gpm_wait_descriptor (int desc) 6831add_gpm_wait_descriptor (int desc)
6752{ 6832{
6753 if (! add_gpm_wait_descriptor_called_flag) 6833 add_keyboard_wait_descriptor (desc);
6754 FD_CLR (0, &input_wait_mask);
6755 add_gpm_wait_descriptor_called_flag = 1;
6756 FD_SET (desc, &input_wait_mask);
6757 FD_SET (desc, &gpm_wait_mask);
6758 if (desc > max_gpm_desc)
6759 max_gpm_desc = desc;
6760} 6834}
6761 6835
6762void 6836void
6763delete_gpm_wait_descriptor (int desc) 6837delete_gpm_wait_descriptor (int desc)
6764{ 6838{
6765 int fd; 6839 delete_keyboard_wait_descriptor (desc);
6766 int lim = max_gpm_desc;
6767
6768 FD_CLR (desc, &input_wait_mask);
6769 FD_CLR (desc, &non_process_wait_mask);
6770
6771 if (desc == max_gpm_desc)
6772 for (fd = 0; fd < lim; fd++)
6773 if (FD_ISSET (fd, &input_wait_mask)
6774 && !FD_ISSET (fd, &non_keyboard_wait_mask)
6775 && !FD_ISSET (fd, &non_process_wait_mask))
6776 max_gpm_desc = fd;
6777} 6840}
6778 6841
6779/* Return nonzero if *MASK has a bit set 6842/* Return nonzero if *MASK has a bit set
@@ -6784,7 +6847,7 @@ keyboard_bit_set (fd_set *mask)
6784{ 6847{
6785 int fd; 6848 int fd;
6786 6849
6787 for (fd = 0; fd <= max_keyboard_desc; fd++) 6850 for (fd = 0; fd <= max_input_desc; fd++)
6788 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask) 6851 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask)
6789 && !FD_ISSET (fd, &non_keyboard_wait_mask)) 6852 && !FD_ISSET (fd, &non_keyboard_wait_mask))
6790 return 1; 6853 return 1;
@@ -7023,12 +7086,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
7023void 7086void
7024add_keyboard_wait_descriptor (int desc) 7087add_keyboard_wait_descriptor (int desc)
7025{ 7088{
7026#ifdef subprocesses
7027 FD_SET (desc, &input_wait_mask); 7089 FD_SET (desc, &input_wait_mask);
7028 FD_SET (desc, &non_process_wait_mask); 7090 FD_SET (desc, &non_process_wait_mask);
7029 if (desc > max_keyboard_desc) 7091 if (desc > max_input_desc)
7030 max_keyboard_desc = desc; 7092 max_input_desc = desc;
7031#endif
7032} 7093}
7033 7094
7034/* From now on, do not expect DESC to give keyboard input. */ 7095/* From now on, do not expect DESC to give keyboard input. */
@@ -7036,20 +7097,16 @@ add_keyboard_wait_descriptor (int desc)
7036void 7097void
7037delete_keyboard_wait_descriptor (int desc) 7098delete_keyboard_wait_descriptor (int desc)
7038{ 7099{
7039#ifdef subprocesses
7040 int fd; 7100 int fd;
7041 int lim = max_keyboard_desc; 7101 int lim = max_input_desc;
7042 7102
7043 FD_CLR (desc, &input_wait_mask); 7103 FD_CLR (desc, &input_wait_mask);
7044 FD_CLR (desc, &non_process_wait_mask); 7104 FD_CLR (desc, &non_process_wait_mask);
7045 7105
7046 if (desc == max_keyboard_desc) 7106 if (desc == max_input_desc)
7047 for (fd = 0; fd < lim; fd++) 7107 for (fd = 0; fd < lim; fd++)
7048 if (FD_ISSET (fd, &input_wait_mask) 7108 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
7049 && !FD_ISSET (fd, &non_keyboard_wait_mask) 7109 max_input_desc = fd;
7050 && !FD_ISSET (fd, &gpm_wait_mask))
7051 max_keyboard_desc = fd;
7052#endif /* subprocesses */
7053} 7110}
7054 7111
7055/* Setup coding systems of PROCESS. */ 7112/* Setup coding systems of PROCESS. */
@@ -7306,7 +7363,9 @@ init_process (void)
7306 FD_ZERO (&input_wait_mask); 7363 FD_ZERO (&input_wait_mask);
7307 FD_ZERO (&non_keyboard_wait_mask); 7364 FD_ZERO (&non_keyboard_wait_mask);
7308 FD_ZERO (&non_process_wait_mask); 7365 FD_ZERO (&non_process_wait_mask);
7366 FD_ZERO (&write_mask);
7309 max_process_desc = 0; 7367 max_process_desc = 0;
7368 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7310 7369
7311#ifdef NON_BLOCKING_CONNECT 7370#ifdef NON_BLOCKING_CONNECT
7312 FD_ZERO (&connect_wait_mask); 7371 FD_ZERO (&connect_wait_mask);