diff options
| author | Richard M. Stallman | 1994-06-25 22:35:28 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-06-25 22:35:28 +0000 |
| commit | 4556b700ea7c816ed120170a5f1cdf3bfdbe5689 (patch) | |
| tree | 9c7e53db43d09782afaf795b7ae7af2e0b0515d4 /src/process.c | |
| parent | 274a9425361237d6623f2f27d6267eef45a2adfc (diff) | |
| download | emacs-4556b700ea7c816ed120170a5f1cdf3bfdbe5689.tar.gz emacs-4556b700ea7c816ed120170a5f1cdf3bfdbe5689.zip | |
(send_process): Major rewrite.
Don't put in a C-d unless a single line is too long.
Read process input whenever output gets stuck.
Relocate BUF if we read input. New arg OBJECT.
Fprocess_send_region, Fprocess_send_string, process_send_signal)
(Fprocess_send_eof): Pass new arg OBJECT.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 178 |
1 files changed, 111 insertions, 67 deletions
diff --git a/src/process.c b/src/process.c index 66e21c1dc2e..9f740e4d026 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -2337,16 +2337,20 @@ send_process_trap () | |||
| 2337 | longjmp (send_process_frame, 1); | 2337 | longjmp (send_process_frame, 1); |
| 2338 | } | 2338 | } |
| 2339 | 2339 | ||
| 2340 | send_process (proc, buf, len) | 2340 | /* Send some data to process PROC. |
| 2341 | BUF is the beginning of the data; LEN is the number of characters. | ||
| 2342 | OBJECT is the Lisp object that the data comes from. */ | ||
| 2343 | |||
| 2344 | send_process (proc, buf, len, object) | ||
| 2341 | Lisp_Object proc; | 2345 | Lisp_Object proc; |
| 2342 | char *buf; | 2346 | char *buf; |
| 2343 | int len; | 2347 | int len; |
| 2348 | Lisp_Object object; | ||
| 2344 | { | 2349 | { |
| 2345 | /* Don't use register vars; longjmp can lose them. */ | 2350 | /* Don't use register vars; longjmp can lose them. */ |
| 2346 | int rv; | 2351 | int rv; |
| 2347 | unsigned char *procname = XSTRING (XPROCESS (proc)->name)->data; | 2352 | unsigned char *procname = XSTRING (XPROCESS (proc)->name)->data; |
| 2348 | 2353 | ||
| 2349 | |||
| 2350 | #ifdef VMS | 2354 | #ifdef VMS |
| 2351 | struct Lisp_Process *p = XPROCESS (proc); | 2355 | struct Lisp_Process *p = XPROCESS (proc); |
| 2352 | VMS_PROC_STUFF *vs, *get_vms_process_pointer(); | 2356 | VMS_PROC_STUFF *vs, *get_vms_process_pointer(); |
| @@ -2364,6 +2368,21 @@ send_process (proc, buf, len) | |||
| 2364 | else if (write_to_vms_process (vs, buf, len)) | 2368 | else if (write_to_vms_process (vs, buf, len)) |
| 2365 | ; | 2369 | ; |
| 2366 | #else | 2370 | #else |
| 2371 | |||
| 2372 | if (pty_max_bytes == 0) | ||
| 2373 | { | ||
| 2374 | #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) | ||
| 2375 | pty_max_bytes = fpathconf (XFASTINT (XPROCESS (proc)->outfd), | ||
| 2376 | _PC_MAX_CANON); | ||
| 2377 | if (pty_max_bytes < 0) | ||
| 2378 | pty_max_bytes = 250; | ||
| 2379 | #else | ||
| 2380 | pty_max_bytes = 250; | ||
| 2381 | #endif | ||
| 2382 | /* Deduct one, to leave space for the eof. */ | ||
| 2383 | pty_max_bytes--; | ||
| 2384 | } | ||
| 2385 | |||
| 2367 | if (!setjmp (send_process_frame)) | 2386 | if (!setjmp (send_process_frame)) |
| 2368 | while (len > 0) | 2387 | while (len > 0) |
| 2369 | { | 2388 | { |
| @@ -2371,65 +2390,89 @@ send_process (proc, buf, len) | |||
| 2371 | SIGTYPE (*old_sigpipe)(); | 2390 | SIGTYPE (*old_sigpipe)(); |
| 2372 | int flush_pty = 0; | 2391 | int flush_pty = 0; |
| 2373 | 2392 | ||
| 2374 | if (pty_max_bytes == 0) | 2393 | /* Decide how much data we can send in one batch. |
| 2394 | Long lines need to be split into multiple batches. */ | ||
| 2395 | if (!NILP (XPROCESS (proc)->pty_flag)) | ||
| 2375 | { | 2396 | { |
| 2376 | #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) | 2397 | /* Starting this at zero is always correct when not the first iteration |
| 2377 | pty_max_bytes = fpathconf (XFASTINT (XPROCESS (proc)->outfd), | 2398 | because the previous iteration ended by sending C-d. |
| 2378 | _PC_MAX_CANON); | 2399 | It may not be correct for the first iteration |
| 2379 | if (pty_max_bytes < 0) | 2400 | if a partial line was sent in a separate send_process call. |
| 2380 | pty_max_bytes = 250; | 2401 | If that proves worth handling, we need to save linepos |
| 2381 | #else | 2402 | in the process object. */ |
| 2382 | pty_max_bytes = 250; | 2403 | int linepos = 0; |
| 2383 | #endif | 2404 | char *ptr = buf; |
| 2405 | char *end = buf + len; | ||
| 2406 | |||
| 2407 | /* Scan through this text for a line that is too long. */ | ||
| 2408 | while (ptr != end && linepos < pty_max_bytes) | ||
| 2409 | { | ||
| 2410 | if (*ptr == '\n') | ||
| 2411 | linepos = 0; | ||
| 2412 | else | ||
| 2413 | linepos++; | ||
| 2414 | ptr++; | ||
| 2415 | } | ||
| 2416 | /* If we found one, break the line there | ||
| 2417 | and put in a C-d to force the buffer through. */ | ||
| 2418 | this = ptr - buf; | ||
| 2384 | } | 2419 | } |
| 2385 | 2420 | ||
| 2386 | /* Don't send more than pty_max_bytes bytes at a time. */ | 2421 | /* Send this batch, using one or more write calls. */ |
| 2387 | /* Subtract 1 to leave room for the EOF. */ | 2422 | while (this > 0) |
| 2388 | if (this >= pty_max_bytes && !NILP (XPROCESS (proc)->pty_flag)) | ||
| 2389 | this = pty_max_bytes - 1; | ||
| 2390 | |||
| 2391 | old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap); | ||
| 2392 | rv = write (XINT (XPROCESS (proc)->outfd), buf, this); | ||
| 2393 | |||
| 2394 | /* If we sent just part of the string, put in an EOF | ||
| 2395 | to force it through, before we send the rest. */ | ||
| 2396 | if (this < len) | ||
| 2397 | Fprocess_send_eof (proc); | ||
| 2398 | |||
| 2399 | signal (SIGPIPE, old_sigpipe); | ||
| 2400 | if (rv < 0) | ||
| 2401 | { | 2423 | { |
| 2402 | if (0 | 2424 | old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap); |
| 2425 | rv = write (XINT (XPROCESS (proc)->outfd), buf, this); | ||
| 2426 | signal (SIGPIPE, old_sigpipe); | ||
| 2427 | |||
| 2428 | if (rv < 0) | ||
| 2429 | { | ||
| 2430 | if (0 | ||
| 2403 | #ifdef EWOULDBLOCK | 2431 | #ifdef EWOULDBLOCK |
| 2404 | || errno == EWOULDBLOCK | 2432 | || errno == EWOULDBLOCK |
| 2405 | #endif | 2433 | #endif |
| 2406 | #ifdef EAGAIN | 2434 | #ifdef EAGAIN |
| 2407 | || errno == EAGAIN | 2435 | || errno == EAGAIN |
| 2408 | #endif | 2436 | #endif |
| 2409 | ) | 2437 | ) |
| 2410 | { | 2438 | /* Buffer is full. Wait, accepting input; |
| 2411 | /* It would be nice to accept process output here, | 2439 | that may allow the program |
| 2412 | but that is difficult. For example, it could | 2440 | to finish doing output and read more. */ |
| 2413 | garbage what we are sending if that is from a buffer. */ | 2441 | { |
| 2414 | immediate_quit = 1; | 2442 | Lisp_Object zero; |
| 2415 | QUIT; | 2443 | int offset; |
| 2416 | sleep (1); | 2444 | |
| 2417 | immediate_quit = 0; | 2445 | /* Running filters might relocate buffers or strings. |
| 2418 | continue; | 2446 | Arrange to relocate BUF. */ |
| 2447 | if (BUFFERP (object)) | ||
| 2448 | offset = BUF_PTR_CHAR_POS (XBUFFER (object), | ||
| 2449 | (unsigned char *) buf); | ||
| 2450 | else if (STRINGP (object)) | ||
| 2451 | offset = buf - (char *) XSTRING (object)->data; | ||
| 2452 | |||
| 2453 | XFASTINT (zero) = 0; | ||
| 2454 | wait_reading_process_input (1, 0, zero, 0); | ||
| 2455 | |||
| 2456 | if (BUFFERP (object)) | ||
| 2457 | buf = (char *) BUF_CHAR_ADDRESS (XBUFFER (object), offset); | ||
| 2458 | else if (STRINGP (object)) | ||
| 2459 | buf = offset + (char *) XSTRING (object)->data; | ||
| 2460 | |||
| 2461 | rv = 0; | ||
| 2462 | } | ||
| 2463 | else | ||
| 2464 | /* This is a real error. */ | ||
| 2465 | report_file_error ("writing to process", Fcons (proc, Qnil)); | ||
| 2419 | } | 2466 | } |
| 2420 | report_file_error ("writing to process", Fcons (proc, Qnil)); | 2467 | buf += rv; |
| 2468 | len -= rv; | ||
| 2469 | this -= rv; | ||
| 2421 | } | 2470 | } |
| 2422 | buf += rv; | ||
| 2423 | len -= rv; | ||
| 2424 | /* Allow input from processes between bursts of sending. | ||
| 2425 | Otherwise things may get stopped up. */ | ||
| 2426 | if (len > 0) | ||
| 2427 | { | ||
| 2428 | Lisp_Object zero; | ||
| 2429 | 2471 | ||
| 2430 | XFASTINT (zero) = 0; | 2472 | /* If we sent just part of the string, put in an EOF |
| 2431 | wait_reading_process_input (-1, 0, zero, 0); | 2473 | to force it through, before we send the rest. */ |
| 2432 | } | 2474 | if (len > 0) |
| 2475 | Fprocess_send_eof (proc); | ||
| 2433 | } | 2476 | } |
| 2434 | #endif | 2477 | #endif |
| 2435 | else | 2478 | else |
| @@ -2469,7 +2512,8 @@ Output from processes can arrive in between bunches.") | |||
| 2469 | move_gap (start); | 2512 | move_gap (start); |
| 2470 | 2513 | ||
| 2471 | start1 = XINT (start); | 2514 | start1 = XINT (start); |
| 2472 | send_process (proc, &FETCH_CHAR (start1), XINT (end) - XINT (start)); | 2515 | send_process (proc, &FETCH_CHAR (start1), XINT (end) - XINT (start), |
| 2516 | Fcurrent_buffer ()); | ||
| 2473 | 2517 | ||
| 2474 | return Qnil; | 2518 | return Qnil; |
| 2475 | } | 2519 | } |
| @@ -2488,7 +2532,7 @@ Output from processes can arrive in between bunches.") | |||
| 2488 | Lisp_Object proc; | 2532 | Lisp_Object proc; |
| 2489 | CHECK_STRING (string, 1); | 2533 | CHECK_STRING (string, 1); |
| 2490 | proc = get_process (process); | 2534 | proc = get_process (process); |
| 2491 | send_process (proc, XSTRING (string)->data, XSTRING (string)->size); | 2535 | send_process (proc, XSTRING (string)->data, XSTRING (string)->size, string); |
| 2492 | return Qnil; | 2536 | return Qnil; |
| 2493 | } | 2537 | } |
| 2494 | 2538 | ||
| @@ -2544,20 +2588,20 @@ process_send_signal (process, signo, current_group, nomsg) | |||
| 2544 | { | 2588 | { |
| 2545 | case SIGINT: | 2589 | case SIGINT: |
| 2546 | tcgetattr (XINT (p->infd), &t); | 2590 | tcgetattr (XINT (p->infd), &t); |
| 2547 | send_process (proc, &t.c_cc[VINTR], 1); | 2591 | send_process (proc, &t.c_cc[VINTR], 1, Qnil); |
| 2548 | return; | 2592 | return; |
| 2549 | 2593 | ||
| 2550 | case SIGQUIT: | 2594 | case SIGQUIT: |
| 2551 | tcgetattr (XINT (p->infd), &t); | 2595 | tcgetattr (XINT (p->infd), &t); |
| 2552 | send_process (proc, &t.c_cc[VQUIT], 1); | 2596 | send_process (proc, &t.c_cc[VQUIT], 1, Qnil); |
| 2553 | return; | 2597 | return; |
| 2554 | 2598 | ||
| 2555 | case SIGTSTP: | 2599 | case SIGTSTP: |
| 2556 | tcgetattr (XINT (p->infd), &t); | 2600 | tcgetattr (XINT (p->infd), &t); |
| 2557 | #if defined (VSWTCH) && !defined (PREFER_VSUSP) | 2601 | #if defined (VSWTCH) && !defined (PREFER_VSUSP) |
| 2558 | send_process (proc, &t.c_cc[VSWTCH], 1); | 2602 | send_process (proc, &t.c_cc[VSWTCH], 1, Qnil); |
| 2559 | #else | 2603 | #else |
| 2560 | send_process (proc, &t.c_cc[VSUSP], 1); | 2604 | send_process (proc, &t.c_cc[VSUSP], 1, Qnil); |
| 2561 | #endif | 2605 | #endif |
| 2562 | return; | 2606 | return; |
| 2563 | } | 2607 | } |
| @@ -2575,16 +2619,16 @@ process_send_signal (process, signo, current_group, nomsg) | |||
| 2575 | { | 2619 | { |
| 2576 | case SIGINT: | 2620 | case SIGINT: |
| 2577 | ioctl (XINT (p->infd), TIOCGETC, &c); | 2621 | ioctl (XINT (p->infd), TIOCGETC, &c); |
| 2578 | send_process (proc, &c.t_intrc, 1); | 2622 | send_process (proc, &c.t_intrc, 1, Qnil); |
| 2579 | return; | 2623 | return; |
| 2580 | case SIGQUIT: | 2624 | case SIGQUIT: |
| 2581 | ioctl (XINT (p->infd), TIOCGETC, &c); | 2625 | ioctl (XINT (p->infd), TIOCGETC, &c); |
| 2582 | send_process (proc, &c.t_quitc, 1); | 2626 | send_process (proc, &c.t_quitc, 1, Qnil); |
| 2583 | return; | 2627 | return; |
| 2584 | #ifdef SIGTSTP | 2628 | #ifdef SIGTSTP |
| 2585 | case SIGTSTP: | 2629 | case SIGTSTP: |
| 2586 | ioctl (XINT (p->infd), TIOCGLTC, &lc); | 2630 | ioctl (XINT (p->infd), TIOCGLTC, &lc); |
| 2587 | send_process (proc, &lc.t_suspc, 1); | 2631 | send_process (proc, &lc.t_suspc, 1, Qnil); |
| 2588 | return; | 2632 | return; |
| 2589 | #endif /* ! defined (SIGTSTP) */ | 2633 | #endif /* ! defined (SIGTSTP) */ |
| 2590 | } | 2634 | } |
| @@ -2599,16 +2643,16 @@ process_send_signal (process, signo, current_group, nomsg) | |||
| 2599 | { | 2643 | { |
| 2600 | case SIGINT: | 2644 | case SIGINT: |
| 2601 | ioctl (XINT (p->infd), TCGETA, &t); | 2645 | ioctl (XINT (p->infd), TCGETA, &t); |
| 2602 | send_process (proc, &t.c_cc[VINTR], 1); | 2646 | send_process (proc, &t.c_cc[VINTR], 1, Qnil); |
| 2603 | return; | 2647 | return; |
| 2604 | case SIGQUIT: | 2648 | case SIGQUIT: |
| 2605 | ioctl (XINT (p->infd), TCGETA, &t); | 2649 | ioctl (XINT (p->infd), TCGETA, &t); |
| 2606 | send_process (proc, &t.c_cc[VQUIT], 1); | 2650 | send_process (proc, &t.c_cc[VQUIT], 1, Qnil); |
| 2607 | return; | 2651 | return; |
| 2608 | #ifdef SIGTSTP | 2652 | #ifdef SIGTSTP |
| 2609 | case SIGTSTP: | 2653 | case SIGTSTP: |
| 2610 | ioctl (XINT (p->infd), TCGETA, &t); | 2654 | ioctl (XINT (p->infd), TCGETA, &t); |
| 2611 | send_process (proc, &t.c_cc[VSWTCH], 1); | 2655 | send_process (proc, &t.c_cc[VSWTCH], 1, Qnil); |
| 2612 | return; | 2656 | return; |
| 2613 | #endif /* ! defined (SIGTSTP) */ | 2657 | #endif /* ! defined (SIGTSTP) */ |
| 2614 | } | 2658 | } |
| @@ -2669,12 +2713,12 @@ process_send_signal (process, signo, current_group, nomsg) | |||
| 2669 | #endif /* ! defined (SIGCONT) */ | 2713 | #endif /* ! defined (SIGCONT) */ |
| 2670 | case SIGINT: | 2714 | case SIGINT: |
| 2671 | #ifdef VMS | 2715 | #ifdef VMS |
| 2672 | send_process (proc, "\003", 1); /* ^C */ | 2716 | send_process (proc, "\003", 1, Qnil); /* ^C */ |
| 2673 | goto whoosh; | 2717 | goto whoosh; |
| 2674 | #endif | 2718 | #endif |
| 2675 | case SIGQUIT: | 2719 | case SIGQUIT: |
| 2676 | #ifdef VMS | 2720 | #ifdef VMS |
| 2677 | send_process (proc, "\031", 1); /* ^Y */ | 2721 | send_process (proc, "\031", 1, Qnil); /* ^Y */ |
| 2678 | goto whoosh; | 2722 | goto whoosh; |
| 2679 | #endif | 2723 | #endif |
| 2680 | case SIGKILL: | 2724 | case SIGKILL: |
| @@ -2815,10 +2859,10 @@ text to PROCESS after you call this function.") | |||
| 2815 | } | 2859 | } |
| 2816 | #else /* did not do TOICREMOTE */ | 2860 | #else /* did not do TOICREMOTE */ |
| 2817 | #ifdef VMS | 2861 | #ifdef VMS |
| 2818 | send_process (proc, "\032", 1); /* ^z */ | 2862 | send_process (proc, "\032", 1, Qnil); /* ^z */ |
| 2819 | #else | 2863 | #else |
| 2820 | if (!NILP (XPROCESS (proc)->pty_flag)) | 2864 | if (!NILP (XPROCESS (proc)->pty_flag)) |
| 2821 | send_process (proc, "\004", 1); | 2865 | send_process (proc, "\004", 1, Qnil); |
| 2822 | else | 2866 | else |
| 2823 | { | 2867 | { |
| 2824 | close (XINT (XPROCESS (proc)->outfd)); | 2868 | close (XINT (XPROCESS (proc)->outfd)); |