diff options
| author | Joakim Verona | 2012-07-27 02:22:03 +0200 |
|---|---|---|
| committer | Joakim Verona | 2012-07-27 02:22:03 +0200 |
| commit | 5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f (patch) | |
| tree | 5c55f1096a656a9759f0b53a0b5d1a2289bd366f /src/process.c | |
| parent | 0c5c85cf2b350c965bb1ffa5b2d77c2adebc406b (diff) | |
| parent | 562157c814037dcba58a20cd6908a95992c22283 (diff) | |
| download | emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.tar.gz emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.zip | |
upstream
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 372 |
1 files changed, 182 insertions, 190 deletions
diff --git a/src/process.c b/src/process.c index cb89cae99fe..1b66bef03a8 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -228,13 +228,11 @@ static EMACS_INT update_tick; | |||
| 228 | #endif | 228 | #endif |
| 229 | 229 | ||
| 230 | #if !defined (ADAPTIVE_READ_BUFFERING) && !defined (NO_ADAPTIVE_READ_BUFFERING) | 230 | #if !defined (ADAPTIVE_READ_BUFFERING) && !defined (NO_ADAPTIVE_READ_BUFFERING) |
| 231 | #ifdef EMACS_HAS_USECS | ||
| 232 | #define ADAPTIVE_READ_BUFFERING | 231 | #define ADAPTIVE_READ_BUFFERING |
| 233 | #endif | 232 | #endif |
| 234 | #endif | ||
| 235 | 233 | ||
| 236 | #ifdef ADAPTIVE_READ_BUFFERING | 234 | #ifdef ADAPTIVE_READ_BUFFERING |
| 237 | #define READ_OUTPUT_DELAY_INCREMENT 10000 | 235 | #define READ_OUTPUT_DELAY_INCREMENT (EMACS_TIME_RESOLUTION / 100) |
| 238 | #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5) | 236 | #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5) |
| 239 | #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7) | 237 | #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7) |
| 240 | 238 | ||
| @@ -251,7 +249,6 @@ static int process_output_skip; | |||
| 251 | #define process_output_delay_count 0 | 249 | #define process_output_delay_count 0 |
| 252 | #endif | 250 | #endif |
| 253 | 251 | ||
| 254 | static Lisp_Object Fget_process (Lisp_Object); | ||
| 255 | static void create_process (Lisp_Object, char **, Lisp_Object); | 252 | static void create_process (Lisp_Object, char **, Lisp_Object); |
| 256 | #ifdef SIGIO | 253 | #ifdef SIGIO |
| 257 | static int keyboard_bit_set (SELECT_TYPE *); | 254 | static int keyboard_bit_set (SELECT_TYPE *); |
| @@ -355,7 +352,7 @@ static struct fd_callback_data | |||
| 355 | void | 352 | void |
| 356 | add_read_fd (int fd, fd_callback func, void *data) | 353 | add_read_fd (int fd, fd_callback func, void *data) |
| 357 | { | 354 | { |
| 358 | xassert (fd < MAXDESC); | 355 | eassert (fd < MAXDESC); |
| 359 | add_keyboard_wait_descriptor (fd); | 356 | add_keyboard_wait_descriptor (fd); |
| 360 | 357 | ||
| 361 | fd_callback_info[fd].func = func; | 358 | fd_callback_info[fd].func = func; |
| @@ -368,7 +365,7 @@ add_read_fd (int fd, fd_callback func, void *data) | |||
| 368 | void | 365 | void |
| 369 | delete_read_fd (int fd) | 366 | delete_read_fd (int fd) |
| 370 | { | 367 | { |
| 371 | xassert (fd < MAXDESC); | 368 | eassert (fd < MAXDESC); |
| 372 | delete_keyboard_wait_descriptor (fd); | 369 | delete_keyboard_wait_descriptor (fd); |
| 373 | 370 | ||
| 374 | fd_callback_info[fd].condition &= ~FOR_READ; | 371 | fd_callback_info[fd].condition &= ~FOR_READ; |
| @@ -385,7 +382,7 @@ delete_read_fd (int fd) | |||
| 385 | void | 382 | void |
| 386 | add_write_fd (int fd, fd_callback func, void *data) | 383 | add_write_fd (int fd, fd_callback func, void *data) |
| 387 | { | 384 | { |
| 388 | xassert (fd < MAXDESC); | 385 | eassert (fd < MAXDESC); |
| 389 | FD_SET (fd, &write_mask); | 386 | FD_SET (fd, &write_mask); |
| 390 | if (fd > max_input_desc) | 387 | if (fd > max_input_desc) |
| 391 | max_input_desc = fd; | 388 | max_input_desc = fd; |
| @@ -402,7 +399,7 @@ delete_write_fd (int fd) | |||
| 402 | { | 399 | { |
| 403 | int lim = max_input_desc; | 400 | int lim = max_input_desc; |
| 404 | 401 | ||
| 405 | xassert (fd < MAXDESC); | 402 | eassert (fd < MAXDESC); |
| 406 | FD_CLR (fd, &write_mask); | 403 | FD_CLR (fd, &write_mask); |
| 407 | fd_callback_info[fd].condition &= ~FOR_WRITE; | 404 | fd_callback_info[fd].condition &= ~FOR_WRITE; |
| 408 | if (fd_callback_info[fd].condition == 0) | 405 | if (fd_callback_info[fd].condition == 0) |
| @@ -500,7 +497,7 @@ status_message (struct Lisp_Process *p) | |||
| 500 | { | 497 | { |
| 501 | int c1, c2; | 498 | int c1, c2; |
| 502 | 499 | ||
| 503 | string = make_unibyte_string (signame, strlen (signame)); | 500 | string = build_unibyte_string (signame); |
| 504 | if (! NILP (Vlocale_coding_system)) | 501 | if (! NILP (Vlocale_coding_system)) |
| 505 | string = (code_convert_string_norecord | 502 | string = (code_convert_string_norecord |
| 506 | (string, Vlocale_coding_system, 0)); | 503 | (string, Vlocale_coding_system, 0)); |
| @@ -627,35 +624,18 @@ make_process (Lisp_Object name) | |||
| 627 | printmax_t i; | 624 | printmax_t i; |
| 628 | 625 | ||
| 629 | p = allocate_process (); | 626 | p = allocate_process (); |
| 630 | 627 | /* Initialize Lisp data. Note that allocate_process initializes all | |
| 631 | p->infd = -1; | 628 | Lisp data to nil, so do it only for slots which should not be nil. */ |
| 632 | p->outfd = -1; | ||
| 633 | p->tick = 0; | ||
| 634 | p->update_tick = 0; | ||
| 635 | p->pid = 0; | ||
| 636 | p->pty_flag = 0; | ||
| 637 | p->raw_status_new = 0; | ||
| 638 | p->status = Qrun; | 629 | p->status = Qrun; |
| 639 | p->mark = Fmake_marker (); | 630 | p->mark = Fmake_marker (); |
| 640 | p->kill_without_query = 0; | ||
| 641 | p->write_queue = Qnil; | ||
| 642 | 631 | ||
| 643 | #ifdef ADAPTIVE_READ_BUFFERING | 632 | /* Initialize non-Lisp data. Note that allocate_process zeroes out all |
| 644 | p->adaptive_read_buffering = 0; | 633 | non-Lisp data, so do it only for slots which should not be zero. */ |
| 645 | p->read_output_delay = 0; | 634 | p->infd = -1; |
| 646 | p->read_output_skip = 0; | 635 | p->outfd = -1; |
| 647 | #endif | ||
| 648 | 636 | ||
| 649 | #ifdef HAVE_GNUTLS | 637 | #ifdef HAVE_GNUTLS |
| 650 | p->gnutls_initstage = GNUTLS_STAGE_EMPTY; | 638 | p->gnutls_initstage = GNUTLS_STAGE_EMPTY; |
| 651 | /* Default log level. */ | ||
| 652 | p->gnutls_log_level = 0; | ||
| 653 | /* GnuTLS handshakes attempted for this connection. */ | ||
| 654 | p->gnutls_handshakes_tried = 0; | ||
| 655 | p->gnutls_p = 0; | ||
| 656 | p->gnutls_state = NULL; | ||
| 657 | p->gnutls_x509_cred = NULL; | ||
| 658 | p->gnutls_anon_cred = NULL; | ||
| 659 | #endif | 639 | #endif |
| 660 | 640 | ||
| 661 | /* If name is already in use, modify it until it is unused. */ | 641 | /* If name is already in use, modify it until it is unused. */ |
| @@ -665,8 +645,7 @@ make_process (Lisp_Object name) | |||
| 665 | { | 645 | { |
| 666 | tem = Fget_process (name1); | 646 | tem = Fget_process (name1); |
| 667 | if (NILP (tem)) break; | 647 | if (NILP (tem)) break; |
| 668 | sprintf (suffix, "<%"pMd">", i); | 648 | name1 = concat2 (name, make_formatted_string (suffix, "<%"pMd">", i)); |
| 669 | name1 = concat2 (name, build_string (suffix)); | ||
| 670 | } | 649 | } |
| 671 | name = name1; | 650 | name = name1; |
| 672 | p->name = name; | 651 | p->name = name; |
| @@ -1047,8 +1026,8 @@ DEFUN ("set-process-window-size", Fset_process_window_size, | |||
| 1047 | (register Lisp_Object process, Lisp_Object height, Lisp_Object width) | 1026 | (register Lisp_Object process, Lisp_Object height, Lisp_Object width) |
| 1048 | { | 1027 | { |
| 1049 | CHECK_PROCESS (process); | 1028 | CHECK_PROCESS (process); |
| 1050 | CHECK_RANGED_INTEGER (0, height, INT_MAX); | 1029 | CHECK_RANGED_INTEGER (height, 0, INT_MAX); |
| 1051 | CHECK_RANGED_INTEGER (0, width, INT_MAX); | 1030 | CHECK_RANGED_INTEGER (width, 0, INT_MAX); |
| 1052 | 1031 | ||
| 1053 | if (XPROCESS (process)->infd < 0 | 1032 | if (XPROCESS (process)->infd < 0 |
| 1054 | || set_window_size (XPROCESS (process)->infd, | 1033 | || set_window_size (XPROCESS (process)->infd, |
| @@ -1108,10 +1087,6 @@ DEFUN ("process-query-on-exit-flag", | |||
| 1108 | return (XPROCESS (process)->kill_without_query ? Qnil : Qt); | 1087 | return (XPROCESS (process)->kill_without_query ? Qnil : Qt); |
| 1109 | } | 1088 | } |
| 1110 | 1089 | ||
| 1111 | #ifdef DATAGRAM_SOCKETS | ||
| 1112 | static Lisp_Object Fprocess_datagram_address (Lisp_Object); | ||
| 1113 | #endif | ||
| 1114 | |||
| 1115 | DEFUN ("process-contact", Fprocess_contact, Sprocess_contact, | 1090 | DEFUN ("process-contact", Fprocess_contact, Sprocess_contact, |
| 1116 | 1, 2, 0, | 1091 | 1, 2, 0, |
| 1117 | doc: /* Return the contact info of PROCESS; t for a real child. | 1092 | doc: /* Return the contact info of PROCESS; t for a real child. |
| @@ -1389,7 +1364,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1389 | val = Vcoding_system_for_read; | 1364 | val = Vcoding_system_for_read; |
| 1390 | if (NILP (val)) | 1365 | if (NILP (val)) |
| 1391 | { | 1366 | { |
| 1392 | args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); | 1367 | args2 = alloca ((nargs + 1) * sizeof *args2); |
| 1393 | args2[0] = Qstart_process; | 1368 | args2[0] = Qstart_process; |
| 1394 | for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; | 1369 | for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; |
| 1395 | GCPRO2 (proc, current_dir); | 1370 | GCPRO2 (proc, current_dir); |
| @@ -1408,7 +1383,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1408 | { | 1383 | { |
| 1409 | if (EQ (coding_systems, Qt)) | 1384 | if (EQ (coding_systems, Qt)) |
| 1410 | { | 1385 | { |
| 1411 | args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); | 1386 | args2 = alloca ((nargs + 1) * sizeof *args2); |
| 1412 | args2[0] = Qstart_process; | 1387 | args2[0] = Qstart_process; |
| 1413 | for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; | 1388 | for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; |
| 1414 | GCPRO2 (proc, current_dir); | 1389 | GCPRO2 (proc, current_dir); |
| @@ -1502,7 +1477,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1502 | 1477 | ||
| 1503 | /* Now that everything is encoded we can collect the strings into | 1478 | /* Now that everything is encoded we can collect the strings into |
| 1504 | NEW_ARGV. */ | 1479 | NEW_ARGV. */ |
| 1505 | new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *)); | 1480 | new_argv = alloca ((nargs - 1) * sizeof *new_argv); |
| 1506 | new_argv[nargs - 2] = 0; | 1481 | new_argv[nargs - 2] = 0; |
| 1507 | 1482 | ||
| 1508 | for (i = nargs - 2; i-- != 0; ) | 1483 | for (i = nargs - 2; i-- != 0; ) |
| @@ -1876,10 +1851,9 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1876 | So have an interrupt jar it loose. */ | 1851 | So have an interrupt jar it loose. */ |
| 1877 | { | 1852 | { |
| 1878 | struct atimer *timer; | 1853 | struct atimer *timer; |
| 1879 | EMACS_TIME offset; | 1854 | EMACS_TIME offset = make_emacs_time (1, 0); |
| 1880 | 1855 | ||
| 1881 | stop_polling (); | 1856 | stop_polling (); |
| 1882 | EMACS_SET_SECS_USECS (offset, 1, 0); | ||
| 1883 | timer = start_atimer (ATIMER_RELATIVE, offset, create_process_1, 0); | 1857 | timer = start_atimer (ATIMER_RELATIVE, offset, create_process_1, 0); |
| 1884 | 1858 | ||
| 1885 | if (forkin >= 0) | 1859 | if (forkin >= 0) |
| @@ -3038,7 +3012,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3038 | CHECK_STRING (service); | 3012 | CHECK_STRING (service); |
| 3039 | memset (&address_un, 0, sizeof address_un); | 3013 | memset (&address_un, 0, sizeof address_un); |
| 3040 | address_un.sun_family = AF_LOCAL; | 3014 | address_un.sun_family = AF_LOCAL; |
| 3041 | strncpy (address_un.sun_path, SSDATA (service), sizeof address_un.sun_path); | 3015 | if (sizeof address_un.sun_path <= SBYTES (service)) |
| 3016 | error ("Service name too long"); | ||
| 3017 | strcpy (address_un.sun_path, SSDATA (service)); | ||
| 3042 | ai.ai_addr = (struct sockaddr *) &address_un; | 3018 | ai.ai_addr = (struct sockaddr *) &address_un; |
| 3043 | ai.ai_addrlen = sizeof address_un; | 3019 | ai.ai_addrlen = sizeof address_un; |
| 3044 | goto open_socket; | 3020 | goto open_socket; |
| @@ -3291,7 +3267,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3291 | { | 3267 | { |
| 3292 | /* Unlike most other syscalls connect() cannot be called | 3268 | /* Unlike most other syscalls connect() cannot be called |
| 3293 | again. (That would return EALREADY.) The proper way to | 3269 | again. (That would return EALREADY.) The proper way to |
| 3294 | wait for completion is select(). */ | 3270 | wait for completion is pselect(). */ |
| 3295 | int sc; | 3271 | int sc; |
| 3296 | socklen_t len; | 3272 | socklen_t len; |
| 3297 | SELECT_TYPE fdset; | 3273 | SELECT_TYPE fdset; |
| @@ -3299,8 +3275,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3299 | FD_ZERO (&fdset); | 3275 | FD_ZERO (&fdset); |
| 3300 | FD_SET (s, &fdset); | 3276 | FD_SET (s, &fdset); |
| 3301 | QUIT; | 3277 | QUIT; |
| 3302 | sc = select (s + 1, (SELECT_TYPE *)0, &fdset, (SELECT_TYPE *)0, | 3278 | sc = pselect (s + 1, NULL, &fdset, NULL, NULL, NULL); |
| 3303 | (EMACS_TIME *)0); | ||
| 3304 | if (sc == -1) | 3279 | if (sc == -1) |
| 3305 | { | 3280 | { |
| 3306 | if (errno == EINTR) | 3281 | if (errno == EINTR) |
| @@ -3341,7 +3316,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3341 | { | 3316 | { |
| 3342 | if (datagram_address[s].sa) | 3317 | if (datagram_address[s].sa) |
| 3343 | abort (); | 3318 | abort (); |
| 3344 | datagram_address[s].sa = (struct sockaddr *) xmalloc (lres->ai_addrlen); | 3319 | datagram_address[s].sa = xmalloc (lres->ai_addrlen); |
| 3345 | datagram_address[s].len = lres->ai_addrlen; | 3320 | datagram_address[s].len = lres->ai_addrlen; |
| 3346 | if (is_server) | 3321 | if (is_server) |
| 3347 | { | 3322 | { |
| @@ -3743,8 +3718,9 @@ FLAGS is the current flags of the interface. */) | |||
| 3743 | 3718 | ||
| 3744 | CHECK_STRING (ifname); | 3719 | CHECK_STRING (ifname); |
| 3745 | 3720 | ||
| 3746 | memset (rq.ifr_name, 0, sizeof rq.ifr_name); | 3721 | if (sizeof rq.ifr_name <= SBYTES (ifname)) |
| 3747 | strncpy (rq.ifr_name, SSDATA (ifname), sizeof (rq.ifr_name)); | 3722 | error ("interface name too long"); |
| 3723 | strcpy (rq.ifr_name, SSDATA (ifname)); | ||
| 3748 | 3724 | ||
| 3749 | s = socket (AF_INET, SOCK_STREAM, 0); | 3725 | s = socket (AF_INET, SOCK_STREAM, 0); |
| 3750 | if (s < 0) | 3726 | if (s < 0) |
| @@ -3961,7 +3937,8 @@ If JUST-THIS-ONE is an integer, don't run any timers either. | |||
| 3961 | Return non-nil if we received any output before the timeout expired. */) | 3937 | Return non-nil if we received any output before the timeout expired. */) |
| 3962 | (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one) | 3938 | (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one) |
| 3963 | { | 3939 | { |
| 3964 | int secs = -1, usecs = 0; | 3940 | intmax_t secs; |
| 3941 | int nsecs; | ||
| 3965 | 3942 | ||
| 3966 | if (! NILP (process)) | 3943 | if (! NILP (process)) |
| 3967 | CHECK_PROCESS (process); | 3944 | CHECK_PROCESS (process); |
| @@ -3980,17 +3957,36 @@ Return non-nil if we received any output before the timeout expired. */) | |||
| 3980 | } | 3957 | } |
| 3981 | } | 3958 | } |
| 3982 | 3959 | ||
| 3960 | secs = 0; | ||
| 3961 | nsecs = -1; | ||
| 3962 | |||
| 3983 | if (!NILP (seconds)) | 3963 | if (!NILP (seconds)) |
| 3984 | { | 3964 | { |
| 3985 | double duration = extract_float (seconds); | 3965 | if (INTEGERP (seconds)) |
| 3986 | if (0 < duration) | 3966 | { |
| 3987 | duration_to_sec_usec (duration, &secs, &usecs); | 3967 | if (0 < XINT (seconds)) |
| 3968 | { | ||
| 3969 | secs = XINT (seconds); | ||
| 3970 | nsecs = 0; | ||
| 3971 | } | ||
| 3972 | } | ||
| 3973 | else if (FLOATP (seconds)) | ||
| 3974 | { | ||
| 3975 | if (0 < XFLOAT_DATA (seconds)) | ||
| 3976 | { | ||
| 3977 | EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); | ||
| 3978 | secs = min (EMACS_SECS (t), WAIT_READING_MAX); | ||
| 3979 | nsecs = EMACS_NSECS (t); | ||
| 3980 | } | ||
| 3981 | } | ||
| 3982 | else | ||
| 3983 | wrong_type_argument (Qnumberp, seconds); | ||
| 3988 | } | 3984 | } |
| 3989 | else if (!NILP (process)) | 3985 | else if (! NILP (process)) |
| 3990 | secs = 0; | 3986 | nsecs = 0; |
| 3991 | 3987 | ||
| 3992 | return | 3988 | return |
| 3993 | (wait_reading_process_output (secs, usecs, 0, 0, | 3989 | (wait_reading_process_output (secs, nsecs, 0, 0, |
| 3994 | Qnil, | 3990 | Qnil, |
| 3995 | !NILP (process) ? XPROCESS (process) : NULL, | 3991 | !NILP (process) ? XPROCESS (process) : NULL, |
| 3996 | NILP (just_this_one) ? 0 : | 3992 | NILP (just_this_one) ? 0 : |
| @@ -4231,36 +4227,21 @@ wait_reading_process_output_1 (void) | |||
| 4231 | { | 4227 | { |
| 4232 | } | 4228 | } |
| 4233 | 4229 | ||
| 4234 | /* Use a wrapper around select to work around a bug in gdb 5.3. | ||
| 4235 | Normally, the wrapper is optimized away by inlining. | ||
| 4236 | |||
| 4237 | If emacs is stopped inside select, the gdb backtrace doesn't | ||
| 4238 | show the function which called select, so it is practically | ||
| 4239 | impossible to step through wait_reading_process_output. */ | ||
| 4240 | |||
| 4241 | #ifndef select | ||
| 4242 | static inline int | ||
| 4243 | select_wrapper (int n, fd_set *rfd, fd_set *wfd, fd_set *xfd, struct timeval *tmo) | ||
| 4244 | { | ||
| 4245 | return select (n, rfd, wfd, xfd, tmo); | ||
| 4246 | } | ||
| 4247 | #define select select_wrapper | ||
| 4248 | #endif | ||
| 4249 | |||
| 4250 | /* Read and dispose of subprocess output while waiting for timeout to | 4230 | /* Read and dispose of subprocess output while waiting for timeout to |
| 4251 | elapse and/or keyboard input to be available. | 4231 | elapse and/or keyboard input to be available. |
| 4252 | 4232 | ||
| 4253 | TIME_LIMIT is: | 4233 | TIME_LIMIT is: |
| 4254 | timeout in seconds, or | 4234 | timeout in seconds |
| 4255 | zero for no limit, or | 4235 | If negative, gobble data immediately available but don't wait for any. |
| 4256 | -1 means gobble data immediately available but don't wait for any. | ||
| 4257 | 4236 | ||
| 4258 | MICROSECS is: | 4237 | NSECS is: |
| 4259 | an additional duration to wait, measured in microseconds. | 4238 | an additional duration to wait, measured in nanoseconds |
| 4260 | If this is nonzero and time_limit is 0, then the timeout | 4239 | If TIME_LIMIT is zero, then: |
| 4261 | consists of MICROSECS only. | 4240 | If NSECS == 0, there is no limit. |
| 4241 | If NSECS > 0, the timeout consists of NSECS only. | ||
| 4242 | If NSECS < 0, gobble data immediately, as if TIME_LIMIT were negative. | ||
| 4262 | 4243 | ||
| 4263 | READ_KBD is a lisp value: | 4244 | READ_KBD is: |
| 4264 | 0 to ignore keyboard input, or | 4245 | 0 to ignore keyboard input, or |
| 4265 | 1 to return when input is available, or | 4246 | 1 to return when input is available, or |
| 4266 | -1 meaning caller will actually read the input, so don't throw to | 4247 | -1 meaning caller will actually read the input, so don't throw to |
| @@ -4285,7 +4266,7 @@ select_wrapper (int n, fd_set *rfd, fd_set *wfd, fd_set *xfd, struct timeval *tm | |||
| 4285 | Otherwise, return true if we received input from any process. */ | 4266 | Otherwise, return true if we received input from any process. */ |
| 4286 | 4267 | ||
| 4287 | int | 4268 | int |
| 4288 | wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | 4269 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 4289 | int do_display, | 4270 | int do_display, |
| 4290 | Lisp_Object wait_for_cell, | 4271 | Lisp_Object wait_for_cell, |
| 4291 | struct Lisp_Process *wait_proc, int just_wait_proc) | 4272 | struct Lisp_Process *wait_proc, int just_wait_proc) |
| @@ -4305,7 +4286,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4305 | FD_ZERO (&Available); | 4286 | FD_ZERO (&Available); |
| 4306 | FD_ZERO (&Writeok); | 4287 | FD_ZERO (&Writeok); |
| 4307 | 4288 | ||
| 4308 | if (time_limit == 0 && microsecs == 0 && wait_proc && !NILP (Vinhibit_quit) | 4289 | if (time_limit == 0 && nsecs == 0 && wait_proc && !NILP (Vinhibit_quit) |
| 4309 | && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit))) | 4290 | && !(CONSP (wait_proc->status) && EQ (XCAR (wait_proc->status), Qexit))) |
| 4310 | message ("Blocking call to accept-process-output with quit inhibited!!"); | 4291 | message ("Blocking call to accept-process-output with quit inhibited!!"); |
| 4311 | 4292 | ||
| @@ -4317,13 +4298,20 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4317 | make_number (waiting_for_user_input_p)); | 4298 | make_number (waiting_for_user_input_p)); |
| 4318 | waiting_for_user_input_p = read_kbd; | 4299 | waiting_for_user_input_p = read_kbd; |
| 4319 | 4300 | ||
| 4301 | if (time_limit < 0) | ||
| 4302 | { | ||
| 4303 | time_limit = 0; | ||
| 4304 | nsecs = -1; | ||
| 4305 | } | ||
| 4306 | else if (TYPE_MAXIMUM (time_t) < time_limit) | ||
| 4307 | time_limit = TYPE_MAXIMUM (time_t); | ||
| 4308 | |||
| 4320 | /* Since we may need to wait several times, | 4309 | /* Since we may need to wait several times, |
| 4321 | compute the absolute time to return at. */ | 4310 | compute the absolute time to return at. */ |
| 4322 | if (time_limit || microsecs) | 4311 | if (time_limit || 0 < nsecs) |
| 4323 | { | 4312 | { |
| 4324 | EMACS_GET_TIME (end_time); | 4313 | timeout = make_emacs_time (time_limit, nsecs); |
| 4325 | EMACS_SET_SECS_USECS (timeout, time_limit, microsecs); | 4314 | end_time = add_emacs_time (current_emacs_time (), timeout); |
| 4326 | EMACS_ADD_TIME (end_time, end_time, timeout); | ||
| 4327 | } | 4315 | } |
| 4328 | 4316 | ||
| 4329 | while (1) | 4317 | while (1) |
| @@ -4346,24 +4334,24 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4346 | 4334 | ||
| 4347 | /* Compute time from now till when time limit is up */ | 4335 | /* Compute time from now till when time limit is up */ |
| 4348 | /* Exit if already run out */ | 4336 | /* Exit if already run out */ |
| 4349 | if (time_limit == -1) | 4337 | if (nsecs < 0) |
| 4350 | { | 4338 | { |
| 4351 | /* -1 specified for timeout means | 4339 | /* A negative timeout means |
| 4352 | gobble output available now | 4340 | gobble output available now |
| 4353 | but don't wait at all. */ | 4341 | but don't wait at all. */ |
| 4354 | 4342 | ||
| 4355 | EMACS_SET_SECS_USECS (timeout, 0, 0); | 4343 | timeout = make_emacs_time (0, 0); |
| 4356 | } | 4344 | } |
| 4357 | else if (time_limit || microsecs) | 4345 | else if (time_limit || 0 < nsecs) |
| 4358 | { | 4346 | { |
| 4359 | EMACS_GET_TIME (timeout); | 4347 | EMACS_TIME now = current_emacs_time (); |
| 4360 | EMACS_SUB_TIME (timeout, end_time, timeout); | 4348 | if (EMACS_TIME_LE (end_time, now)) |
| 4361 | if (EMACS_TIME_NEG_P (timeout)) | ||
| 4362 | break; | 4349 | break; |
| 4350 | timeout = sub_emacs_time (end_time, now); | ||
| 4363 | } | 4351 | } |
| 4364 | else | 4352 | else |
| 4365 | { | 4353 | { |
| 4366 | EMACS_SET_SECS_USECS (timeout, 100000, 0); | 4354 | timeout = make_emacs_time (100000, 0); |
| 4367 | } | 4355 | } |
| 4368 | 4356 | ||
| 4369 | /* Normally we run timers here. | 4357 | /* Normally we run timers here. |
| @@ -4405,21 +4393,22 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4405 | && requeued_events_pending_p ()) | 4393 | && requeued_events_pending_p ()) |
| 4406 | break; | 4394 | break; |
| 4407 | 4395 | ||
| 4408 | if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1) | 4396 | /* A negative timeout means do not wait at all. */ |
| 4397 | if (0 <= nsecs) | ||
| 4409 | { | 4398 | { |
| 4410 | EMACS_TIME difference; | 4399 | if (EMACS_TIME_VALID_P (timer_delay)) |
| 4411 | EMACS_SUB_TIME (difference, timer_delay, timeout); | ||
| 4412 | if (EMACS_TIME_NEG_P (difference)) | ||
| 4413 | { | 4400 | { |
| 4414 | timeout = timer_delay; | 4401 | if (EMACS_TIME_LT (timer_delay, timeout)) |
| 4415 | timeout_reduced_for_timers = 1; | 4402 | { |
| 4403 | timeout = timer_delay; | ||
| 4404 | timeout_reduced_for_timers = 1; | ||
| 4405 | } | ||
| 4406 | } | ||
| 4407 | else | ||
| 4408 | { | ||
| 4409 | /* This is so a breakpoint can be put here. */ | ||
| 4410 | wait_reading_process_output_1 (); | ||
| 4416 | } | 4411 | } |
| 4417 | } | ||
| 4418 | /* If time_limit is -1, we are not going to wait at all. */ | ||
| 4419 | else if (time_limit != -1) | ||
| 4420 | { | ||
| 4421 | /* This is so a breakpoint can be put here. */ | ||
| 4422 | wait_reading_process_output_1 (); | ||
| 4423 | } | 4412 | } |
| 4424 | } | 4413 | } |
| 4425 | 4414 | ||
| @@ -4447,15 +4436,15 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4447 | Atemp = input_wait_mask; | 4436 | Atemp = input_wait_mask; |
| 4448 | Ctemp = write_mask; | 4437 | Ctemp = write_mask; |
| 4449 | 4438 | ||
| 4450 | EMACS_SET_SECS_USECS (timeout, 0, 0); | 4439 | timeout = make_emacs_time (0, 0); |
| 4451 | if ((select (max (max_process_desc, max_input_desc) + 1, | 4440 | if ((pselect (max (max_process_desc, max_input_desc) + 1, |
| 4452 | &Atemp, | 4441 | &Atemp, |
| 4453 | #ifdef NON_BLOCKING_CONNECT | 4442 | #ifdef NON_BLOCKING_CONNECT |
| 4454 | (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), | 4443 | (num_pending_connects > 0 ? &Ctemp : NULL), |
| 4455 | #else | 4444 | #else |
| 4456 | (SELECT_TYPE *)0, | 4445 | NULL, |
| 4457 | #endif | 4446 | #endif |
| 4458 | (SELECT_TYPE *)0, &timeout) | 4447 | NULL, &timeout, NULL) |
| 4459 | <= 0)) | 4448 | <= 0)) |
| 4460 | { | 4449 | { |
| 4461 | /* It's okay for us to do this and then continue with | 4450 | /* It's okay for us to do this and then continue with |
| @@ -4578,9 +4567,9 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4578 | Vprocess_adaptive_read_buffering is nil. */ | 4567 | Vprocess_adaptive_read_buffering is nil. */ |
| 4579 | if (process_output_skip && check_delay > 0) | 4568 | if (process_output_skip && check_delay > 0) |
| 4580 | { | 4569 | { |
| 4581 | int usecs = EMACS_USECS (timeout); | 4570 | int nsecs = EMACS_NSECS (timeout); |
| 4582 | if (EMACS_SECS (timeout) > 0 || usecs > READ_OUTPUT_DELAY_MAX) | 4571 | if (EMACS_SECS (timeout) > 0 || nsecs > READ_OUTPUT_DELAY_MAX) |
| 4583 | usecs = READ_OUTPUT_DELAY_MAX; | 4572 | nsecs = READ_OUTPUT_DELAY_MAX; |
| 4584 | for (channel = 0; check_delay > 0 && channel <= max_process_desc; channel++) | 4573 | for (channel = 0; check_delay > 0 && channel <= max_process_desc; channel++) |
| 4585 | { | 4574 | { |
| 4586 | proc = chan_process[channel]; | 4575 | proc = chan_process[channel]; |
| @@ -4595,11 +4584,11 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4595 | continue; | 4584 | continue; |
| 4596 | FD_CLR (channel, &Available); | 4585 | FD_CLR (channel, &Available); |
| 4597 | XPROCESS (proc)->read_output_skip = 0; | 4586 | XPROCESS (proc)->read_output_skip = 0; |
| 4598 | if (XPROCESS (proc)->read_output_delay < usecs) | 4587 | if (XPROCESS (proc)->read_output_delay < nsecs) |
| 4599 | usecs = XPROCESS (proc)->read_output_delay; | 4588 | nsecs = XPROCESS (proc)->read_output_delay; |
| 4600 | } | 4589 | } |
| 4601 | } | 4590 | } |
| 4602 | EMACS_SET_SECS_USECS (timeout, 0, usecs); | 4591 | timeout = make_emacs_time (0, nsecs); |
| 4603 | process_output_skip = 0; | 4592 | process_output_skip = 0; |
| 4604 | } | 4593 | } |
| 4605 | #endif | 4594 | #endif |
| @@ -4608,12 +4597,12 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4608 | #elif defined (HAVE_NS) | 4597 | #elif defined (HAVE_NS) |
| 4609 | nfds = ns_select | 4598 | nfds = ns_select |
| 4610 | #else | 4599 | #else |
| 4611 | nfds = select | 4600 | nfds = pselect |
| 4612 | #endif | 4601 | #endif |
| 4613 | (max (max_process_desc, max_input_desc) + 1, | 4602 | (max (max_process_desc, max_input_desc) + 1, |
| 4614 | &Available, | 4603 | &Available, |
| 4615 | (check_write ? &Writeok : (SELECT_TYPE *)0), | 4604 | (check_write ? &Writeok : (SELECT_TYPE *)0), |
| 4616 | (SELECT_TYPE *)0, &timeout); | 4605 | NULL, &timeout, NULL); |
| 4617 | 4606 | ||
| 4618 | #ifdef HAVE_GNUTLS | 4607 | #ifdef HAVE_GNUTLS |
| 4619 | /* GnuTLS buffers data internally. In lowat mode it leaves | 4608 | /* GnuTLS buffers data internally. In lowat mode it leaves |
| @@ -4671,8 +4660,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4671 | /* If we woke up due to SIGWINCH, actually change size now. */ | 4660 | /* If we woke up due to SIGWINCH, actually change size now. */ |
| 4672 | do_pending_window_change (0); | 4661 | do_pending_window_change (0); |
| 4673 | 4662 | ||
| 4674 | if (time_limit && nfds == 0 && ! timeout_reduced_for_timers) | 4663 | if ((time_limit || nsecs) && nfds == 0 && ! timeout_reduced_for_timers) |
| 4675 | /* We wanted the full specified time, so return now. */ | 4664 | /* We waited the full specified time, so return now. */ |
| 4676 | break; | 4665 | break; |
| 4677 | if (nfds < 0) | 4666 | if (nfds < 0) |
| 4678 | { | 4667 | { |
| @@ -4823,7 +4812,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 4823 | if (wait_channel == channel) | 4812 | if (wait_channel == channel) |
| 4824 | { | 4813 | { |
| 4825 | wait_channel = -1; | 4814 | wait_channel = -1; |
| 4826 | time_limit = -1; | 4815 | nsecs = -1; |
| 4827 | got_some_input = 1; | 4816 | got_some_input = 1; |
| 4828 | } | 4817 | } |
| 4829 | proc = chan_process[channel]; | 4818 | proc = chan_process[channel]; |
| @@ -5048,7 +5037,7 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5048 | ptrdiff_t count = SPECPDL_INDEX (); | 5037 | ptrdiff_t count = SPECPDL_INDEX (); |
| 5049 | Lisp_Object odeactivate; | 5038 | Lisp_Object odeactivate; |
| 5050 | 5039 | ||
| 5051 | chars = (char *) alloca (carryover + readmax); | 5040 | chars = alloca (carryover + readmax); |
| 5052 | if (carryover) | 5041 | if (carryover) |
| 5053 | /* See the comment above. */ | 5042 | /* See the comment above. */ |
| 5054 | memcpy (chars, SDATA (p->decoding_buf), carryover); | 5043 | memcpy (chars, SDATA (p->decoding_buf), carryover); |
| @@ -5361,7 +5350,7 @@ static jmp_buf send_process_frame; | |||
| 5361 | static Lisp_Object process_sent_to; | 5350 | static Lisp_Object process_sent_to; |
| 5362 | 5351 | ||
| 5363 | #ifndef FORWARD_SIGNAL_TO_MAIN_THREAD | 5352 | #ifndef FORWARD_SIGNAL_TO_MAIN_THREAD |
| 5364 | static void send_process_trap (int) NO_RETURN; | 5353 | static _Noreturn void send_process_trap (int); |
| 5365 | #endif | 5354 | #endif |
| 5366 | 5355 | ||
| 5367 | static void | 5356 | static void |
| @@ -5680,11 +5669,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5680 | 5669 | ||
| 5681 | /* Put what we should have written in wait_queue. */ | 5670 | /* Put what we should have written in wait_queue. */ |
| 5682 | write_queue_push (p, cur_object, cur_buf, cur_len, 1); | 5671 | write_queue_push (p, cur_object, cur_buf, cur_len, 1); |
| 5683 | #ifdef EMACS_HAS_USECS | 5672 | wait_reading_process_output (0, 20 * 1000 * 1000, |
| 5684 | wait_reading_process_output (0, 20000, 0, 0, Qnil, NULL, 0); | 5673 | 0, 0, Qnil, NULL, 0); |
| 5685 | #else | ||
| 5686 | wait_reading_process_output (1, 0, 0, 0, Qnil, NULL, 0); | ||
| 5687 | #endif | ||
| 5688 | /* Reread queue, to see what is left. */ | 5674 | /* Reread queue, to see what is left. */ |
| 5689 | break; | 5675 | break; |
| 5690 | } | 5676 | } |
| @@ -6300,7 +6286,7 @@ process has been transmitted to the serial port. */) | |||
| 6300 | 6286 | ||
| 6301 | if (!proc_encode_coding_system[new_outfd]) | 6287 | if (!proc_encode_coding_system[new_outfd]) |
| 6302 | proc_encode_coding_system[new_outfd] | 6288 | proc_encode_coding_system[new_outfd] |
| 6303 | = (struct coding_system *) xmalloc (sizeof (struct coding_system)); | 6289 | = xmalloc (sizeof (struct coding_system)); |
| 6304 | memcpy (proc_encode_coding_system[new_outfd], | 6290 | memcpy (proc_encode_coding_system[new_outfd], |
| 6305 | proc_encode_coding_system[old_outfd], | 6291 | proc_encode_coding_system[old_outfd], |
| 6306 | sizeof (struct coding_system)); | 6292 | sizeof (struct coding_system)); |
| @@ -6438,7 +6424,7 @@ sigchld_handler (int signo) | |||
| 6438 | /* Tell wait_reading_process_output that it needs to wake up and | 6424 | /* Tell wait_reading_process_output that it needs to wake up and |
| 6439 | look around. */ | 6425 | look around. */ |
| 6440 | if (input_available_clear_time) | 6426 | if (input_available_clear_time) |
| 6441 | EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | 6427 | *input_available_clear_time = make_emacs_time (0, 0); |
| 6442 | } | 6428 | } |
| 6443 | 6429 | ||
| 6444 | /* There was no asynchronous process found for that pid: we have | 6430 | /* There was no asynchronous process found for that pid: we have |
| @@ -6456,7 +6442,7 @@ sigchld_handler (int signo) | |||
| 6456 | /* Tell wait_reading_process_output that it needs to wake up and | 6442 | /* Tell wait_reading_process_output that it needs to wake up and |
| 6457 | look around. */ | 6443 | look around. */ |
| 6458 | if (input_available_clear_time) | 6444 | if (input_available_clear_time) |
| 6459 | EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | 6445 | *input_available_clear_time = make_emacs_time (0, 0); |
| 6460 | } | 6446 | } |
| 6461 | 6447 | ||
| 6462 | sigchld_end_of_loop: | 6448 | sigchld_end_of_loop: |
| @@ -6817,19 +6803,25 @@ keyboard_bit_set (fd_set *mask) | |||
| 6817 | 6803 | ||
| 6818 | /* Defined on msdos.c. */ | 6804 | /* Defined on msdos.c. */ |
| 6819 | extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | 6805 | extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, |
| 6820 | EMACS_TIME *); | 6806 | EMACS_TIME *, void *); |
| 6821 | 6807 | ||
| 6822 | /* Implementation of wait_reading_process_output, assuming that there | 6808 | /* Implementation of wait_reading_process_output, assuming that there |
| 6823 | are no subprocesses. Used only by the MS-DOS build. | 6809 | are no subprocesses. Used only by the MS-DOS build. |
| 6824 | 6810 | ||
| 6825 | Wait for timeout to elapse and/or keyboard input to be available. | 6811 | Wait for timeout to elapse and/or keyboard input to be available. |
| 6826 | 6812 | ||
| 6827 | time_limit is: | 6813 | TIME_LIMIT is: |
| 6828 | timeout in seconds, or | 6814 | timeout in seconds |
| 6829 | zero for no limit, or | 6815 | If negative, gobble data immediately available but don't wait for any. |
| 6830 | -1 means gobble data immediately available but don't wait for any. | 6816 | |
| 6817 | NSECS is: | ||
| 6818 | an additional duration to wait, measured in nanoseconds | ||
| 6819 | If TIME_LIMIT is zero, then: | ||
| 6820 | If NSECS == 0, there is no limit. | ||
| 6821 | If NSECS > 0, the timeout consists of NSECS only. | ||
| 6822 | If NSECS < 0, gobble data immediately, as if TIME_LIMIT were negative. | ||
| 6831 | 6823 | ||
| 6832 | read_kbd is a Lisp_Object: | 6824 | READ_KBD is: |
| 6833 | 0 to ignore keyboard input, or | 6825 | 0 to ignore keyboard input, or |
| 6834 | 1 to return when input is available, or | 6826 | 1 to return when input is available, or |
| 6835 | -1 means caller will actually read the input, so don't throw to | 6827 | -1 means caller will actually read the input, so don't throw to |
| @@ -6838,28 +6830,33 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | |||
| 6838 | see full version for other parameters. We know that wait_proc will | 6830 | see full version for other parameters. We know that wait_proc will |
| 6839 | always be NULL, since `subprocesses' isn't defined. | 6831 | always be NULL, since `subprocesses' isn't defined. |
| 6840 | 6832 | ||
| 6841 | do_display != 0 means redisplay should be done to show subprocess | 6833 | DO_DISPLAY != 0 means redisplay should be done to show subprocess |
| 6842 | output that arrives. | 6834 | output that arrives. |
| 6843 | 6835 | ||
| 6844 | Return true if we received input from any process. */ | 6836 | Return true if we received input from any process. */ |
| 6845 | 6837 | ||
| 6846 | int | 6838 | int |
| 6847 | wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | 6839 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 6848 | int do_display, | 6840 | int do_display, |
| 6849 | Lisp_Object wait_for_cell, | 6841 | Lisp_Object wait_for_cell, |
| 6850 | struct Lisp_Process *wait_proc, int just_wait_proc) | 6842 | struct Lisp_Process *wait_proc, int just_wait_proc) |
| 6851 | { | 6843 | { |
| 6852 | register int nfds; | 6844 | register int nfds; |
| 6853 | EMACS_TIME end_time, timeout; | 6845 | EMACS_TIME end_time, timeout; |
| 6854 | SELECT_TYPE waitchannels; | 6846 | |
| 6855 | int xerrno; | 6847 | if (time_limit < 0) |
| 6848 | { | ||
| 6849 | time_limit = 0; | ||
| 6850 | nsecs = -1; | ||
| 6851 | } | ||
| 6852 | else if (TYPE_MAXIMUM (time_t) < time_limit) | ||
| 6853 | time_limit = TYPE_MAXIMUM (time_t); | ||
| 6856 | 6854 | ||
| 6857 | /* What does time_limit really mean? */ | 6855 | /* What does time_limit really mean? */ |
| 6858 | if (time_limit || microsecs) | 6856 | if (time_limit || 0 < nsecs) |
| 6859 | { | 6857 | { |
| 6860 | EMACS_GET_TIME (end_time); | 6858 | timeout = make_emacs_time (time_limit, nsecs); |
| 6861 | EMACS_SET_SECS_USECS (timeout, time_limit, microsecs); | 6859 | end_time = add_emacs_time (current_emacs_time (), timeout); |
| 6862 | EMACS_ADD_TIME (end_time, end_time, timeout); | ||
| 6863 | } | 6860 | } |
| 6864 | 6861 | ||
| 6865 | /* Turn off periodic alarms (in case they are in use) | 6862 | /* Turn off periodic alarms (in case they are in use) |
| @@ -6871,6 +6868,8 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 6871 | while (1) | 6868 | while (1) |
| 6872 | { | 6869 | { |
| 6873 | int timeout_reduced_for_timers = 0; | 6870 | int timeout_reduced_for_timers = 0; |
| 6871 | SELECT_TYPE waitchannels; | ||
| 6872 | int xerrno; | ||
| 6874 | 6873 | ||
| 6875 | /* If calling from keyboard input, do not quit | 6874 | /* If calling from keyboard input, do not quit |
| 6876 | since we want to return C-g as an input character. | 6875 | since we want to return C-g as an input character. |
| @@ -6884,24 +6883,24 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 6884 | 6883 | ||
| 6885 | /* Compute time from now till when time limit is up */ | 6884 | /* Compute time from now till when time limit is up */ |
| 6886 | /* Exit if already run out */ | 6885 | /* Exit if already run out */ |
| 6887 | if (time_limit == -1) | 6886 | if (nsecs < 0) |
| 6888 | { | 6887 | { |
| 6889 | /* -1 specified for timeout means | 6888 | /* A negative timeout means |
| 6890 | gobble output available now | 6889 | gobble output available now |
| 6891 | but don't wait at all. */ | 6890 | but don't wait at all. */ |
| 6892 | 6891 | ||
| 6893 | EMACS_SET_SECS_USECS (timeout, 0, 0); | 6892 | timeout = make_emacs_time (0, 0); |
| 6894 | } | 6893 | } |
| 6895 | else if (time_limit || microsecs) | 6894 | else if (time_limit || 0 < nsecs) |
| 6896 | { | 6895 | { |
| 6897 | EMACS_GET_TIME (timeout); | 6896 | EMACS_TIME now = current_emacs_time (); |
| 6898 | EMACS_SUB_TIME (timeout, end_time, timeout); | 6897 | if (EMACS_TIME_LE (end_time, now)) |
| 6899 | if (EMACS_TIME_NEG_P (timeout)) | ||
| 6900 | break; | 6898 | break; |
| 6899 | timeout = sub_emacs_time (end_time, now); | ||
| 6901 | } | 6900 | } |
| 6902 | else | 6901 | else |
| 6903 | { | 6902 | { |
| 6904 | EMACS_SET_SECS_USECS (timeout, 100000, 0); | 6903 | timeout = make_emacs_time (100000, 0); |
| 6905 | } | 6904 | } |
| 6906 | 6905 | ||
| 6907 | /* If our caller will not immediately handle keyboard events, | 6906 | /* If our caller will not immediately handle keyboard events, |
| @@ -6930,11 +6929,9 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 6930 | && requeued_events_pending_p ()) | 6929 | && requeued_events_pending_p ()) |
| 6931 | break; | 6930 | break; |
| 6932 | 6931 | ||
| 6933 | if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1) | 6932 | if (EMACS_TIME_VALID_P (timer_delay) && 0 <= nsecs) |
| 6934 | { | 6933 | { |
| 6935 | EMACS_TIME difference; | 6934 | if (EMACS_TIME_LT (timer_delay, timeout)) |
| 6936 | EMACS_SUB_TIME (difference, timer_delay, timeout); | ||
| 6937 | if (EMACS_TIME_NEG_P (difference)) | ||
| 6938 | { | 6935 | { |
| 6939 | timeout = timer_delay; | 6936 | timeout = timer_delay; |
| 6940 | timeout_reduced_for_timers = 1; | 6937 | timeout_reduced_for_timers = 1; |
| @@ -6947,13 +6944,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 6947 | if (read_kbd < 0) | 6944 | if (read_kbd < 0) |
| 6948 | set_waiting_for_input (&timeout); | 6945 | set_waiting_for_input (&timeout); |
| 6949 | 6946 | ||
| 6950 | /* Wait till there is something to do. */ | ||
| 6951 | |||
| 6952 | if (! read_kbd && NILP (wait_for_cell)) | ||
| 6953 | FD_ZERO (&waitchannels); | ||
| 6954 | else | ||
| 6955 | FD_SET (0, &waitchannels); | ||
| 6956 | |||
| 6957 | /* If a frame has been newly mapped and needs updating, | 6947 | /* If a frame has been newly mapped and needs updating, |
| 6958 | reprocess its display stuff. */ | 6948 | reprocess its display stuff. */ |
| 6959 | if (frame_garbaged && do_display) | 6949 | if (frame_garbaged && do_display) |
| @@ -6964,14 +6954,16 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 6964 | set_waiting_for_input (&timeout); | 6954 | set_waiting_for_input (&timeout); |
| 6965 | } | 6955 | } |
| 6966 | 6956 | ||
| 6957 | /* Wait till there is something to do. */ | ||
| 6958 | FD_ZERO (&waitchannels); | ||
| 6967 | if (read_kbd && detect_input_pending ()) | 6959 | if (read_kbd && detect_input_pending ()) |
| 6960 | nfds = 0; | ||
| 6961 | else | ||
| 6968 | { | 6962 | { |
| 6969 | nfds = 0; | 6963 | if (read_kbd || !NILP (wait_for_cell)) |
| 6970 | FD_ZERO (&waitchannels); | 6964 | FD_SET (0, &waitchannels); |
| 6965 | nfds = pselect (1, &waitchannels, NULL, NULL, &timeout, NULL); | ||
| 6971 | } | 6966 | } |
| 6972 | else | ||
| 6973 | nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, | ||
| 6974 | &timeout); | ||
| 6975 | 6967 | ||
| 6976 | xerrno = errno; | 6968 | xerrno = errno; |
| 6977 | 6969 | ||
| @@ -6981,7 +6973,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd, | |||
| 6981 | /* If we woke up due to SIGWINCH, actually change size now. */ | 6973 | /* If we woke up due to SIGWINCH, actually change size now. */ |
| 6982 | do_pending_window_change (0); | 6974 | do_pending_window_change (0); |
| 6983 | 6975 | ||
| 6984 | if (time_limit && nfds == 0 && ! timeout_reduced_for_timers) | 6976 | if ((time_limit || nsecs) && nfds == 0 && ! timeout_reduced_for_timers) |
| 6985 | /* We waited the full specified time, so return now. */ | 6977 | /* We waited the full specified time, so return now. */ |
| 6986 | break; | 6978 | break; |
| 6987 | 6979 | ||
| @@ -7086,8 +7078,7 @@ setup_process_coding_systems (Lisp_Object process) | |||
| 7086 | return; | 7078 | return; |
| 7087 | 7079 | ||
| 7088 | if (!proc_decode_coding_system[inch]) | 7080 | if (!proc_decode_coding_system[inch]) |
| 7089 | proc_decode_coding_system[inch] | 7081 | proc_decode_coding_system[inch] = xmalloc (sizeof (struct coding_system)); |
| 7090 | = (struct coding_system *) xmalloc (sizeof (struct coding_system)); | ||
| 7091 | coding_system = p->decode_coding_system; | 7082 | coding_system = p->decode_coding_system; |
| 7092 | if (! NILP (p->filter)) | 7083 | if (! NILP (p->filter)) |
| 7093 | ; | 7084 | ; |
| @@ -7099,8 +7090,7 @@ setup_process_coding_systems (Lisp_Object process) | |||
| 7099 | setup_coding_system (coding_system, proc_decode_coding_system[inch]); | 7090 | setup_coding_system (coding_system, proc_decode_coding_system[inch]); |
| 7100 | 7091 | ||
| 7101 | if (!proc_encode_coding_system[outch]) | 7092 | if (!proc_encode_coding_system[outch]) |
| 7102 | proc_encode_coding_system[outch] | 7093 | proc_encode_coding_system[outch] = xmalloc (sizeof (struct coding_system)); |
| 7103 | = (struct coding_system *) xmalloc (sizeof (struct coding_system)); | ||
| 7104 | setup_coding_system (p->encode_coding_system, | 7094 | setup_coding_system (p->encode_coding_system, |
| 7105 | proc_encode_coding_system[outch]); | 7095 | proc_encode_coding_system[outch]); |
| 7106 | #endif | 7096 | #endif |
| @@ -7284,19 +7274,20 @@ integer or floating point values. | |||
| 7284 | majflt -- number of major page faults (number) | 7274 | majflt -- number of major page faults (number) |
| 7285 | cminflt -- cumulative number of minor page faults (number) | 7275 | cminflt -- cumulative number of minor page faults (number) |
| 7286 | cmajflt -- cumulative number of major page faults (number) | 7276 | cmajflt -- cumulative number of major page faults (number) |
| 7287 | utime -- user time used by the process, in the (HIGH LOW USEC) format | 7277 | utime -- user time used by the process, in (current-time) format, |
| 7288 | stime -- system time used by the process, in the (HIGH LOW USEC) format | 7278 | which is a list of integers (HIGH LOW USEC PSEC) |
| 7289 | time -- sum of utime and stime, in the (HIGH LOW USEC) format | 7279 | stime -- system time used by the process (current-time) |
| 7290 | cutime -- user time used by the process and its children, (HIGH LOW USEC) | 7280 | time -- sum of utime and stime (current-time) |
| 7291 | cstime -- system time used by the process and its children, (HIGH LOW USEC) | 7281 | cutime -- user time used by the process and its children (current-time) |
| 7292 | ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format | 7282 | cstime -- system time used by the process and its children (current-time) |
| 7283 | ctime -- sum of cutime and cstime (current-time) | ||
| 7293 | pri -- priority of the process (number) | 7284 | pri -- priority of the process (number) |
| 7294 | nice -- nice value of the process (number) | 7285 | nice -- nice value of the process (number) |
| 7295 | thcount -- process thread count (number) | 7286 | thcount -- process thread count (number) |
| 7296 | start -- time the process started, in the (HIGH LOW USEC) format | 7287 | start -- time the process started (current-time) |
| 7297 | vsize -- virtual memory size of the process in KB's (number) | 7288 | vsize -- virtual memory size of the process in KB's (number) |
| 7298 | rss -- resident set size of the process in KB's (number) | 7289 | rss -- resident set size of the process in KB's (number) |
| 7299 | etime -- elapsed time the process is running, in (HIGH LOW USEC) format | 7290 | etime -- elapsed time the process is running, in (HIGH LOW USEC PSEC) format |
| 7300 | pcpu -- percents of CPU time used by the process (floating-point number) | 7291 | pcpu -- percents of CPU time used by the process (floating-point number) |
| 7301 | pmem -- percents of total physical memory used by process's resident set | 7292 | pmem -- percents of total physical memory used by process's resident set |
| 7302 | (floating-point number) | 7293 | (floating-point number) |
| @@ -7307,8 +7298,10 @@ integer or floating point values. | |||
| 7307 | } | 7298 | } |
| 7308 | 7299 | ||
| 7309 | 7300 | ||
| 7301 | /* This is not called "init_process" because that is the name of a | ||
| 7302 | Mach system call, so it would cause problems on Darwin systems. */ | ||
| 7310 | void | 7303 | void |
| 7311 | init_process (void) | 7304 | init_process_emacs (void) |
| 7312 | { | 7305 | { |
| 7313 | #ifdef subprocesses | 7306 | #ifdef subprocesses |
| 7314 | register int i; | 7307 | register int i; |
| @@ -7405,8 +7398,7 @@ init_process (void) | |||
| 7405 | char const *release = (STRINGP (Voperating_system_release) | 7398 | char const *release = (STRINGP (Voperating_system_release) |
| 7406 | ? SSDATA (Voperating_system_release) | 7399 | ? SSDATA (Voperating_system_release) |
| 7407 | : 0); | 7400 | : 0); |
| 7408 | if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION | 7401 | if (!release || !release[0] || (release[0] < '7' && release[1] == '.')) { |
| 7409 | && release[1] == '.')) { | ||
| 7410 | Vprocess_connection_type = Qnil; | 7402 | Vprocess_connection_type = Qnil; |
| 7411 | } | 7403 | } |
| 7412 | } | 7404 | } |