diff options
| author | Alain Schneble | 2016-02-15 15:44:29 +1100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2016-02-15 15:44:29 +1100 |
| commit | c740d190e857bf63d04ec0d00eeeed23bbd66ace (patch) | |
| tree | ac96c16b24b85896fce56a14d683285beb56edfe /src/process.c | |
| parent | 51d728c8345416ab50a378a789dde645a7247499 (diff) | |
| download | emacs-c740d190e857bf63d04ec0d00eeeed23bbd66ace.tar.gz emacs-c740d190e857bf63d04ec0d00eeeed23bbd66ace.zip | |
Add blockers to process functions
* src/process.c (set-process-filter, set-process-window-size,
process-contact, process-datagram-address, set-process-datagram-address,
set-network-process-option): Make functions wait (block) on network
process until pending DNS requests have been processed and associated
socket initialized.
* src/process.c (process-send-region, process-send-string,
process-send-eof): Make functions wait (block) while network process is
in connect state.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 91 |
1 files changed, 84 insertions, 7 deletions
diff --git a/src/process.c b/src/process.c index 497b0696e00..5acf31550ef 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -284,6 +284,7 @@ static Lisp_Object chan_process[FD_SETSIZE]; | |||
| 284 | #ifdef HAVE_GETADDRINFO_A | 284 | #ifdef HAVE_GETADDRINFO_A |
| 285 | /* Pending DNS requests. */ | 285 | /* Pending DNS requests. */ |
| 286 | static Lisp_Object dns_processes; | 286 | static Lisp_Object dns_processes; |
| 287 | static void wait_for_socket_fds (Lisp_Object process); | ||
| 287 | #endif | 288 | #endif |
| 288 | 289 | ||
| 289 | /* Alist of elements (NAME . PROCESS). */ | 290 | /* Alist of elements (NAME . PROCESS). */ |
| @@ -1029,6 +1030,12 @@ The string argument is normally a multibyte string, except: | |||
| 1029 | struct Lisp_Process *p; | 1030 | struct Lisp_Process *p; |
| 1030 | 1031 | ||
| 1031 | CHECK_PROCESS (process); | 1032 | CHECK_PROCESS (process); |
| 1033 | |||
| 1034 | #ifdef HAVE_GETADDRINFO_A | ||
| 1035 | if (NETCONN_P (process)) | ||
| 1036 | wait_for_socket_fds (process); | ||
| 1037 | #endif | ||
| 1038 | |||
| 1032 | p = XPROCESS (process); | 1039 | p = XPROCESS (process); |
| 1033 | 1040 | ||
| 1034 | /* Don't signal an error if the process's input file descriptor | 1041 | /* Don't signal an error if the process's input file descriptor |
| @@ -1113,6 +1120,11 @@ DEFUN ("set-process-window-size", Fset_process_window_size, | |||
| 1113 | { | 1120 | { |
| 1114 | CHECK_PROCESS (process); | 1121 | CHECK_PROCESS (process); |
| 1115 | 1122 | ||
| 1123 | #ifdef HAVE_GETADDRINFO_A | ||
| 1124 | if (NETCONN_P (process)) | ||
| 1125 | wait_for_socket_fds (process); | ||
| 1126 | #endif | ||
| 1127 | |||
| 1116 | /* All known platforms store window sizes as 'unsigned short'. */ | 1128 | /* All known platforms store window sizes as 'unsigned short'. */ |
| 1117 | CHECK_RANGED_INTEGER (height, 0, USHRT_MAX); | 1129 | CHECK_RANGED_INTEGER (height, 0, USHRT_MAX); |
| 1118 | CHECK_RANGED_INTEGER (width, 0, USHRT_MAX); | 1130 | CHECK_RANGED_INTEGER (width, 0, USHRT_MAX); |
| @@ -1194,6 +1206,12 @@ list of keywords. */) | |||
| 1194 | contact = XPROCESS (process)->childp; | 1206 | contact = XPROCESS (process)->childp; |
| 1195 | 1207 | ||
| 1196 | #ifdef DATAGRAM_SOCKETS | 1208 | #ifdef DATAGRAM_SOCKETS |
| 1209 | |||
| 1210 | #ifdef HAVE_GETADDRINFO_A | ||
| 1211 | if (NETCONN_P (process)) | ||
| 1212 | wait_for_socket_fds (process); | ||
| 1213 | #endif | ||
| 1214 | |||
| 1197 | if (DATAGRAM_CONN_P (process) | 1215 | if (DATAGRAM_CONN_P (process) |
| 1198 | && (EQ (key, Qt) || EQ (key, QCremote))) | 1216 | && (EQ (key, Qt) || EQ (key, QCremote))) |
| 1199 | contact = Fplist_put (contact, QCremote, | 1217 | contact = Fplist_put (contact, QCremote, |
| @@ -2423,6 +2441,11 @@ DEFUN ("process-datagram-address", Fprocess_datagram_address, Sprocess_datagram_ | |||
| 2423 | 2441 | ||
| 2424 | CHECK_PROCESS (process); | 2442 | CHECK_PROCESS (process); |
| 2425 | 2443 | ||
| 2444 | #ifdef HAVE_GETADDRINFO_A | ||
| 2445 | if (NETCONN_P (process)) | ||
| 2446 | wait_for_socket_fds (process); | ||
| 2447 | #endif | ||
| 2448 | |||
| 2426 | if (!DATAGRAM_CONN_P (process)) | 2449 | if (!DATAGRAM_CONN_P (process)) |
| 2427 | return Qnil; | 2450 | return Qnil; |
| 2428 | 2451 | ||
| @@ -2442,6 +2465,11 @@ Returns nil upon error setting address, ADDRESS otherwise. */) | |||
| 2442 | 2465 | ||
| 2443 | CHECK_PROCESS (process); | 2466 | CHECK_PROCESS (process); |
| 2444 | 2467 | ||
| 2468 | #ifdef HAVE_GETADDRINFO_A | ||
| 2469 | if (NETCONN_P (process)) | ||
| 2470 | wait_for_socket_fds (process); | ||
| 2471 | #endif | ||
| 2472 | |||
| 2445 | if (!DATAGRAM_CONN_P (process)) | 2473 | if (!DATAGRAM_CONN_P (process)) |
| 2446 | return Qnil; | 2474 | return Qnil; |
| 2447 | 2475 | ||
| @@ -2610,6 +2638,10 @@ OPTION is not a supported option, return nil instead; otherwise return t. */) | |||
| 2610 | if (!NETCONN1_P (p)) | 2638 | if (!NETCONN1_P (p)) |
| 2611 | error ("Process is not a network process"); | 2639 | error ("Process is not a network process"); |
| 2612 | 2640 | ||
| 2641 | #ifdef HAVE_GETADDRINFO_A | ||
| 2642 | wait_for_socket_fds (process); | ||
| 2643 | #endif | ||
| 2644 | |||
| 2613 | s = p->infd; | 2645 | s = p->infd; |
| 2614 | if (s < 0) | 2646 | if (s < 0) |
| 2615 | error ("Process is not running"); | 2647 | error ("Process is not running"); |
| @@ -3693,7 +3725,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3693 | #endif | 3725 | #endif |
| 3694 | 3726 | ||
| 3695 | #ifdef HAVE_GETADDRINFO_A | 3727 | #ifdef HAVE_GETADDRINFO_A |
| 3696 | if (EQ (Fplist_get (contact, QCnowait), Qdns) && | 3728 | if (EQ (Fplist_get (contact, QCnowait), Qt) && |
| 3697 | !NILP (host)) | 3729 | !NILP (host)) |
| 3698 | { | 3730 | { |
| 3699 | int ret; | 3731 | int ret; |
| @@ -4650,6 +4682,24 @@ check_for_dns (Lisp_Object proc) | |||
| 4650 | 4682 | ||
| 4651 | return ip_addresses; | 4683 | return ip_addresses; |
| 4652 | } | 4684 | } |
| 4685 | |||
| 4686 | static void | ||
| 4687 | wait_for_socket_fds(Lisp_Object process) | ||
| 4688 | { | ||
| 4689 | while (XPROCESS(process)->dns_requests) | ||
| 4690 | { | ||
| 4691 | wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0); | ||
| 4692 | } | ||
| 4693 | } | ||
| 4694 | |||
| 4695 | static void | ||
| 4696 | wait_while_connecting(Lisp_Object process) | ||
| 4697 | { | ||
| 4698 | while (EQ (Qconnect, XPROCESS(process)->status)) | ||
| 4699 | { | ||
| 4700 | wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0); | ||
| 4701 | } | ||
| 4702 | } | ||
| 4653 | #endif /* HAVE_GETADDRINFO_A */ | 4703 | #endif /* HAVE_GETADDRINFO_A */ |
| 4654 | 4704 | ||
| 4655 | /* This variable is different from waiting_for_input in keyboard.c. | 4705 | /* This variable is different from waiting_for_input in keyboard.c. |
| @@ -6143,6 +6193,11 @@ Output from processes can arrive in between bunches. */) | |||
| 6143 | if (XINT (start) < GPT && XINT (end) > GPT) | 6193 | if (XINT (start) < GPT && XINT (end) > GPT) |
| 6144 | move_gap_both (XINT (start), start_byte); | 6194 | move_gap_both (XINT (start), start_byte); |
| 6145 | 6195 | ||
| 6196 | #ifdef HAVE_GETADDRINFO_A | ||
| 6197 | if (NETCONN_P (proc)) | ||
| 6198 | wait_while_connecting (proc); | ||
| 6199 | #endif | ||
| 6200 | |||
| 6146 | send_process (proc, (char *) BYTE_POS_ADDR (start_byte), | 6201 | send_process (proc, (char *) BYTE_POS_ADDR (start_byte), |
| 6147 | end_byte - start_byte, Fcurrent_buffer ()); | 6202 | end_byte - start_byte, Fcurrent_buffer ()); |
| 6148 | 6203 | ||
| @@ -6162,6 +6217,12 @@ Output from processes can arrive in between bunches. */) | |||
| 6162 | Lisp_Object proc; | 6217 | Lisp_Object proc; |
| 6163 | CHECK_STRING (string); | 6218 | CHECK_STRING (string); |
| 6164 | proc = get_process (process); | 6219 | proc = get_process (process); |
| 6220 | |||
| 6221 | #ifdef HAVE_GETADDRINFO_A | ||
| 6222 | if (NETCONN_P (proc)) | ||
| 6223 | wait_while_connecting (proc); | ||
| 6224 | #endif | ||
| 6225 | |||
| 6165 | send_process (proc, SSDATA (string), | 6226 | send_process (proc, SSDATA (string), |
| 6166 | SBYTES (string), string); | 6227 | SBYTES (string), string); |
| 6167 | return Qnil; | 6228 | return Qnil; |
| @@ -6576,10 +6637,17 @@ process has been transmitted to the serial port. */) | |||
| 6576 | struct coding_system *coding = NULL; | 6637 | struct coding_system *coding = NULL; |
| 6577 | int outfd; | 6638 | int outfd; |
| 6578 | 6639 | ||
| 6579 | if (DATAGRAM_CONN_P (process)) | 6640 | proc = get_process (process); |
| 6641 | |||
| 6642 | #ifdef HAVE_GETADDRINFO_A | ||
| 6643 | if (NETCONN_P (proc)) | ||
| 6644 | wait_while_connecting (proc); | ||
| 6645 | #endif | ||
| 6646 | |||
| 6647 | if (DATAGRAM_CONN_P (proc)) | ||
| 6580 | return process; | 6648 | return process; |
| 6581 | 6649 | ||
| 6582 | proc = get_process (process); | 6650 | |
| 6583 | outfd = XPROCESS (proc)->outfd; | 6651 | outfd = XPROCESS (proc)->outfd; |
| 6584 | if (outfd >= 0) | 6652 | if (outfd >= 0) |
| 6585 | coding = proc_encode_coding_system[outfd]; | 6653 | coding = proc_encode_coding_system[outfd]; |
| @@ -7030,7 +7098,14 @@ encode subprocess input. */) | |||
| 7030 | register struct Lisp_Process *p; | 7098 | register struct Lisp_Process *p; |
| 7031 | 7099 | ||
| 7032 | CHECK_PROCESS (process); | 7100 | CHECK_PROCESS (process); |
| 7101 | |||
| 7102 | #ifdef HAVE_GETADDRINFO_A | ||
| 7103 | if (NETCONN_P (process)) | ||
| 7104 | wait_for_socket_fds (process); | ||
| 7105 | #endif | ||
| 7106 | |||
| 7033 | p = XPROCESS (process); | 7107 | p = XPROCESS (process); |
| 7108 | |||
| 7034 | if (p->infd < 0) | 7109 | if (p->infd < 0) |
| 7035 | error ("Input file descriptor of %s closed", SDATA (p->name)); | 7110 | error ("Input file descriptor of %s closed", SDATA (p->name)); |
| 7036 | if (p->outfd < 0) | 7111 | if (p->outfd < 0) |
| @@ -7067,6 +7142,12 @@ suppressed. */) | |||
| 7067 | register struct Lisp_Process *p; | 7142 | register struct Lisp_Process *p; |
| 7068 | 7143 | ||
| 7069 | CHECK_PROCESS (process); | 7144 | CHECK_PROCESS (process); |
| 7145 | |||
| 7146 | #ifdef HAVE_GETADDRINFO_A | ||
| 7147 | if (NETCONN_P (process)) | ||
| 7148 | wait_for_socket_fds (process); | ||
| 7149 | #endif | ||
| 7150 | |||
| 7070 | p = XPROCESS (process); | 7151 | p = XPROCESS (process); |
| 7071 | if (NILP (flag)) | 7152 | if (NILP (flag)) |
| 7072 | pset_decode_coding_system | 7153 | pset_decode_coding_system |
| @@ -7757,7 +7838,6 @@ syms_of_process (void) | |||
| 7757 | DEFSYM (QCcoding, ":coding"); | 7838 | DEFSYM (QCcoding, ":coding"); |
| 7758 | DEFSYM (QCserver, ":server"); | 7839 | DEFSYM (QCserver, ":server"); |
| 7759 | DEFSYM (QCnowait, ":nowait"); | 7840 | DEFSYM (QCnowait, ":nowait"); |
| 7760 | DEFSYM (Qdns, "dns"); | ||
| 7761 | DEFSYM (QCsentinel, ":sentinel"); | 7841 | DEFSYM (QCsentinel, ":sentinel"); |
| 7762 | DEFSYM (QCtls_parameters, ":tls-parameters"); | 7842 | DEFSYM (QCtls_parameters, ":tls-parameters"); |
| 7763 | DEFSYM (QClog, ":log"); | 7843 | DEFSYM (QClog, ":log"); |
| @@ -7921,9 +8001,6 @@ The variable takes effect when `start-process' is called. */); | |||
| 7921 | 8001 | ||
| 7922 | #ifdef NON_BLOCKING_CONNECT | 8002 | #ifdef NON_BLOCKING_CONNECT |
| 7923 | ADD_SUBFEATURE (QCnowait, Qt); | 8003 | ADD_SUBFEATURE (QCnowait, Qt); |
| 7924 | #ifdef HAVE_GETADDRINFO_A | ||
| 7925 | ADD_SUBFEATURE (QCnowait, Qdns); | ||
| 7926 | #endif | ||
| 7927 | #endif | 8004 | #endif |
| 7928 | #ifdef DATAGRAM_SOCKETS | 8005 | #ifdef DATAGRAM_SOCKETS |
| 7929 | ADD_SUBFEATURE (QCtype, Qdatagram); | 8006 | ADD_SUBFEATURE (QCtype, Qdatagram); |