aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorJoakim Verona2010-10-18 22:05:07 +0200
committerJoakim Verona2010-10-18 22:05:07 +0200
commit13cfe8df462ab8da9f0028e16cc84dcaceaca3d1 (patch)
tree723f254768f9e503504ab4c8b68801f80a56591a /src/process.c
parent35f4b80a934b299b3b18e62f5db44f64c240e65b (diff)
parente48eb34332dc91de823314090451459ba2ffacbf (diff)
downloademacs-13cfe8df462ab8da9f0028e16cc84dcaceaca3d1.tar.gz
emacs-13cfe8df462ab8da9f0028e16cc84dcaceaca3d1.zip
merge from upstream
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c350
1 files changed, 229 insertions, 121 deletions
diff --git a/src/process.c b/src/process.c
index f348dca7d35..e1515065957 100644
--- a/src/process.c
+++ b/src/process.c
@@ -31,7 +31,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#ifdef HAVE_INTTYPES_H 31#ifdef HAVE_INTTYPES_H
32#include <inttypes.h> 32#include <inttypes.h>
33#endif 33#endif
34#include <stdlib.h>
35 34
36#ifdef HAVE_UNISTD_H 35#ifdef HAVE_UNISTD_H
37#include <unistd.h> 36#include <unistd.h>
@@ -68,10 +67,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
68#include <bsdtty.h> 67#include <bsdtty.h>
69#endif 68#endif
70 69
71#ifdef HAVE_SYS_WAIT
72#include <sys/wait.h>
73#endif
74
75#ifdef HAVE_RES_INIT 70#ifdef HAVE_RES_INIT
76#include <netinet/in.h> 71#include <netinet/in.h>
77#include <arpa/nameser.h> 72#include <arpa/nameser.h>
@@ -82,6 +77,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
82#include <util.h> 77#include <util.h>
83#endif 78#endif
84 79
80#ifdef HAVE_PTY_H
81#include <pty.h>
82#endif
83
85#endif /* subprocesses */ 84#endif /* subprocesses */
86 85
87#include "lisp.h" 86#include "lisp.h"
@@ -105,6 +104,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
105#include "sysselect.h" 104#include "sysselect.h"
106#include "syssignal.h" 105#include "syssignal.h"
107#include "syswait.h" 106#include "syswait.h"
107#ifdef HAVE_GNUTLS
108#include "gnutls.h"
109#endif
108 110
109#if defined (USE_GTK) || defined (HAVE_GCONF) 111#if defined (USE_GTK) || defined (HAVE_GCONF)
110#include "xgselect.h" 112#include "xgselect.h"
@@ -112,6 +114,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
112#ifdef HAVE_NS 114#ifdef HAVE_NS
113#include "nsterm.h" 115#include "nsterm.h"
114#endif 116#endif
117
115extern int timers_run; 118extern int timers_run;
116 119
117Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; 120Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
@@ -168,13 +171,6 @@ extern Lisp_Object QCfilter;
168/* Define first descriptor number available for subprocesses. */ 171/* Define first descriptor number available for subprocesses. */
169#define FIRST_PROC_DESC 3 172#define FIRST_PROC_DESC 3
170 173
171/* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
172 testing SIGCHLD. */
173
174#if !defined (SIGCHLD) && defined (SIGCLD)
175#define SIGCHLD SIGCLD
176#endif /* SIGCLD */
177
178extern const char *get_operating_system_release (void); 174extern const char *get_operating_system_release (void);
179 175
180/* From sysdep.c or w32.c */ 176/* From sysdep.c or w32.c */
@@ -198,8 +194,10 @@ int update_tick;
198 194
199/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */ 195/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */
200 196
197/* Only W32 has this, it really means that select can't take write mask. */
201#ifdef BROKEN_NON_BLOCKING_CONNECT 198#ifdef BROKEN_NON_BLOCKING_CONNECT
202#undef NON_BLOCKING_CONNECT 199#undef NON_BLOCKING_CONNECT
200#define SELECT_CANT_DO_WRITE_MASK
203#else 201#else
204#ifndef NON_BLOCKING_CONNECT 202#ifndef NON_BLOCKING_CONNECT
205#ifdef HAVE_SELECT 203#ifdef HAVE_SELECT
@@ -291,9 +289,9 @@ static SELECT_TYPE non_keyboard_wait_mask;
291 289
292static SELECT_TYPE non_process_wait_mask; 290static SELECT_TYPE non_process_wait_mask;
293 291
294/* Mask for the gpm mouse input descriptor. */ 292/* Mask for selecting for write. */
295 293
296static SELECT_TYPE gpm_wait_mask; 294static SELECT_TYPE write_mask;
297 295
298#ifdef NON_BLOCKING_CONNECT 296#ifdef NON_BLOCKING_CONNECT
299/* Mask of bits indicating the descriptors that we wait for connect to 297/* Mask of bits indicating the descriptors that we wait for connect to
@@ -313,11 +311,8 @@ static int num_pending_connects;
313/* The largest descriptor currently in use for a process object. */ 311/* The largest descriptor currently in use for a process object. */
314static int max_process_desc; 312static int max_process_desc;
315 313
316/* The largest descriptor currently in use for keyboard input. */ 314/* The largest descriptor currently in use for input. */
317static int max_keyboard_desc; 315static int max_input_desc;
318
319/* The largest descriptor currently in use for gpm mouse input. */
320static int max_gpm_desc;
321 316
322/* Indexed by descriptor, gives the process (if any) for that descriptor */ 317/* Indexed by descriptor, gives the process (if any) for that descriptor */
323Lisp_Object chan_process[MAXDESC]; 318Lisp_Object chan_process[MAXDESC];
@@ -354,14 +349,90 @@ struct sockaddr_and_len {
354/* Maximum number of bytes to send to a pty without an eof. */ 349/* Maximum number of bytes to send to a pty without an eof. */
355static int pty_max_bytes; 350static int pty_max_bytes;
356 351
357#ifdef HAVE_PTYS 352
358#ifdef HAVE_PTY_H 353
359#include <pty.h> 354struct fd_callback_data
360#endif 355{
361/* The file name of the pty opened by allocate_pty. */ 356 fd_callback func;
357 void *data;
358#define FOR_READ 1
359#define FOR_WRITE 2
360 int condition; /* mask of the defines above. */
361} fd_callback_info[MAXDESC];
362
363
364/* Add a file descriptor FD to be monitored for when read is possible.
365 When read is possible, call FUNC with argument DATA. */
366
367void
368add_read_fd (int fd, fd_callback func, void *data)
369{
370 xassert (fd < MAXDESC);
371 add_keyboard_wait_descriptor (fd);
372
373 fd_callback_info[fd].func = func;
374 fd_callback_info[fd].data = data;
375 fd_callback_info[fd].condition |= FOR_READ;
376}
377
378/* Stop monitoring file descriptor FD for when read is possible. */
379
380void
381delete_read_fd (int fd)
382{
383 xassert (fd < MAXDESC);
384 delete_keyboard_wait_descriptor (fd);
385
386 fd_callback_info[fd].condition &= ~FOR_READ;
387 if (fd_callback_info[fd].condition == 0)
388 {
389 fd_callback_info[fd].func = 0;
390 fd_callback_info[fd].data = 0;
391 }
392}
393
394/* Add a file descriptor FD to be monitored for when write is possible.
395 When write is possible, call FUNC with argument DATA. */
396
397void
398add_write_fd (int fd, fd_callback func, void *data)
399{
400 xassert (fd < MAXDESC);
401 FD_SET (fd, &write_mask);
402 if (fd > max_input_desc)
403 max_input_desc = fd;
404
405 fd_callback_info[fd].func = func;
406 fd_callback_info[fd].data = data;
407 fd_callback_info[fd].condition |= FOR_WRITE;
408}
409
410/* Stop monitoring file descriptor FD for when write is possible. */
411
412void
413delete_write_fd (int fd)
414{
415 int lim = max_input_desc;
416
417 xassert (fd < MAXDESC);
418 FD_CLR (fd, &write_mask);
419 fd_callback_info[fd].condition &= ~FOR_WRITE;
420 if (fd_callback_info[fd].condition == 0)
421 {
422 fd_callback_info[fd].func = 0;
423 fd_callback_info[fd].data = 0;
424
425 if (fd == max_input_desc)
426 for (fd = lim; fd >= 0; fd--)
427 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
428 {
429 max_input_desc = fd;
430 break;
431 }
432
433 }
434}
362 435
363static char pty_name[24];
364#endif
365 436
366/* Compute the Lisp form of the process status, p->status, from 437/* Compute the Lisp form of the process status, p->status, from
367 the numeric status that was returned by `wait'. */ 438 the numeric status that was returned by `wait'. */
@@ -477,6 +548,9 @@ status_message (struct Lisp_Process *p)
477 548
478#ifdef HAVE_PTYS 549#ifdef HAVE_PTYS
479 550
551/* The file name of the pty opened by allocate_pty. */
552static char pty_name[24];
553
480/* Open an available pty, returning a file descriptor. 554/* Open an available pty, returning a file descriptor.
481 Return -1 on failure. 555 Return -1 on failure.
482 The file name of the terminal corresponding to the pty 556 The file name of the terminal corresponding to the pty
@@ -583,6 +657,12 @@ make_process (Lisp_Object name)
583 p->read_output_skip = 0; 657 p->read_output_skip = 0;
584#endif 658#endif
585 659
660#ifdef HAVE_GNUTLS
661 p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
662 p->gnutls_log_level = 0;
663 p->gnutls_p = 0;
664#endif
665
586 /* If name is already in use, modify it until it is unused. */ 666 /* If name is already in use, modify it until it is unused. */
587 667
588 name1 = name; 668 name1 = name;
@@ -1526,6 +1606,12 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1526 XPROCESS (proc)->filter = Qnil; 1606 XPROCESS (proc)->filter = Qnil;
1527 XPROCESS (proc)->command = Flist (nargs - 2, args + 2); 1607 XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
1528 1608
1609#ifdef HAVE_GNUTLS
1610 /* AKA GNUTLS_INITSTAGE(proc). */
1611 XPROCESS (proc)->gnutls_initstage = GNUTLS_STAGE_EMPTY;
1612 XPROCESS (proc)->gnutls_cred_type = Qnil;
1613#endif
1614
1529#ifdef ADAPTIVE_READ_BUFFERING 1615#ifdef ADAPTIVE_READ_BUFFERING
1530 XPROCESS (proc)->adaptive_read_buffering 1616 XPROCESS (proc)->adaptive_read_buffering
1531 = (NILP (Vprocess_adaptive_read_buffering) ? 0 1617 = (NILP (Vprocess_adaptive_read_buffering) ? 0
@@ -1584,6 +1670,11 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1584 val = XCDR (Vdefault_process_coding_system); 1670 val = XCDR (Vdefault_process_coding_system);
1585 } 1671 }
1586 XPROCESS (proc)->encode_coding_system = val; 1672 XPROCESS (proc)->encode_coding_system = val;
1673 /* Note: At this momemnt, the above coding system may leave
1674 text-conversion or eol-conversion unspecified. They will be
1675 decided after we read output from the process and decode it by
1676 some coding system, or just before we actually send a text to
1677 the process. */
1587 } 1678 }
1588 1679
1589 1680
@@ -1626,6 +1717,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1626 tem = Fsubstring (tem, make_number (2), Qnil); 1717 tem = Fsubstring (tem, make_number (2), Qnil);
1627 1718
1628 { 1719 {
1720 Lisp_Object arg_encoding = Qnil;
1629 struct gcpro gcpro1; 1721 struct gcpro gcpro1;
1630 GCPRO1 (tem); 1722 GCPRO1 (tem);
1631 1723
@@ -1643,9 +1735,14 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1643 tem = Fcons (args[i], tem); 1735 tem = Fcons (args[i], tem);
1644 CHECK_STRING (XCAR (tem)); 1736 CHECK_STRING (XCAR (tem));
1645 if (STRING_MULTIBYTE (XCAR (tem))) 1737 if (STRING_MULTIBYTE (XCAR (tem)))
1646 XSETCAR (tem, 1738 {
1647 code_convert_string_norecord 1739 if (NILP (arg_encoding))
1648 (XCAR (tem), XPROCESS (proc)->encode_coding_system, 1)); 1740 arg_encoding = (complement_process_encoding_system
1741 (XPROCESS (proc)->encode_coding_system));
1742 XSETCAR (tem,
1743 code_convert_string_norecord
1744 (XCAR (tem), arg_encoding, 1));
1745 }
1649 } 1746 }
1650 1747
1651 UNGCPRO; 1748 UNGCPRO;
@@ -1781,12 +1878,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1781 } 1878 }
1782#endif 1879#endif
1783 1880
1784#if 0
1785 /* Replaced by close_process_descs */
1786 set_exclusive_use (inchannel);
1787 set_exclusive_use (outchannel);
1788#endif
1789
1790#ifdef O_NONBLOCK 1881#ifdef O_NONBLOCK
1791 fcntl (inchannel, F_SETFL, O_NONBLOCK); 1882 fcntl (inchannel, F_SETFL, O_NONBLOCK);
1792 fcntl (outchannel, F_SETFL, O_NONBLOCK); 1883 fcntl (outchannel, F_SETFL, O_NONBLOCK);
@@ -3170,7 +3261,9 @@ usage: (make-network-process &rest ARGS) */)
3170 if (!NILP (host)) 3261 if (!NILP (host))
3171 { 3262 {
3172 if (EQ (host, Qlocal)) 3263 if (EQ (host, Qlocal))
3173 host = build_string ("localhost"); 3264 /* Depending on setup, "localhost" may map to different IPv4 and/or
3265 IPv6 addresses, so it's better to be explicit. (Bug#6781) */
3266 host = build_string ("127.0.0.1");
3174 CHECK_STRING (host); 3267 CHECK_STRING (host);
3175 } 3268 }
3176 3269
@@ -3605,6 +3698,7 @@ usage: (make-network-process &rest ARGS) */)
3605 if (!FD_ISSET (inch, &connect_wait_mask)) 3698 if (!FD_ISSET (inch, &connect_wait_mask))
3606 { 3699 {
3607 FD_SET (inch, &connect_wait_mask); 3700 FD_SET (inch, &connect_wait_mask);
3701 FD_SET (inch, &write_mask);
3608 num_pending_connects++; 3702 num_pending_connects++;
3609 } 3703 }
3610 } 3704 }
@@ -4008,6 +4102,7 @@ deactivate_process (Lisp_Object proc)
4008 if (FD_ISSET (inchannel, &connect_wait_mask)) 4102 if (FD_ISSET (inchannel, &connect_wait_mask))
4009 { 4103 {
4010 FD_CLR (inchannel, &connect_wait_mask); 4104 FD_CLR (inchannel, &connect_wait_mask);
4105 FD_CLR (inchannel, &write_mask);
4011 if (--num_pending_connects < 0) 4106 if (--num_pending_connects < 0)
4012 abort (); 4107 abort ();
4013 } 4108 }
@@ -4386,10 +4481,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4386{ 4481{
4387 register int channel, nfds; 4482 register int channel, nfds;
4388 SELECT_TYPE Available; 4483 SELECT_TYPE Available;
4389#ifdef NON_BLOCKING_CONNECT 4484 SELECT_TYPE Writeok;
4390 SELECT_TYPE Connecting; 4485 int check_write;
4391 int check_connect;
4392#endif
4393 int check_delay, no_avail; 4486 int check_delay, no_avail;
4394 int xerrno; 4487 int xerrno;
4395 Lisp_Object proc; 4488 Lisp_Object proc;
@@ -4399,11 +4492,9 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4399 int count = SPECPDL_INDEX (); 4492 int count = SPECPDL_INDEX ();
4400 4493
4401 FD_ZERO (&Available); 4494 FD_ZERO (&Available);
4402#ifdef NON_BLOCKING_CONNECT 4495 FD_ZERO (&Writeok);
4403 FD_ZERO (&Connecting);
4404#endif
4405 4496
4406 if (time_limit == 0 && wait_proc && !NILP (Vinhibit_quit) 4497 if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit)
4407 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit))) 4498 && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit)))
4408 message ("Blocking call to accept-process-output with quit inhibited!!"); 4499 message ("Blocking call to accept-process-output with quit inhibited!!");
4409 4500
@@ -4537,19 +4628,16 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4537 if (update_tick != process_tick) 4628 if (update_tick != process_tick)
4538 { 4629 {
4539 SELECT_TYPE Atemp; 4630 SELECT_TYPE Atemp;
4540#ifdef NON_BLOCKING_CONNECT
4541 SELECT_TYPE Ctemp; 4631 SELECT_TYPE Ctemp;
4542#endif
4543 4632
4544 if (kbd_on_hold_p ()) 4633 if (kbd_on_hold_p ())
4545 FD_ZERO (&Atemp); 4634 FD_ZERO (&Atemp);
4546 else 4635 else
4547 Atemp = input_wait_mask; 4636 Atemp = input_wait_mask;
4548 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); 4637 Ctemp = write_mask;
4549 4638
4550 EMACS_SET_SECS_USECS (timeout, 0, 0); 4639 EMACS_SET_SECS_USECS (timeout, 0, 0);
4551 if ((select (max (max (max_process_desc, max_keyboard_desc), 4640 if ((select (max (max_process_desc, max_input_desc) + 1,
4552 max_gpm_desc) + 1,
4553 &Atemp, 4641 &Atemp,
4554#ifdef NON_BLOCKING_CONNECT 4642#ifdef NON_BLOCKING_CONNECT
4555 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), 4643 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0),
@@ -4620,13 +4708,13 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4620 break; 4708 break;
4621 FD_SET (wait_proc->infd, &Available); 4709 FD_SET (wait_proc->infd, &Available);
4622 check_delay = 0; 4710 check_delay = 0;
4623 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4711 check_write = 0;
4624 } 4712 }
4625 else if (!NILP (wait_for_cell)) 4713 else if (!NILP (wait_for_cell))
4626 { 4714 {
4627 Available = non_process_wait_mask; 4715 Available = non_process_wait_mask;
4628 check_delay = 0; 4716 check_delay = 0;
4629 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4717 check_write = 0;
4630 } 4718 }
4631 else 4719 else
4632 { 4720 {
@@ -4634,7 +4722,12 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4634 Available = non_keyboard_wait_mask; 4722 Available = non_keyboard_wait_mask;
4635 else 4723 else
4636 Available = input_wait_mask; 4724 Available = input_wait_mask;
4637 IF_NON_BLOCKING_CONNECT (check_connect = (num_pending_connects > 0)); 4725 Writeok = write_mask;
4726#ifdef SELECT_CANT_DO_WRITE_MASK
4727 check_write = 0;
4728#else
4729 check_write = 1;
4730#endif
4638 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; 4731 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count;
4639 } 4732 }
4640 4733
@@ -4659,10 +4752,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4659 } 4752 }
4660 else 4753 else
4661 { 4754 {
4662#ifdef NON_BLOCKING_CONNECT
4663 if (check_connect)
4664 Connecting = connect_wait_mask;
4665#endif
4666 4755
4667#ifdef ADAPTIVE_READ_BUFFERING 4756#ifdef ADAPTIVE_READ_BUFFERING
4668 /* Set the timeout for adaptive read buffering if any 4757 /* Set the timeout for adaptive read buffering if any
@@ -4704,15 +4793,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4704#else 4793#else
4705 nfds = select 4794 nfds = select
4706#endif 4795#endif
4707 (max (max (max_process_desc, max_keyboard_desc), 4796 (max (max_process_desc, max_input_desc) + 1,
4708 max_gpm_desc) + 1, 4797 &Available,
4709 &Available, 4798 (check_write ? &Writeok : (SELECT_TYPE *)0),
4710#ifdef NON_BLOCKING_CONNECT 4799 (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 } 4800 }
4717 4801
4718 xerrno = errno; 4802 xerrno = errno;
@@ -4752,7 +4836,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4752 if (no_avail) 4836 if (no_avail)
4753 { 4837 {
4754 FD_ZERO (&Available); 4838 FD_ZERO (&Available);
4755 IF_NON_BLOCKING_CONNECT (check_connect = 0); 4839 check_write = 0;
4756 } 4840 }
4757 4841
4758#if 0 /* When polling is used, interrupt_input is 0, 4842#if 0 /* When polling is used, interrupt_input is 0,
@@ -4848,12 +4932,26 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4848 if (no_avail || nfds == 0) 4932 if (no_avail || nfds == 0)
4849 continue; 4933 continue;
4850 4934
4935 for (channel = 0; channel <= max_input_desc; ++channel)
4936 {
4937 struct fd_callback_data *d = &fd_callback_info[channel];
4938 if (FD_ISSET (channel, &Available)
4939 && d->func != 0
4940 && (d->condition & FOR_READ) != 0)
4941 d->func (channel, d->data, 1);
4942 if (FD_ISSET (channel, &write_mask)
4943 && d->func != 0
4944 && (d->condition & FOR_WRITE) != 0)
4945 d->func (channel, d->data, 0);
4946 }
4947
4851 /* Really FIRST_PROC_DESC should be 0 on Unix, 4948 /* Really FIRST_PROC_DESC should be 0 on Unix,
4852 but this is safer in the short run. */ 4949 but this is safer in the short run. */
4853 for (channel = 0; channel <= max_process_desc; channel++) 4950 for (channel = 0; channel <= max_process_desc; channel++)
4854 { 4951 {
4855 if (FD_ISSET (channel, &Available) 4952 if (FD_ISSET (channel, &Available)
4856 && FD_ISSET (channel, &non_keyboard_wait_mask)) 4953 && FD_ISSET (channel, &non_keyboard_wait_mask)
4954 && !FD_ISSET (channel, &non_process_wait_mask))
4857 { 4955 {
4858 int nread; 4956 int nread;
4859 4957
@@ -4958,12 +5056,13 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4958 } 5056 }
4959 } 5057 }
4960#ifdef NON_BLOCKING_CONNECT 5058#ifdef NON_BLOCKING_CONNECT
4961 if (check_connect && FD_ISSET (channel, &Connecting) 5059 if (FD_ISSET (channel, &Writeok)
4962 && FD_ISSET (channel, &connect_wait_mask)) 5060 && FD_ISSET (channel, &connect_wait_mask))
4963 { 5061 {
4964 struct Lisp_Process *p; 5062 struct Lisp_Process *p;
4965 5063
4966 FD_CLR (channel, &connect_wait_mask); 5064 FD_CLR (channel, &connect_wait_mask);
5065 FD_CLR (channel, &write_mask);
4967 if (--num_pending_connects < 0) 5066 if (--num_pending_connects < 0)
4968 abort (); 5067 abort ();
4969 5068
@@ -5073,7 +5172,7 @@ read_process_output (Lisp_Object proc, register int channel)
5073 char *chars; 5172 char *chars;
5074 register Lisp_Object outstream; 5173 register Lisp_Object outstream;
5075 register struct Lisp_Process *p = XPROCESS (proc); 5174 register struct Lisp_Process *p = XPROCESS (proc);
5076 register int opoint; 5175 register EMACS_INT opoint;
5077 struct coding_system *coding = proc_decode_coding_system[channel]; 5176 struct coding_system *coding = proc_decode_coding_system[channel];
5078 int carryover = p->decoding_carryover; 5177 int carryover = p->decoding_carryover;
5079 int readmax = 4096; 5178 int readmax = 4096;
@@ -5097,7 +5196,13 @@ read_process_output (Lisp_Object proc, register int channel)
5097#endif 5196#endif
5098 if (proc_buffered_char[channel] < 0) 5197 if (proc_buffered_char[channel] < 0)
5099 { 5198 {
5100 nbytes = emacs_read (channel, chars + carryover, readmax); 5199#ifdef HAVE_GNUTLS
5200 if (XPROCESS (proc)->gnutls_p)
5201 nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
5202 chars + carryover, readmax);
5203 else
5204#endif
5205 nbytes = emacs_read (channel, chars + carryover, readmax);
5101#ifdef ADAPTIVE_READ_BUFFERING 5206#ifdef ADAPTIVE_READ_BUFFERING
5102 if (nbytes > 0 && p->adaptive_read_buffering) 5207 if (nbytes > 0 && p->adaptive_read_buffering)
5103 { 5208 {
@@ -5130,7 +5235,13 @@ read_process_output (Lisp_Object proc, register int channel)
5130 { 5235 {
5131 chars[carryover] = proc_buffered_char[channel]; 5236 chars[carryover] = proc_buffered_char[channel];
5132 proc_buffered_char[channel] = -1; 5237 proc_buffered_char[channel] = -1;
5133 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1); 5238#ifdef HAVE_GNUTLS
5239 if (XPROCESS (proc)->gnutls_p)
5240 nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
5241 chars + carryover + 1, readmax - 1);
5242 else
5243#endif
5244 nbytes = emacs_read (channel, chars + carryover + 1, readmax - 1);
5134 if (nbytes < 0) 5245 if (nbytes < 0)
5135 nbytes = 1; 5246 nbytes = 1;
5136 else 5247 else
@@ -5263,10 +5374,10 @@ read_process_output (Lisp_Object proc, register int channel)
5263 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name)) 5374 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name))
5264 { 5375 {
5265 Lisp_Object old_read_only; 5376 Lisp_Object old_read_only;
5266 int old_begv, old_zv; 5377 EMACS_INT old_begv, old_zv;
5267 int old_begv_byte, old_zv_byte; 5378 EMACS_INT old_begv_byte, old_zv_byte;
5268 int before, before_byte; 5379 EMACS_INT before, before_byte;
5269 int opoint_byte; 5380 EMACS_INT opoint_byte;
5270 Lisp_Object text; 5381 Lisp_Object text;
5271 struct buffer *b; 5382 struct buffer *b;
5272 5383
@@ -5403,11 +5514,11 @@ send_process_trap (int ignore)
5403 5514
5404static void 5515static void
5405send_process (volatile Lisp_Object proc, const unsigned char *volatile buf, 5516send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5406 volatile int len, volatile Lisp_Object object) 5517 volatile EMACS_INT len, volatile Lisp_Object object)
5407{ 5518{
5408 /* Use volatile to protect variables from being clobbered by longjmp. */ 5519 /* Use volatile to protect variables from being clobbered by longjmp. */
5409 struct Lisp_Process *p = XPROCESS (proc); 5520 struct Lisp_Process *p = XPROCESS (proc);
5410 int rv; 5521 EMACS_INT rv;
5411 struct coding_system *coding; 5522 struct coding_system *coding;
5412 struct gcpro gcpro1; 5523 struct gcpro gcpro1;
5413 SIGTYPE (*volatile old_sigpipe) (int); 5524 SIGTYPE (*volatile old_sigpipe) (int);
@@ -5429,12 +5540,21 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5429 && !NILP (XBUFFER (object)->enable_multibyte_characters)) 5540 && !NILP (XBUFFER (object)->enable_multibyte_characters))
5430 || EQ (object, Qt)) 5541 || EQ (object, Qt))
5431 { 5542 {
5543 p->encode_coding_system
5544 = complement_process_encoding_system (p->encode_coding_system);
5432 if (!EQ (Vlast_coding_system_used, p->encode_coding_system)) 5545 if (!EQ (Vlast_coding_system_used, p->encode_coding_system))
5433 /* The coding system for encoding was changed to raw-text 5546 {
5434 because we sent a unibyte text previously. Now we are 5547 /* The coding system for encoding was changed to raw-text
5435 sending a multibyte text, thus we must encode it by the 5548 because we sent a unibyte text previously. Now we are
5436 original coding system specified for the current process. */ 5549 sending a multibyte text, thus we must encode it by the
5437 setup_coding_system (p->encode_coding_system, coding); 5550 original coding system specified for the current process.
5551
5552 Another reason we comming here is that the coding system
5553 was just complemented and new one was returned by
5554 complement_process_encoding_system. */
5555 setup_coding_system (p->encode_coding_system, coding);
5556 Vlast_coding_system_used = p->encode_coding_system;
5557 }
5438 coding->src_multibyte = 1; 5558 coding->src_multibyte = 1;
5439 } 5559 }
5440 else 5560 else
@@ -5464,8 +5584,8 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5464 coding->dst_object = Qt; 5584 coding->dst_object = Qt;
5465 if (BUFFERP (object)) 5585 if (BUFFERP (object))
5466 { 5586 {
5467 int from_byte, from, to; 5587 EMACS_INT from_byte, from, to;
5468 int save_pt, save_pt_byte; 5588 EMACS_INT save_pt, save_pt_byte;
5469 struct buffer *cur = current_buffer; 5589 struct buffer *cur = current_buffer;
5470 5590
5471 set_buffer_internal (XBUFFER (object)); 5591 set_buffer_internal (XBUFFER (object));
@@ -5517,7 +5637,7 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5517 process_sent_to = proc; 5637 process_sent_to = proc;
5518 while (len > 0) 5638 while (len > 0)
5519 { 5639 {
5520 int this = len; 5640 EMACS_INT this = len;
5521 5641
5522 /* Send this batch, using one or more write calls. */ 5642 /* Send this batch, using one or more write calls. */
5523 while (this > 0) 5643 while (this > 0)
@@ -5540,7 +5660,14 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5540 else 5660 else
5541#endif 5661#endif
5542 { 5662 {
5543 rv = emacs_write (outfd, (char *) buf, this); 5663#ifdef HAVE_GNUTLS
5664 if (XPROCESS (proc)->gnutls_p)
5665 rv = emacs_gnutls_write (outfd,
5666 XPROCESS (proc),
5667 (char *) buf, this);
5668 else
5669#endif
5670 rv = emacs_write (outfd, (char *) buf, this);
5544#ifdef ADAPTIVE_READ_BUFFERING 5671#ifdef ADAPTIVE_READ_BUFFERING
5545 if (p->read_output_delay > 0 5672 if (p->read_output_delay > 0
5546 && p->adaptive_read_buffering == 1) 5673 && p->adaptive_read_buffering == 1)
@@ -5651,7 +5778,7 @@ Output from processes can arrive in between bunches. */)
5651 (Lisp_Object process, Lisp_Object start, Lisp_Object end) 5778 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5652{ 5779{
5653 Lisp_Object proc; 5780 Lisp_Object proc;
5654 int start1, end1; 5781 EMACS_INT start1, end1;
5655 5782
5656 proc = get_process (process); 5783 proc = get_process (process);
5657 validate_region (&start, &end); 5784 validate_region (&start, &end);
@@ -6592,8 +6719,8 @@ status_notify (struct Lisp_Process *deleting_process)
6592 { 6719 {
6593 Lisp_Object tem; 6720 Lisp_Object tem;
6594 struct buffer *old = current_buffer; 6721 struct buffer *old = current_buffer;
6595 int opoint, opoint_byte; 6722 EMACS_INT opoint, opoint_byte;
6596 int before, before_byte; 6723 EMACS_INT before, before_byte;
6597 6724
6598 /* Avoid error if buffer is deleted 6725 /* Avoid error if buffer is deleted
6599 (probably that's why the process is dead, too) */ 6726 (probably that's why the process is dead, too) */
@@ -6711,35 +6838,16 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6711 6838
6712 6839
6713 6840
6714static int add_gpm_wait_descriptor_called_flag;
6715
6716void 6841void
6717add_gpm_wait_descriptor (int desc) 6842add_gpm_wait_descriptor (int desc)
6718{ 6843{
6719 if (! add_gpm_wait_descriptor_called_flag) 6844 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} 6845}
6727 6846
6728void 6847void
6729delete_gpm_wait_descriptor (int desc) 6848delete_gpm_wait_descriptor (int desc)
6730{ 6849{
6731 int fd; 6850 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} 6851}
6744 6852
6745/* Return nonzero if *MASK has a bit set 6853/* Return nonzero if *MASK has a bit set
@@ -6750,7 +6858,7 @@ keyboard_bit_set (fd_set *mask)
6750{ 6858{
6751 int fd; 6859 int fd;
6752 6860
6753 for (fd = 0; fd <= max_keyboard_desc; fd++) 6861 for (fd = 0; fd <= max_input_desc; fd++)
6754 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask) 6862 if (FD_ISSET (fd, mask) && FD_ISSET (fd, &input_wait_mask)
6755 && !FD_ISSET (fd, &non_keyboard_wait_mask)) 6863 && !FD_ISSET (fd, &non_keyboard_wait_mask))
6756 return 1; 6864 return 1;
@@ -6989,11 +7097,11 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
6989void 7097void
6990add_keyboard_wait_descriptor (int desc) 7098add_keyboard_wait_descriptor (int desc)
6991{ 7099{
6992#ifdef subprocesses 7100#ifdef subprocesses /* actually means "not MSDOS" */
6993 FD_SET (desc, &input_wait_mask); 7101 FD_SET (desc, &input_wait_mask);
6994 FD_SET (desc, &non_process_wait_mask); 7102 FD_SET (desc, &non_process_wait_mask);
6995 if (desc > max_keyboard_desc) 7103 if (desc > max_input_desc)
6996 max_keyboard_desc = desc; 7104 max_input_desc = desc;
6997#endif 7105#endif
6998} 7106}
6999 7107
@@ -7004,18 +7112,16 @@ delete_keyboard_wait_descriptor (int desc)
7004{ 7112{
7005#ifdef subprocesses 7113#ifdef subprocesses
7006 int fd; 7114 int fd;
7007 int lim = max_keyboard_desc; 7115 int lim = max_input_desc;
7008 7116
7009 FD_CLR (desc, &input_wait_mask); 7117 FD_CLR (desc, &input_wait_mask);
7010 FD_CLR (desc, &non_process_wait_mask); 7118 FD_CLR (desc, &non_process_wait_mask);
7011 7119
7012 if (desc == max_keyboard_desc) 7120 if (desc == max_input_desc)
7013 for (fd = 0; fd < lim; fd++) 7121 for (fd = 0; fd < lim; fd++)
7014 if (FD_ISSET (fd, &input_wait_mask) 7122 if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
7015 && !FD_ISSET (fd, &non_keyboard_wait_mask) 7123 max_input_desc = fd;
7016 && !FD_ISSET (fd, &gpm_wait_mask)) 7124#endif
7017 max_keyboard_desc = fd;
7018#endif /* subprocesses */
7019} 7125}
7020 7126
7021/* Setup coding systems of PROCESS. */ 7127/* Setup coding systems of PROCESS. */
@@ -7272,7 +7378,9 @@ init_process (void)
7272 FD_ZERO (&input_wait_mask); 7378 FD_ZERO (&input_wait_mask);
7273 FD_ZERO (&non_keyboard_wait_mask); 7379 FD_ZERO (&non_keyboard_wait_mask);
7274 FD_ZERO (&non_process_wait_mask); 7380 FD_ZERO (&non_process_wait_mask);
7381 FD_ZERO (&write_mask);
7275 max_process_desc = 0; 7382 max_process_desc = 0;
7383 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7276 7384
7277#ifdef NON_BLOCKING_CONNECT 7385#ifdef NON_BLOCKING_CONNECT
7278 FD_ZERO (&connect_wait_mask); 7386 FD_ZERO (&connect_wait_mask);