aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c282
1 files changed, 194 insertions, 88 deletions
diff --git a/src/process.c b/src/process.c
index f348dca7d35..a698e56fe39 100644
--- a/src/process.c
+++ b/src/process.c
@@ -105,6 +105,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
105#include "sysselect.h" 105#include "sysselect.h"
106#include "syssignal.h" 106#include "syssignal.h"
107#include "syswait.h" 107#include "syswait.h"
108#ifdef HAVE_GNUTLS
109#include "gnutls.h"
110#endif
108 111
109#if defined (USE_GTK) || defined (HAVE_GCONF) 112#if defined (USE_GTK) || defined (HAVE_GCONF)
110#include "xgselect.h" 113#include "xgselect.h"
@@ -198,8 +201,10 @@ int update_tick;
198 201
199/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */ 202/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */
200 203
204/* Only W32 has this, it really means that select can't take write mask. */
201#ifdef BROKEN_NON_BLOCKING_CONNECT 205#ifdef BROKEN_NON_BLOCKING_CONNECT
202#undef NON_BLOCKING_CONNECT 206#undef NON_BLOCKING_CONNECT
207#define SELECT_CANT_DO_WRITE_MASK
203#else 208#else
204#ifndef NON_BLOCKING_CONNECT 209#ifndef NON_BLOCKING_CONNECT
205#ifdef HAVE_SELECT 210#ifdef HAVE_SELECT
@@ -291,9 +296,9 @@ static SELECT_TYPE non_keyboard_wait_mask;
291 296
292static SELECT_TYPE non_process_wait_mask; 297static SELECT_TYPE non_process_wait_mask;
293 298
294/* Mask for the gpm mouse input descriptor. */ 299/* Mask for selecting for write. */
295 300
296static SELECT_TYPE gpm_wait_mask; 301static SELECT_TYPE write_mask;
297 302
298#ifdef NON_BLOCKING_CONNECT 303#ifdef NON_BLOCKING_CONNECT
299/* Mask of bits indicating the descriptors that we wait for connect to 304/* Mask of bits indicating the descriptors that we wait for connect to
@@ -313,11 +318,8 @@ static int num_pending_connects;
313/* The largest descriptor currently in use for a process object. */ 318/* The largest descriptor currently in use for a process object. */
314static int max_process_desc; 319static int max_process_desc;
315 320
316/* The largest descriptor currently in use for keyboard input. */ 321/* The largest descriptor currently in use for input. */
317static int max_keyboard_desc; 322static int max_input_desc;
318
319/* The largest descriptor currently in use for gpm mouse input. */
320static int max_gpm_desc;
321 323
322/* Indexed by descriptor, gives the process (if any) for that descriptor */ 324/* Indexed by descriptor, gives the process (if any) for that descriptor */
323Lisp_Object chan_process[MAXDESC]; 325Lisp_Object chan_process[MAXDESC];
@@ -363,6 +365,90 @@ static int pty_max_bytes;
363static char pty_name[24]; 365static char pty_name[24];
364#endif 366#endif
365 367
368
369struct fd_callback_data
370{
371 fd_callback func;
372 void *data;
373#define FOR_READ 1
374#define FOR_WRITE 2
375 int condition; /* mask of the defines above. */
376} fd_callback_info[MAXDESC];
377
378
379/* Add a file descriptor FD to be monitored for when read is possible.
380 When read is possible, call FUNC with argument DATA. */
381
382void
383add_read_fd (int fd, fd_callback func, void *data)
384{
385 xassert (fd < MAXDESC);
386 add_keyboard_wait_descriptor (fd);
387
388 fd_callback_info[fd].func = func;
389 fd_callback_info[fd].data = data;
390 fd_callback_info[fd].condition |= FOR_READ;
391}
392
393/* Stop monitoring file descriptor FD for when read is possible. */
394
395void
396delete_read_fd (int fd)
397{
398 xassert (fd < MAXDESC);
399 delete_keyboard_wait_descriptor (fd);
400
401 fd_callback_info[fd].condition &= ~FOR_READ;
402 if (fd_callback_info[fd].condition == 0)
403 {
404 fd_callback_info[fd].func = 0;
405 fd_callback_info[fd].data = 0;
406 }
407}
408
409/* Add a file descriptor FD to be monitored for when write is possible.
410 When write is possible, call FUNC with argument DATA. */
411
412void
413add_write_fd (int fd, fd_callback func, void *data)
414{
415 xassert (fd < MAXDESC);
416 FD_SET (fd, &write_mask);
417 if (fd > max_input_desc)
418 max_input_desc = fd;
419
420 fd_callback_info[fd].func = func;
421 fd_callback_info[fd].data = data;
422 fd_callback_info[fd].condition |= FOR_WRITE;
423}
424
425/* Stop monitoring file descriptor FD for when write is possible. */
426
427void
428delete_write_fd (int fd)
429{
430 int lim = max_input_desc;
431
432 xassert (fd < MAXDESC);
433 FD_CLR (fd, &write_mask);
434 fd_callback_info[fd].condition &= ~FOR_WRITE;
435 if (fd_callback_info[fd].condition == 0)
436 {
437 fd_callback_info[fd].func = 0;
438 fd_callback_info[fd].data = 0;
439
440 if (fd == max_input_desc)
441 for (fd = lim; fd >= 0; fd--)
442 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
443 {
444 max_input_desc = fd;
445 break;
446 }
447
448 }
449}
450
451
366/* Compute the Lisp form of the process status, p->status, from 452/* Compute the Lisp form of the process status, p->status, from
367 the numeric status that was returned by `wait'. */ 453 the numeric status that was returned by `wait'. */
368 454
@@ -583,6 +669,12 @@ make_process (Lisp_Object name)
583 p->read_output_skip = 0; 669 p->read_output_skip = 0;
584#endif 670#endif
585 671
672#ifdef HAVE_GNUTLS
673 p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
674 p->gnutls_log_level = 0;
675 p->gnutls_p = 0;
676#endif
677
586 /* If name is already in use, modify it until it is unused. */ 678 /* If name is already in use, modify it until it is unused. */
587 679
588 name1 = name; 680 name1 = name;
@@ -1526,6 +1618,12 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1526 XPROCESS (proc)->filter = Qnil; 1618 XPROCESS (proc)->filter = Qnil;
1527 XPROCESS (proc)->command = Flist (nargs - 2, args + 2); 1619 XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
1528 1620
1621#ifdef HAVE_GNUTLS
1622 /* AKA GNUTLS_INITSTAGE(proc). */
1623 XPROCESS (proc)->gnutls_initstage = GNUTLS_STAGE_EMPTY;
1624 XPROCESS (proc)->gnutls_cred_type = Qnil;
1625#endif
1626
1529#ifdef ADAPTIVE_READ_BUFFERING 1627#ifdef ADAPTIVE_READ_BUFFERING
1530 XPROCESS (proc)->adaptive_read_buffering 1628 XPROCESS (proc)->adaptive_read_buffering
1531 = (NILP (Vprocess_adaptive_read_buffering) ? 0 1629 = (NILP (Vprocess_adaptive_read_buffering) ? 0
@@ -3170,7 +3268,9 @@ usage: (make-network-process &rest ARGS) */)
3170 if (!NILP (host)) 3268 if (!NILP (host))
3171 { 3269 {
3172 if (EQ (host, Qlocal)) 3270 if (EQ (host, Qlocal))
3173 host = build_string ("localhost"); 3271 /* Depending on setup, "localhost" may map to different IPv4 and/or
3272 IPv6 addresses, so it's better to be explicit. (Bug#6781) */
3273 host = build_string ("127.0.0.1");
3174 CHECK_STRING (host); 3274 CHECK_STRING (host);
3175 } 3275 }
3176 3276
@@ -3605,6 +3705,7 @@ usage: (make-network-process &rest ARGS) */)
3605 if (!FD_ISSET (inch, &connect_wait_mask)) 3705 if (!FD_ISSET (inch, &connect_wait_mask))
3606 { 3706 {
3607 FD_SET (inch, &connect_wait_mask); 3707 FD_SET (inch, &connect_wait_mask);
3708 FD_SET (inch, &write_mask);
3608 num_pending_connects++; 3709 num_pending_connects++;
3609 } 3710 }
3610 } 3711 }
@@ -4008,6 +4109,7 @@ deactivate_process (Lisp_Object proc)
4008 if (FD_ISSET (inchannel, &connect_wait_mask)) 4109 if (FD_ISSET (inchannel, &connect_wait_mask))
4009 { 4110 {
4010 FD_CLR (inchannel, &connect_wait_mask); 4111 FD_CLR (inchannel, &connect_wait_mask);
4112 FD_CLR (inchannel, &write_mask);
4011 if (--num_pending_connects < 0) 4113 if (--num_pending_connects < 0)
4012 abort (); 4114 abort ();
4013 } 4115 }
@@ -4386,10 +4488,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4386{ 4488{
4387 register int channel, nfds; 4489 register int channel, nfds;
4388 SELECT_TYPE Available; 4490 SELECT_TYPE Available;
4389#ifdef NON_BLOCKING_CONNECT 4491 SELECT_TYPE Writeok;
4390 SELECT_TYPE Connecting; 4492 int check_write;
4391 int check_connect;
4392#endif
4393 int check_delay, no_avail; 4493 int check_delay, no_avail;
4394 int xerrno; 4494 int xerrno;
4395 Lisp_Object proc; 4495 Lisp_Object proc;
@@ -4399,11 +4499,9 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4399 int count = SPECPDL_INDEX (); 4499 int count = SPECPDL_INDEX ();
4400 4500
4401 FD_ZERO (&Available); 4501 FD_ZERO (&Available);
4402#ifdef NON_BLOCKING_CONNECT 4502 FD_ZERO (&Writeok);
4403 FD_ZERO (&Connecting);
4404#endif
4405 4503
4406 if (time_limit == 0 && wait_proc && !NILP (Vinhibit_quit) 4504 if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit)
4407 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit))) 4505 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit)))
4408 message ("Blocking call to accept-process-output with quit inhibited!!"); 4506 message ("Blocking call to accept-process-output with quit inhibited!!");
4409 4507
@@ -4537,19 +4635,16 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4537 if (update_tick != process_tick) 4635 if (update_tick != process_tick)
4538 { 4636 {
4539 SELECT_TYPE Atemp; 4637 SELECT_TYPE Atemp;
4540#ifdef NON_BLOCKING_CONNECT
4541 SELECT_TYPE Ctemp; 4638 SELECT_TYPE Ctemp;
4542#endif
4543 4639
4544 if (kbd_on_hold_p ()) 4640 if (kbd_on_hold_p ())
4545 FD_ZERO (&Atemp); 4641 FD_ZERO (&Atemp);
4546 else 4642 else
4547 Atemp = input_wait_mask; 4643 Atemp = input_wait_mask;
4548 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); 4644 Ctemp = write_mask;
4549 4645
4550 EMACS_SET_SECS_USECS (timeout, 0, 0); 4646 EMACS_SET_SECS_USECS (timeout, 0, 0);
4551 if ((select (max (max (max_process_desc, max_keyboard_desc), 4647 if ((select (max (max_process_desc, max_input_desc) + 1,
4552 max_gpm_desc) + 1,
4553 &Atemp, 4648 &Atemp,
4554#ifdef NON_BLOCKING_CONNECT 4649#ifdef NON_BLOCKING_CONNECT
4555 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), 4650 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0),
@@ -4620,13 +4715,13 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4620 break; 4715 break;
4621 FD_SET (wait_proc->infd, &Available); 4716 FD_SET (wait_proc->infd, &Available);
4622 check_delay = 0; 4717 check_delay = 0;
4623 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4718 check_write = 0;
4624 } 4719 }
4625 else if (!NILP (wait_for_cell)) 4720 else if (!NILP (wait_for_cell))
4626 { 4721 {
4627 Available = non_process_wait_mask; 4722 Available = non_process_wait_mask;
4628 check_delay = 0; 4723 check_delay = 0;
4629 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4724 check_write = 0;
4630 } 4725 }
4631 else 4726 else
4632 { 4727 {
@@ -4634,7 +4729,12 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4634 Available = non_keyboard_wait_mask; 4729 Available = non_keyboard_wait_mask;
4635 else 4730 else
4636 Available = input_wait_mask; 4731 Available = input_wait_mask;
4637 IF_NON_BLOCKING_CONNECT (check_connect = (num_pending_connects > 0)); 4732 Writeok = write_mask;
4733#ifdef SELECT_CANT_DO_WRITE_MASK
4734 check_write = 0;
4735#else
4736 check_write = 1;
4737#endif
4638 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; 4738 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count;
4639 } 4739 }
4640 4740
@@ -4659,10 +4759,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4659 } 4759 }
4660 else 4760 else
4661 { 4761 {
4662#ifdef NON_BLOCKING_CONNECT
4663 if (check_connect)
4664 Connecting = connect_wait_mask;
4665#endif
4666 4762
4667#ifdef ADAPTIVE_READ_BUFFERING 4763#ifdef ADAPTIVE_READ_BUFFERING
4668 /* Set the timeout for adaptive read buffering if any 4764 /* Set the timeout for adaptive read buffering if any
@@ -4704,15 +4800,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4704#else 4800#else
4705 nfds = select 4801 nfds = select
4706#endif 4802#endif
4707 (max (max (max_process_desc, max_keyboard_desc), 4803 (max (max_process_desc, max_input_desc) + 1,
4708 max_gpm_desc) + 1, 4804 &Available,
4709 &Available, 4805 (check_write ? &Writeok : (SELECT_TYPE *)0),
4710#ifdef NON_BLOCKING_CONNECT 4806 (SELECT_TYPE *)0, &timeout);
4711 (check_connect ? &Connecting : (SELECT_TYPE *)0),
4712#else
4713 (SELECT_TYPE *)0,
4714#endif
4715 (SELECT_TYPE *)0, &timeout);
4716 } 4807 }
4717 4808
4718 xerrno = errno; 4809 xerrno = errno;
@@ -4752,7 +4843,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4752 if (no_avail) 4843 if (no_avail)
4753 { 4844 {
4754 FD_ZERO (&Available); 4845 FD_ZERO (&Available);
4755 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4846 check_write = 0;
4756 } 4847 }
4757 4848
4758#if 0 /* When polling is used, interrupt_input is 0, 4849#if 0 /* When polling is used, interrupt_input is 0,
@@ -4848,12 +4939,26 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4848 if (no_avail || nfds == 0) 4939 if (no_avail || nfds == 0)
4849 continue; 4940 continue;
4850 4941
4942 for (channel = 0; channel <= max_input_desc; ++channel)
4943 {
4944 struct fd_callback_data *d = &fd_callback_info[channel];
4945 if (FD_ISSET (channel, &Available)
4946 && d->func != 0
4947 && (d->condition & FOR_READ) != 0)
4948 d->func (channel, d->data, 1);
4949 if (FD_ISSET (channel, &write_mask)
4950 && d->func != 0
4951 && (d->condition & FOR_WRITE) != 0)
4952 d->func (channel, d->data, 0);
4953 }
4954
4851 /* Really FIRST_PROC_DESC should be 0 on Unix, 4955 /* Really FIRST_PROC_DESC should be 0 on Unix,
4852 but this is safer in the short run. */ 4956 but this is safer in the short run. */
4853 for (channel = 0; channel <= max_process_desc; channel++) 4957 for (channel = 0; channel <= max_process_desc; channel++)
4854 { 4958 {
4855 if (FD_ISSET (channel, &Available) 4959 if (FD_ISSET (channel, &Available)
4856 && FD_ISSET (channel, &non_keyboard_wait_mask)) 4960 && FD_ISSET (channel, &non_keyboard_wait_mask)
4961 && !FD_ISSET (channel, &non_process_wait_mask))
4857 { 4962 {
4858 int nread; 4963 int nread;
4859 4964
@@ -4958,12 +5063,13 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4958 } 5063 }
4959 } 5064 }
4960#ifdef NON_BLOCKING_CONNECT 5065#ifdef NON_BLOCKING_CONNECT
4961 if (check_connect && FD_ISSET (channel, &Connecting) 5066 if (FD_ISSET (channel, &Writeok)
4962 && FD_ISSET (channel, &connect_wait_mask)) 5067 && FD_ISSET (channel, &connect_wait_mask))
4963 { 5068 {
4964 struct Lisp_Process *p; 5069 struct Lisp_Process *p;
4965 5070
4966 FD_CLR (channel, &connect_wait_mask); 5071 FD_CLR (channel, &connect_wait_mask);
5072 FD_CLR (channel, &write_mask);
4967 if (--num_pending_connects < 0) 5073 if (--num_pending_connects < 0)
4968 abort (); 5074 abort ();
4969 5075
@@ -5073,7 +5179,7 @@ read_process_output (Lisp_Object proc, register int channel)
5073 char *chars; 5179 char *chars;
5074 register Lisp_Object outstream; 5180 register Lisp_Object outstream;
5075 register struct Lisp_Process *p = XPROCESS (proc); 5181 register struct Lisp_Process *p = XPROCESS (proc);
5076 register int opoint; 5182 register EMACS_INT opoint;
5077 struct coding_system *coding = proc_decode_coding_system[channel]; 5183 struct coding_system *coding = proc_decode_coding_system[channel];
5078 int carryover = p->decoding_carryover; 5184 int carryover = p->decoding_carryover;
5079 int readmax = 4096; 5185 int readmax = 4096;
@@ -5097,7 +5203,13 @@ read_process_output (Lisp_Object proc, register int channel)
5097#endif 5203#endif
5098 if (proc_buffered_char[channel] < 0) 5204 if (proc_buffered_char[channel] < 0)
5099 { 5205 {
5100 nbytes = emacs_read (channel, chars + carryover, readmax); 5206#ifdef HAVE_GNUTLS
5207 if (XPROCESS (proc)->gnutls_p)
5208 nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
5209 chars + carryover, readmax);
5210 else
5211#endif
5212 nbytes = emacs_read (channel, chars + carryover, readmax);
5101#ifdef ADAPTIVE_READ_BUFFERING 5213#ifdef ADAPTIVE_READ_BUFFERING
5102 if (nbytes > 0 && p->adaptive_read_buffering) 5214 if (nbytes > 0 && p->adaptive_read_buffering)
5103 { 5215 {
@@ -5130,7 +5242,13 @@ read_process_output (Lisp_Object proc, register int channel)
5130 { 5242 {
5131 chars[carryover] = proc_buffered_char[channel]; 5243 chars[carryover] = proc_buffered_char[channel];
5132 proc_buffered_char[channel] = -1; 5244 proc_buffered_char[channel] = -1;
5133 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1); 5245#ifdef HAVE_GNUTLS
5246 if (XPROCESS (proc)->gnutls_p)
5247 nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
5248 chars + carryover + 1, readmax - 1);
5249 else
5250#endif
5251 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1);
5134 if (nbytes < 0) 5252 if (nbytes < 0)
5135 nbytes = 1; 5253 nbytes = 1;
5136 else 5254 else
@@ -5263,10 +5381,10 @@ read_process_output (Lisp_Object proc, register int channel)
5263 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name)) 5381 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name))
5264 { 5382 {
5265 Lisp_Object old_read_only; 5383 Lisp_Object old_read_only;
5266 int old_begv, old_zv; 5384 EMACS_INT old_begv, old_zv;
5267 int old_begv_byte, old_zv_byte; 5385 EMACS_INT old_begv_byte, old_zv_byte;
5268 int before, before_byte; 5386 EMACS_INT before, before_byte;
5269 int opoint_byte; 5387 EMACS_INT opoint_byte;
5270 Lisp_Object text; 5388 Lisp_Object text;
5271 struct buffer *b; 5389 struct buffer *b;
5272 5390
@@ -5403,11 +5521,11 @@ send_process_trap (int ignore)
5403 5521
5404static void 5522static void
5405send_process (volatile Lisp_Object proc, const unsigned char *volatile buf, 5523send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5406 volatile int len, volatile Lisp_Object object) 5524 volatile EMACS_INT len, volatile Lisp_Object object)
5407{ 5525{
5408 /* Use volatile to protect variables from being clobbered by longjmp. */ 5526 /* Use volatile to protect variables from being clobbered by longjmp. */
5409 struct Lisp_Process *p = XPROCESS (proc); 5527 struct Lisp_Process *p = XPROCESS (proc);
5410 int rv; 5528 EMACS_INT rv;
5411 struct coding_system *coding; 5529 struct coding_system *coding;
5412 struct gcpro gcpro1; 5530 struct gcpro gcpro1;
5413 SIGTYPE (*volatile old_sigpipe) (int); 5531 SIGTYPE (*volatile old_sigpipe) (int);
@@ -5464,8 +5582,8 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5464 coding->dst_object = Qt; 5582 coding->dst_object = Qt;
5465 if (BUFFERP (object)) 5583 if (BUFFERP (object))
5466 { 5584 {
5467 int from_byte, from, to; 5585 EMACS_INT from_byte, from, to;
5468 int save_pt, save_pt_byte; 5586 EMACS_INT save_pt, save_pt_byte;
5469 struct buffer *cur = current_buffer; 5587 struct buffer *cur = current_buffer;
5470 5588
5471 set_buffer_internal (XBUFFER (object)); 5589 set_buffer_internal (XBUFFER (object));
@@ -5517,7 +5635,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5517 process_sent_to = proc; 5635 process_sent_to = proc;
5518 while (len > 0) 5636 while (len > 0)
5519 { 5637 {
5520 int this = len; 5638 EMACS_INT this = len;
5521 5639
5522 /* Send this batch, using one or more write calls. */ 5640 /* Send this batch, using one or more write calls. */
5523 while (this > 0) 5641 while (this > 0)
@@ -5540,7 +5658,14 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5540 else 5658 else
5541#endif 5659#endif
5542 { 5660 {
5543 rv = emacs_write (outfd, (char *) buf, this); 5661#ifdef HAVE_GNUTLS
5662 if (XPROCESS (proc)->gnutls_p)
5663 rv = emacs_gnutls_write (outfd,
5664 XPROCESS (proc),
5665 (char *) buf, this);
5666 else
5667#endif
5668 rv = emacs_write (outfd, (char *) buf, this);
5544#ifdef ADAPTIVE_READ_BUFFERING 5669#ifdef ADAPTIVE_READ_BUFFERING
5545 if (p->read_output_delay > 0 5670 if (p->read_output_delay > 0
5546 && p->adaptive_read_buffering == 1) 5671 && p->adaptive_read_buffering == 1)
@@ -5651,7 +5776,7 @@ Output from processes can arrive in between bunches. */)
5651 (Lisp_Object process, Lisp_Object start, Lisp_Object end) 5776 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5652{ 5777{
5653 Lisp_Object proc; 5778 Lisp_Object proc;
5654 int start1, end1; 5779 EMACS_INT start1, end1;
5655 5780
5656 proc = get_process (process); 5781 proc = get_process (process);
5657 validate_region (&start, &end); 5782 validate_region (&start, &end);
@@ -6592,8 +6717,8 @@ status_notify (struct Lisp_Process *deleting_process)
6592 { 6717 {
6593 Lisp_Object tem; 6718 Lisp_Object tem;
6594 struct buffer *old = current_buffer; 6719 struct buffer *old = current_buffer;
6595 int opoint, opoint_byte; 6720 EMACS_INT opoint, opoint_byte;
6596 int before, before_byte; 6721 EMACS_INT before, before_byte;
6597 6722
6598 /* Avoid error if buffer is deleted 6723 /* Avoid error if buffer is deleted
6599 (probably that's why the process is dead, too) */ 6724 (probably that's why the process is dead, too) */
@@ -6711,35 +6836,16 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6711 6836
6712 6837
6713 6838
6714static int add_gpm_wait_descriptor_called_flag;
6715
6716void 6839void
6717add_gpm_wait_descriptor (int desc) 6840add_gpm_wait_descriptor (int desc)
6718{ 6841{
6719 if (! add_gpm_wait_descriptor_called_flag) 6842 add_keyboard_wait_descriptor (desc);
6720 FD_CLR (0, &input_wait_mask);
6721 add_gpm_wait_descriptor_called_flag = 1;
6722 FD_SET (desc, &input_wait_mask);
6723 FD_SET (desc, &gpm_wait_mask);
6724 if (desc > max_gpm_desc)
6725 max_gpm_desc = desc;
6726} 6843}
6727 6844
6728void 6845void
6729delete_gpm_wait_descriptor (int desc) 6846delete_gpm_wait_descriptor (int desc)
6730{ 6847{
6731 int fd; 6848 delete_keyboard_wait_descriptor (desc);
6732 int lim = max_gpm_desc;
6733
6734 FD_CLR (desc, &input_wait_mask);
6735 FD_CLR (desc, &non_process_wait_mask);
6736
6737 if (desc == max_gpm_desc)
6738 for (fd = 0; fd < lim; fd++)
6739 if (FD_ISSET (fd, &input_wait_mask)
6740 && !FD_ISSET (fd, &non_keyboard_wait_mask)
6741 && !FD_ISSET (fd, &non_process_wait_mask))
6742 max_gpm_desc = fd;
6743} 6849}
6744 6850
6745/* Return nonzero if *MASK has a bit set 6851/* Return nonzero if *MASK has a bit set
@@ -6750,7 +6856,7 @@ keyboard_bit_set (fd_set *mask)
6750{ 6856{
6751 int fd; 6857 int fd;
6752 6858
6753 for (fd = 0; fd <= max_keyboard_desc; fd++) 6859 for (fd = 0; fd <= max_input_desc; fd++)
6754 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask) 6860 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask)
6755 && !FD_ISSET (fd, &non_keyboard_wait_mask)) 6861 && !FD_ISSET (fd, &non_keyboard_wait_mask))
6756 return 1; 6862 return 1;
@@ -6989,11 +7095,11 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
6989void 7095void
6990add_keyboard_wait_descriptor (int desc) 7096add_keyboard_wait_descriptor (int desc)
6991{ 7097{
6992#ifdef subprocesses 7098#ifdef subprocesses /* actually means "not MSDOS" */
6993 FD_SET (desc, &input_wait_mask); 7099 FD_SET (desc, &input_wait_mask);
6994 FD_SET (desc, &non_process_wait_mask); 7100 FD_SET (desc, &non_process_wait_mask);
6995 if (desc > max_keyboard_desc) 7101 if (desc > max_input_desc)
6996 max_keyboard_desc = desc; 7102 max_input_desc = desc;
6997#endif 7103#endif
6998} 7104}
6999 7105
@@ -7004,18 +7110,16 @@ delete_keyboard_wait_descriptor (int desc)
7004{ 7110{
7005#ifdef subprocesses 7111#ifdef subprocesses
7006 int fd; 7112 int fd;
7007 int lim = max_keyboard_desc; 7113 int lim = max_input_desc;
7008 7114
7009 FD_CLR (desc, &input_wait_mask); 7115 FD_CLR (desc, &input_wait_mask);
7010 FD_CLR (desc, &non_process_wait_mask); 7116 FD_CLR (desc, &non_process_wait_mask);
7011 7117
7012 if (desc == max_keyboard_desc) 7118 if (desc == max_input_desc)
7013 for (fd = 0; fd < lim; fd++) 7119 for (fd = 0; fd < lim; fd++)
7014 if (FD_ISSET (fd, &input_wait_mask) 7120 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
7015 && !FD_ISSET (fd, &non_keyboard_wait_mask) 7121 max_input_desc = fd;
7016 && !FD_ISSET (fd, &gpm_wait_mask)) 7122#endif
7017 max_keyboard_desc = fd;
7018#endif /* subprocesses */
7019} 7123}
7020 7124
7021/* Setup coding systems of PROCESS. */ 7125/* Setup coding systems of PROCESS. */
@@ -7272,7 +7376,9 @@ init_process (void)
7272 FD_ZERO (&input_wait_mask); 7376 FD_ZERO (&input_wait_mask);
7273 FD_ZERO (&non_keyboard_wait_mask); 7377 FD_ZERO (&non_keyboard_wait_mask);
7274 FD_ZERO (&non_process_wait_mask); 7378 FD_ZERO (&non_process_wait_mask);
7379 FD_ZERO (&write_mask);
7275 max_process_desc = 0; 7380 max_process_desc = 0;
7381 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7276 7382
7277#ifdef NON_BLOCKING_CONNECT 7383#ifdef NON_BLOCKING_CONNECT
7278 FD_ZERO (&connect_wait_mask); 7384 FD_ZERO (&connect_wait_mask);