aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorKenichi Handa2010-09-27 14:42:43 +0900
committerKenichi Handa2010-09-27 14:42:43 +0900
commitb3253cd4b4bcbe1ab4ad1fdc98b30c33af70332c (patch)
tree4d55005558f96dfb44bfcd746098ed0882aff2d0 /src/process.c
parent4be9765d4bad14d68cdfee2a2c6afe1001d9516a (diff)
parente5fa38990bca723fc3ef1d0ede792e8ff84b84f7 (diff)
downloademacs-b3253cd4b4bcbe1ab4ad1fdc98b30c33af70332c.tar.gz
emacs-b3253cd4b4bcbe1ab4ad1fdc98b30c33af70332c.zip
merge trunk
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c277
1 files changed, 190 insertions, 87 deletions
diff --git a/src/process.c b/src/process.c
index ec1b9586db5..70cc8250add 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,10 @@ 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#endif
675
586 /* If name is already in use, modify it until it is unused. */ 676 /* If name is already in use, modify it until it is unused. */
587 677
588 name1 = name; 678 name1 = name;
@@ -1526,6 +1616,12 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1526 XPROCESS (proc)->filter = Qnil; 1616 XPROCESS (proc)->filter = Qnil;
1527 XPROCESS (proc)->command = Flist (nargs - 2, args + 2); 1617 XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
1528 1618
1619#ifdef HAVE_GNUTLS
1620 /* AKA GNUTLS_INITSTAGE(proc). */
1621 XPROCESS (proc)->gnutls_initstage = GNUTLS_STAGE_EMPTY;
1622 XPROCESS (proc)->gnutls_cred_type = Qnil;
1623#endif
1624
1529#ifdef ADAPTIVE_READ_BUFFERING 1625#ifdef ADAPTIVE_READ_BUFFERING
1530 XPROCESS (proc)->adaptive_read_buffering 1626 XPROCESS (proc)->adaptive_read_buffering
1531 = (NILP (Vprocess_adaptive_read_buffering) ? 0 1627 = (NILP (Vprocess_adaptive_read_buffering) ? 0
@@ -3170,7 +3266,9 @@ usage: (make-network-process &rest ARGS) */)
3170 if (!NILP (host)) 3266 if (!NILP (host))
3171 { 3267 {
3172 if (EQ (host, Qlocal)) 3268 if (EQ (host, Qlocal))
3173 host = build_string ("localhost"); 3269 /* Depending on setup, "localhost" may map to different IPv4 and/or
3270 IPv6 addresses, so it's better to be explicit. (Bug#6781) */
3271 host = build_string ("127.0.0.1");
3174 CHECK_STRING (host); 3272 CHECK_STRING (host);
3175 } 3273 }
3176 3274
@@ -3605,6 +3703,7 @@ usage: (make-network-process &rest ARGS) */)
3605 if (!FD_ISSET (inch, &connect_wait_mask)) 3703 if (!FD_ISSET (inch, &connect_wait_mask))
3606 { 3704 {
3607 FD_SET (inch, &connect_wait_mask); 3705 FD_SET (inch, &connect_wait_mask);
3706 FD_SET (inch, &write_mask);
3608 num_pending_connects++; 3707 num_pending_connects++;
3609 } 3708 }
3610 } 3709 }
@@ -4008,6 +4107,7 @@ deactivate_process (Lisp_Object proc)
4008 if (FD_ISSET (inchannel, &connect_wait_mask)) 4107 if (FD_ISSET (inchannel, &connect_wait_mask))
4009 { 4108 {
4010 FD_CLR (inchannel, &connect_wait_mask); 4109 FD_CLR (inchannel, &connect_wait_mask);
4110 FD_CLR (inchannel, &write_mask);
4011 if (--num_pending_connects < 0) 4111 if (--num_pending_connects < 0)
4012 abort (); 4112 abort ();
4013 } 4113 }
@@ -4386,10 +4486,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4386{ 4486{
4387 register int channel, nfds; 4487 register int channel, nfds;
4388 SELECT_TYPE Available; 4488 SELECT_TYPE Available;
4389#ifdef NON_BLOCKING_CONNECT 4489 SELECT_TYPE Writeok;
4390 SELECT_TYPE Connecting; 4490 int check_write;
4391 int check_connect;
4392#endif
4393 int check_delay, no_avail; 4491 int check_delay, no_avail;
4394 int xerrno; 4492 int xerrno;
4395 Lisp_Object proc; 4493 Lisp_Object proc;
@@ -4399,9 +4497,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4399 int count = SPECPDL_INDEX (); 4497 int count = SPECPDL_INDEX ();
4400 4498
4401 FD_ZERO (&Available); 4499 FD_ZERO (&Available);
4402#ifdef NON_BLOCKING_CONNECT 4500 FD_ZERO (&Writeok);
4403 FD_ZERO (&Connecting);
4404#endif
4405 4501
4406 if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit) 4502 if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit)
4407 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit))) 4503 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit)))
@@ -4537,19 +4633,16 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4537 if (update_tick != process_tick) 4633 if (update_tick != process_tick)
4538 { 4634 {
4539 SELECT_TYPE Atemp; 4635 SELECT_TYPE Atemp;
4540#ifdef NON_BLOCKING_CONNECT
4541 SELECT_TYPE Ctemp; 4636 SELECT_TYPE Ctemp;
4542#endif
4543 4637
4544 if (kbd_on_hold_p ()) 4638 if (kbd_on_hold_p ())
4545 FD_ZERO (&Atemp); 4639 FD_ZERO (&Atemp);
4546 else 4640 else
4547 Atemp = input_wait_mask; 4641 Atemp = input_wait_mask;
4548 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); 4642 Ctemp = write_mask;
4549 4643
4550 EMACS_SET_SECS_USECS (timeout, 0, 0); 4644 EMACS_SET_SECS_USECS (timeout, 0, 0);
4551 if ((select (max (max (max_process_desc, max_keyboard_desc), 4645 if ((select (max (max_process_desc, max_input_desc) + 1,
4552 max_gpm_desc) + 1,
4553 &Atemp, 4646 &Atemp,
4554#ifdef NON_BLOCKING_CONNECT 4647#ifdef NON_BLOCKING_CONNECT
4555 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), 4648 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0),
@@ -4620,13 +4713,13 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4620 break; 4713 break;
4621 FD_SET (wait_proc->infd, &Available); 4714 FD_SET (wait_proc->infd, &Available);
4622 check_delay = 0; 4715 check_delay = 0;
4623 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4716 check_write = 0;
4624 } 4717 }
4625 else if (!NILP (wait_for_cell)) 4718 else if (!NILP (wait_for_cell))
4626 { 4719 {
4627 Available = non_process_wait_mask; 4720 Available = non_process_wait_mask;
4628 check_delay = 0; 4721 check_delay = 0;
4629 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4722 check_write = 0;
4630 } 4723 }
4631 else 4724 else
4632 { 4725 {
@@ -4634,7 +4727,12 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4634 Available = non_keyboard_wait_mask; 4727 Available = non_keyboard_wait_mask;
4635 else 4728 else
4636 Available = input_wait_mask; 4729 Available = input_wait_mask;
4637 IF_NON_BLOCKING_CONNECT (check_connect = (num_pending_connects > 0)); 4730 Writeok = write_mask;
4731#ifdef SELECT_CANT_DO_WRITE_MASK
4732 check_write = 0;
4733#else
4734 check_write = 1;
4735#endif
4638 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; 4736 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count;
4639 } 4737 }
4640 4738
@@ -4659,10 +4757,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4659 } 4757 }
4660 else 4758 else
4661 { 4759 {
4662#ifdef NON_BLOCKING_CONNECT
4663 if (check_connect)
4664 Connecting = connect_wait_mask;
4665#endif
4666 4760
4667#ifdef ADAPTIVE_READ_BUFFERING 4761#ifdef ADAPTIVE_READ_BUFFERING
4668 /* Set the timeout for adaptive read buffering if any 4762 /* Set the timeout for adaptive read buffering if any
@@ -4704,15 +4798,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4704#else 4798#else
4705 nfds = select 4799 nfds = select
4706#endif 4800#endif
4707 (max (max (max_process_desc, max_keyboard_desc), 4801 (max (max_process_desc, max_input_desc) + 1,
4708 max_gpm_desc) + 1, 4802 &Available,
4709 &Available, 4803 (check_write ? &Writeok : (SELECT_TYPE *)0),
4710#ifdef NON_BLOCKING_CONNECT 4804 (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 } 4805 }
4717 4806
4718 xerrno = errno; 4807 xerrno = errno;
@@ -4752,7 +4841,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4752 if (no_avail) 4841 if (no_avail)
4753 { 4842 {
4754 FD_ZERO (&Available); 4843 FD_ZERO (&Available);
4755 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4844 check_write = 0;
4756 } 4845 }
4757 4846
4758#if 0 /* When polling is used, interrupt_input is 0, 4847#if 0 /* When polling is used, interrupt_input is 0,
@@ -4848,12 +4937,26 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4848 if (no_avail || nfds == 0) 4937 if (no_avail || nfds == 0)
4849 continue; 4938 continue;
4850 4939
4940 for (channel = 0; channel <= max_input_desc; ++channel)
4941 {
4942 struct fd_callback_data *d = &fd_callback_info[channel];
4943 if (FD_ISSET (channel, &Available)
4944 && d->func != 0
4945 && (d->condition & FOR_READ) != 0)
4946 d->func (channel, d->data, 1);
4947 if (FD_ISSET (channel, &write_mask)
4948 && d->func != 0
4949 && (d->condition & FOR_WRITE) != 0)
4950 d->func (channel, d->data, 0);
4951 }
4952
4851 /* Really FIRST_PROC_DESC should be 0 on Unix, 4953 /* Really FIRST_PROC_DESC should be 0 on Unix,
4852 but this is safer in the short run. */ 4954 but this is safer in the short run. */
4853 for (channel = 0; channel <= max_process_desc; channel++) 4955 for (channel = 0; channel <= max_process_desc; channel++)
4854 { 4956 {
4855 if (FD_ISSET (channel, &Available) 4957 if (FD_ISSET (channel, &Available)
4856 && FD_ISSET (channel, &non_keyboard_wait_mask)) 4958 && FD_ISSET (channel, &non_keyboard_wait_mask)
4959 && !FD_ISSET (channel, &non_process_wait_mask))
4857 { 4960 {
4858 int nread; 4961 int nread;
4859 4962
@@ -4958,7 +5061,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4958 } 5061 }
4959 } 5062 }
4960#ifdef NON_BLOCKING_CONNECT 5063#ifdef NON_BLOCKING_CONNECT
4961 if (check_connect && FD_ISSET (channel, &Connecting) 5064 if (FD_ISSET (channel, &Writeok)
4962 && FD_ISSET (channel, &connect_wait_mask)) 5065 && FD_ISSET (channel, &connect_wait_mask))
4963 { 5066 {
4964 struct Lisp_Process *p; 5067 struct Lisp_Process *p;
@@ -5073,7 +5176,7 @@ read_process_output (Lisp_Object proc, register int channel)
5073 char *chars; 5176 char *chars;
5074 register Lisp_Object outstream; 5177 register Lisp_Object outstream;
5075 register struct Lisp_Process *p = XPROCESS (proc); 5178 register struct Lisp_Process *p = XPROCESS (proc);
5076 register int opoint; 5179 register EMACS_INT opoint;
5077 struct coding_system *coding = proc_decode_coding_system[channel]; 5180 struct coding_system *coding = proc_decode_coding_system[channel];
5078 int carryover = p->decoding_carryover; 5181 int carryover = p->decoding_carryover;
5079 int readmax = 4096; 5182 int readmax = 4096;
@@ -5097,7 +5200,13 @@ read_process_output (Lisp_Object proc, register int channel)
5097#endif 5200#endif
5098 if (proc_buffered_char[channel] < 0) 5201 if (proc_buffered_char[channel] < 0)
5099 { 5202 {
5100 nbytes = emacs_read (channel, chars + carryover, readmax); 5203#ifdef HAVE_GNUTLS
5204 if (NETCONN_P(proc) && GNUTLS_PROCESS_USABLE (proc))
5205 nbytes = emacs_gnutls_read (channel, XPROCESS (proc)->gnutls_state,
5206 chars + carryover, readmax);
5207 else
5208#endif
5209 nbytes = emacs_read (channel, chars + carryover, readmax);
5101#ifdef ADAPTIVE_READ_BUFFERING 5210#ifdef ADAPTIVE_READ_BUFFERING
5102 if (nbytes > 0 && p->adaptive_read_buffering) 5211 if (nbytes > 0 && p->adaptive_read_buffering)
5103 { 5212 {
@@ -5130,7 +5239,13 @@ read_process_output (Lisp_Object proc, register int channel)
5130 { 5239 {
5131 chars[carryover] = proc_buffered_char[channel]; 5240 chars[carryover] = proc_buffered_char[channel];
5132 proc_buffered_char[channel] = -1; 5241 proc_buffered_char[channel] = -1;
5133 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1); 5242#ifdef HAVE_GNUTLS
5243 if (NETCONN_P(proc) && GNUTLS_PROCESS_USABLE (proc))
5244 nbytes = emacs_gnutls_read (channel, XPROCESS (proc)->gnutls_state,
5245 chars + carryover + 1, readmax - 1);
5246 else
5247#endif
5248 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1);
5134 if (nbytes < 0) 5249 if (nbytes < 0)
5135 nbytes = 1; 5250 nbytes = 1;
5136 else 5251 else
@@ -5263,10 +5378,10 @@ read_process_output (Lisp_Object proc, register int channel)
5263 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name)) 5378 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name))
5264 { 5379 {
5265 Lisp_Object old_read_only; 5380 Lisp_Object old_read_only;
5266 int old_begv, old_zv; 5381 EMACS_INT old_begv, old_zv;
5267 int old_begv_byte, old_zv_byte; 5382 EMACS_INT old_begv_byte, old_zv_byte;
5268 int before, before_byte; 5383 EMACS_INT before, before_byte;
5269 int opoint_byte; 5384 EMACS_INT opoint_byte;
5270 Lisp_Object text; 5385 Lisp_Object text;
5271 struct buffer *b; 5386 struct buffer *b;
5272 5387
@@ -5403,11 +5518,11 @@ send_process_trap (int ignore)
5403 5518
5404static void 5519static void
5405send_process (volatile Lisp_Object proc, const unsigned char *volatile buf, 5520send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5406 volatile int len, volatile Lisp_Object object) 5521 volatile EMACS_INT len, volatile Lisp_Object object)
5407{ 5522{
5408 /* Use volatile to protect variables from being clobbered by longjmp. */ 5523 /* Use volatile to protect variables from being clobbered by longjmp. */
5409 struct Lisp_Process *p = XPROCESS (proc); 5524 struct Lisp_Process *p = XPROCESS (proc);
5410 int rv; 5525 EMACS_INT rv;
5411 struct coding_system *coding; 5526 struct coding_system *coding;
5412 struct gcpro gcpro1; 5527 struct gcpro gcpro1;
5413 SIGTYPE (*volatile old_sigpipe) (int); 5528 SIGTYPE (*volatile old_sigpipe) (int);
@@ -5464,8 +5579,8 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5464 coding->dst_object = Qt; 5579 coding->dst_object = Qt;
5465 if (BUFFERP (object)) 5580 if (BUFFERP (object))
5466 { 5581 {
5467 int from_byte, from, to; 5582 EMACS_INT from_byte, from, to;
5468 int save_pt, save_pt_byte; 5583 EMACS_INT save_pt, save_pt_byte;
5469 struct buffer *cur = current_buffer; 5584 struct buffer *cur = current_buffer;
5470 5585
5471 set_buffer_internal (XBUFFER (object)); 5586 set_buffer_internal (XBUFFER (object));
@@ -5517,7 +5632,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5517 process_sent_to = proc; 5632 process_sent_to = proc;
5518 while (len > 0) 5633 while (len > 0)
5519 { 5634 {
5520 int this = len; 5635 EMACS_INT this = len;
5521 5636
5522 /* Send this batch, using one or more write calls. */ 5637 /* Send this batch, using one or more write calls. */
5523 while (this > 0) 5638 while (this > 0)
@@ -5540,7 +5655,14 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5540 else 5655 else
5541#endif 5656#endif
5542 { 5657 {
5543 rv = emacs_write (outfd, (char *) buf, this); 5658#ifdef HAVE_GNUTLS
5659 if (NETCONN_P(proc) && GNUTLS_PROCESS_USABLE (proc))
5660 rv = emacs_gnutls_write (outfd,
5661 XPROCESS (proc)->gnutls_state,
5662 (char *) buf, this);
5663 else
5664#endif
5665 rv = emacs_write (outfd, (char *) buf, this);
5544#ifdef ADAPTIVE_READ_BUFFERING 5666#ifdef ADAPTIVE_READ_BUFFERING
5545 if (p->read_output_delay > 0 5667 if (p->read_output_delay > 0
5546 && p->adaptive_read_buffering == 1) 5668 && p->adaptive_read_buffering == 1)
@@ -5651,7 +5773,7 @@ Output from processes can arrive in between bunches. */)
5651 (Lisp_Object process, Lisp_Object start, Lisp_Object end) 5773 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5652{ 5774{
5653 Lisp_Object proc; 5775 Lisp_Object proc;
5654 int start1, end1; 5776 EMACS_INT start1, end1;
5655 5777
5656 proc = get_process (process); 5778 proc = get_process (process);
5657 validate_region (&start, &end); 5779 validate_region (&start, &end);
@@ -6592,8 +6714,8 @@ status_notify (struct Lisp_Process *deleting_process)
6592 { 6714 {
6593 Lisp_Object tem; 6715 Lisp_Object tem;
6594 struct buffer *old = current_buffer; 6716 struct buffer *old = current_buffer;
6595 int opoint, opoint_byte; 6717 EMACS_INT opoint, opoint_byte;
6596 int before, before_byte; 6718 EMACS_INT before, before_byte;
6597 6719
6598 /* Avoid error if buffer is deleted 6720 /* Avoid error if buffer is deleted
6599 (probably that's why the process is dead, too) */ 6721 (probably that's why the process is dead, too) */
@@ -6711,35 +6833,16 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6711 6833
6712 6834
6713 6835
6714static int add_gpm_wait_descriptor_called_flag;
6715
6716void 6836void
6717add_gpm_wait_descriptor (int desc) 6837add_gpm_wait_descriptor (int desc)
6718{ 6838{
6719 if (! add_gpm_wait_descriptor_called_flag) 6839 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} 6840}
6727 6841
6728void 6842void
6729delete_gpm_wait_descriptor (int desc) 6843delete_gpm_wait_descriptor (int desc)
6730{ 6844{
6731 int fd; 6845 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} 6846}
6744 6847
6745/* Return nonzero if *MASK has a bit set 6848/* Return nonzero if *MASK has a bit set
@@ -6750,7 +6853,7 @@ keyboard_bit_set (fd_set *mask)
6750{ 6853{
6751 int fd; 6854 int fd;
6752 6855
6753 for (fd = 0; fd <= max_keyboard_desc; fd++) 6856 for (fd = 0; fd <= max_input_desc; fd++)
6754 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask) 6857 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask)
6755 && !FD_ISSET (fd, &non_keyboard_wait_mask)) 6858 && !FD_ISSET (fd, &non_keyboard_wait_mask))
6756 return 1; 6859 return 1;
@@ -6989,11 +7092,11 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
6989void 7092void
6990add_keyboard_wait_descriptor (int desc) 7093add_keyboard_wait_descriptor (int desc)
6991{ 7094{
6992#ifdef subprocesses 7095#ifdef subprocesses /* actually means "not MSDOS" */
6993 FD_SET (desc, &input_wait_mask); 7096 FD_SET (desc, &input_wait_mask);
6994 FD_SET (desc, &non_process_wait_mask); 7097 FD_SET (desc, &non_process_wait_mask);
6995 if (desc > max_keyboard_desc) 7098 if (desc > max_input_desc)
6996 max_keyboard_desc = desc; 7099 max_input_desc = desc;
6997#endif 7100#endif
6998} 7101}
6999 7102
@@ -7004,18 +7107,16 @@ delete_keyboard_wait_descriptor (int desc)
7004{ 7107{
7005#ifdef subprocesses 7108#ifdef subprocesses
7006 int fd; 7109 int fd;
7007 int lim = max_keyboard_desc; 7110 int lim = max_input_desc;
7008 7111
7009 FD_CLR (desc, &input_wait_mask); 7112 FD_CLR (desc, &input_wait_mask);
7010 FD_CLR (desc, &non_process_wait_mask); 7113 FD_CLR (desc, &non_process_wait_mask);
7011 7114
7012 if (desc == max_keyboard_desc) 7115 if (desc == max_input_desc)
7013 for (fd = 0; fd < lim; fd++) 7116 for (fd = 0; fd < lim; fd++)
7014 if (FD_ISSET (fd, &input_wait_mask) 7117 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
7015 && !FD_ISSET (fd, &non_keyboard_wait_mask) 7118 max_input_desc = fd;
7016 && !FD_ISSET (fd, &gpm_wait_mask)) 7119#endif
7017 max_keyboard_desc = fd;
7018#endif /* subprocesses */
7019} 7120}
7020 7121
7021/* Setup coding systems of PROCESS. */ 7122/* Setup coding systems of PROCESS. */
@@ -7272,7 +7373,9 @@ init_process (void)
7272 FD_ZERO (&input_wait_mask); 7373 FD_ZERO (&input_wait_mask);
7273 FD_ZERO (&non_keyboard_wait_mask); 7374 FD_ZERO (&non_keyboard_wait_mask);
7274 FD_ZERO (&non_process_wait_mask); 7375 FD_ZERO (&non_process_wait_mask);
7376 FD_ZERO (&write_mask);
7275 max_process_desc = 0; 7377 max_process_desc = 0;
7378 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7276 7379
7277#ifdef NON_BLOCKING_CONNECT 7380#ifdef NON_BLOCKING_CONNECT
7278 FD_ZERO (&connect_wait_mask); 7381 FD_ZERO (&connect_wait_mask);