diff options
| author | Paul Eggert | 2016-02-23 09:42:05 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-02-23 09:42:28 -0800 |
| commit | 82848cf689c24a8bc635449846250ea6edb757c4 (patch) | |
| tree | 4263b19e46cf62711d40ec14ccd3173225d48f2a /src/process.c | |
| parent | f4152efd2f7db87134e5e1c50e312a431e81db23 (diff) | |
| download | emacs-82848cf689c24a8bc635449846250ea6edb757c4.tar.gz emacs-82848cf689c24a8bc635449846250ea6edb757c4.zip | |
Minor cleanups for async DNS etc.
* src/frame.h (FRAME_WINDOW_CONFIGURATION_CHANGED):
Omit unnecessary parens.
* src/gnutls.c (gnutls_try_handshake, emacs_gnutls_deinit)
(gnutls_verify_boot):
Use bool for boolean.
(ATTRIBUTE_FORMAT_PRINTF): Add printf attribute.
* src/process.c (free_dns_request, Fmake_network_process):
Allocate and free async request control block all in one go.
(set_network_socket_coding_system, finish_after_tls_connection)
(connect_network_socket):
Now static.
(conv_numerical_to_lisp): 2nd arg is now int, not unsigned.
(Fmake_network_process): Use list1 for brevity.
(wait_for_socket_fds): 2nd arg is now const ptr.
* src/process.h (struct Lisp_Process.dns_request):
Now struct gaicb *, not struct gaicb **, since there was always
exactly one. All uses changed.
* src/window.c, src/window.h (run_window_configuration_change_hook):
Now static.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 233 |
1 files changed, 110 insertions, 123 deletions
diff --git a/src/process.c b/src/process.c index 5172518ac6b..41e821e145d 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -281,7 +281,7 @@ static int max_input_desc; | |||
| 281 | 281 | ||
| 282 | /* Indexed by descriptor, gives the process (if any) for that descriptor. */ | 282 | /* Indexed by descriptor, gives the process (if any) for that descriptor. */ |
| 283 | static Lisp_Object chan_process[FD_SETSIZE]; | 283 | static Lisp_Object chan_process[FD_SETSIZE]; |
| 284 | static void wait_for_socket_fds (Lisp_Object process, char *name); | 284 | static void wait_for_socket_fds (Lisp_Object, char const *); |
| 285 | 285 | ||
| 286 | /* Alist of elements (NAME . PROCESS). */ | 286 | /* Alist of elements (NAME . PROCESS). */ |
| 287 | static Lisp_Object Vprocess_alist; | 287 | static Lisp_Object Vprocess_alist; |
| @@ -745,14 +745,10 @@ free_dns_request (Lisp_Object proc) | |||
| 745 | { | 745 | { |
| 746 | struct Lisp_Process *p = XPROCESS (proc); | 746 | struct Lisp_Process *p = XPROCESS (proc); |
| 747 | 747 | ||
| 748 | if (p->dns_requests[0]->ar_result) | 748 | if (p->dns_request->ar_result) |
| 749 | freeaddrinfo (p->dns_requests[0]->ar_result); | 749 | freeaddrinfo (p->dns_request->ar_result); |
| 750 | xfree ((void *)p->dns_requests[0]->ar_request); | 750 | xfree (p->dns_request); |
| 751 | xfree ((void *)p->dns_requests[0]->ar_name); | 751 | p->dns_request = NULL; |
| 752 | xfree ((void *)p->dns_requests[0]->ar_service); | ||
| 753 | xfree (p->dns_requests[0]); | ||
| 754 | xfree (p->dns_requests); | ||
| 755 | p->dns_requests = NULL; | ||
| 756 | } | 752 | } |
| 757 | #endif | 753 | #endif |
| 758 | 754 | ||
| @@ -847,9 +843,9 @@ nil, indicating the current buffer's process. */) | |||
| 847 | p = XPROCESS (process); | 843 | p = XPROCESS (process); |
| 848 | 844 | ||
| 849 | #ifdef HAVE_GETADDRINFO_A | 845 | #ifdef HAVE_GETADDRINFO_A |
| 850 | if (p->dns_requests) | 846 | if (p->dns_request) |
| 851 | { | 847 | { |
| 852 | gai_cancel (p->dns_requests[0]); | 848 | gai_cancel (p->dns_request); |
| 853 | free_dns_request (process); | 849 | free_dns_request (process); |
| 854 | } | 850 | } |
| 855 | #endif | 851 | #endif |
| @@ -1063,13 +1059,10 @@ The string argument is normally a multibyte string, except: | |||
| 1063 | - if `default-enable-multibyte-characters' is nil, it is a unibyte | 1059 | - if `default-enable-multibyte-characters' is nil, it is a unibyte |
| 1064 | string (the result of converting the decoded input multibyte | 1060 | string (the result of converting the decoded input multibyte |
| 1065 | string to unibyte with `string-make-unibyte'). */) | 1061 | string to unibyte with `string-make-unibyte'). */) |
| 1066 | (register Lisp_Object process, Lisp_Object filter) | 1062 | (Lisp_Object process, Lisp_Object filter) |
| 1067 | { | 1063 | { |
| 1068 | struct Lisp_Process *p; | ||
| 1069 | |||
| 1070 | CHECK_PROCESS (process); | 1064 | CHECK_PROCESS (process); |
| 1071 | 1065 | struct Lisp_Process *p = XPROCESS (process); | |
| 1072 | p = XPROCESS (process); | ||
| 1073 | 1066 | ||
| 1074 | /* Don't signal an error if the process's input file descriptor | 1067 | /* Don't signal an error if the process's input file descriptor |
| 1075 | is closed. This could make debugging Lisp more difficult, | 1068 | is closed. This could make debugging Lisp more difficult, |
| @@ -1217,7 +1210,7 @@ returned. See `make-network-process' or `make-serial-process' for a | |||
| 1217 | list of keywords. | 1210 | list of keywords. |
| 1218 | If PROCESS is a non-blocking network process that hasn't been fully | 1211 | If PROCESS is a non-blocking network process that hasn't been fully |
| 1219 | set up yet, this function will block until socket setup has completed. */) | 1212 | set up yet, this function will block until socket setup has completed. */) |
| 1220 | (register Lisp_Object process, Lisp_Object key) | 1213 | (Lisp_Object process, Lisp_Object key) |
| 1221 | { | 1214 | { |
| 1222 | Lisp_Object contact; | 1215 | Lisp_Object contact; |
| 1223 | 1216 | ||
| @@ -1263,8 +1256,8 @@ DEFUN ("process-plist", Fprocess_plist, Sprocess_plist, | |||
| 1263 | 1256 | ||
| 1264 | DEFUN ("set-process-plist", Fset_process_plist, Sset_process_plist, | 1257 | DEFUN ("set-process-plist", Fset_process_plist, Sset_process_plist, |
| 1265 | 2, 2, 0, | 1258 | 2, 2, 0, |
| 1266 | doc: /* Replace the plist of PROCESS with PLIST. Returns PLIST. */) | 1259 | doc: /* Replace the plist of PROCESS with PLIST. Return PLIST. */) |
| 1267 | (register Lisp_Object process, Lisp_Object plist) | 1260 | (Lisp_Object process, Lisp_Object plist) |
| 1268 | { | 1261 | { |
| 1269 | CHECK_PROCESS (process); | 1262 | CHECK_PROCESS (process); |
| 1270 | CHECK_LIST (plist); | 1263 | CHECK_LIST (plist); |
| @@ -1304,7 +1297,7 @@ A 4 or 5 element vector represents an IPv4 address (with port number). | |||
| 1304 | An 8 or 9 element vector represents an IPv6 address (with port number). | 1297 | An 8 or 9 element vector represents an IPv6 address (with port number). |
| 1305 | If optional second argument OMIT-PORT is non-nil, don't include a port | 1298 | If optional second argument OMIT-PORT is non-nil, don't include a port |
| 1306 | number in the string, even when present in ADDRESS. | 1299 | number in the string, even when present in ADDRESS. |
| 1307 | Returns nil if format of ADDRESS is invalid. */) | 1300 | Return nil if format of ADDRESS is invalid. */) |
| 1308 | (Lisp_Object address, Lisp_Object omit_port) | 1301 | (Lisp_Object address, Lisp_Object omit_port) |
| 1309 | { | 1302 | { |
| 1310 | if (NILP (address)) | 1303 | if (NILP (address)) |
| @@ -2474,7 +2467,7 @@ set up yet, this function will block until socket setup has completed. */) | |||
| 2474 | DEFUN ("set-process-datagram-address", Fset_process_datagram_address, Sset_process_datagram_address, | 2467 | DEFUN ("set-process-datagram-address", Fset_process_datagram_address, Sset_process_datagram_address, |
| 2475 | 2, 2, 0, | 2468 | 2, 2, 0, |
| 2476 | doc: /* Set the datagram address for PROCESS to ADDRESS. | 2469 | doc: /* Set the datagram address for PROCESS to ADDRESS. |
| 2477 | Returns nil upon error setting address, ADDRESS otherwise. | 2470 | Return nil upon error setting address, ADDRESS otherwise. |
| 2478 | 2471 | ||
| 2479 | If PROCESS is a non-blocking network process that hasn't been fully | 2472 | If PROCESS is a non-blocking network process that hasn't been fully |
| 2480 | set up yet, this function will block until socket setup has completed. */) | 2473 | set up yet, this function will block until socket setup has completed. */) |
| @@ -2543,7 +2536,7 @@ static const struct socket_options { | |||
| 2543 | 2536 | ||
| 2544 | /* Set option OPT to value VAL on socket S. | 2537 | /* Set option OPT to value VAL on socket S. |
| 2545 | 2538 | ||
| 2546 | Returns (1<<socket_options[OPT].optbit) if option is known, 0 otherwise. | 2539 | Return (1<<socket_options[OPT].optbit) if option is known, 0 otherwise. |
| 2547 | Signals an error if setting a known option fails. | 2540 | Signals an error if setting a known option fails. |
| 2548 | */ | 2541 | */ |
| 2549 | 2542 | ||
| @@ -2955,10 +2948,9 @@ usage: (make-serial-process &rest ARGS) */) | |||
| 2955 | return proc; | 2948 | return proc; |
| 2956 | } | 2949 | } |
| 2957 | 2950 | ||
| 2958 | void set_network_socket_coding_system (Lisp_Object proc, | 2951 | static void |
| 2959 | Lisp_Object host, | 2952 | set_network_socket_coding_system (Lisp_Object proc, Lisp_Object host, |
| 2960 | Lisp_Object service, | 2953 | Lisp_Object service, Lisp_Object name) |
| 2961 | Lisp_Object name) | ||
| 2962 | { | 2954 | { |
| 2963 | Lisp_Object tem; | 2955 | Lisp_Object tem; |
| 2964 | struct Lisp_Process *p = XPROCESS (proc); | 2956 | struct Lisp_Process *p = XPROCESS (proc); |
| @@ -2981,9 +2973,10 @@ void set_network_socket_coding_system (Lisp_Object proc, | |||
| 2981 | } | 2973 | } |
| 2982 | else if (!NILP (Vcoding_system_for_read)) | 2974 | else if (!NILP (Vcoding_system_for_read)) |
| 2983 | val = Vcoding_system_for_read; | 2975 | val = Vcoding_system_for_read; |
| 2984 | else if ((!NILP (p->buffer) && | 2976 | else if ((!NILP (p->buffer) |
| 2985 | NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters))) | 2977 | && NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters))) |
| 2986 | || (NILP (p->buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))) | 2978 | || (NILP (p->buffer) |
| 2979 | && NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))) | ||
| 2987 | /* We dare not decode end-of-line format by setting VAL to | 2980 | /* We dare not decode end-of-line format by setting VAL to |
| 2988 | Qraw_text, because the existing Emacs Lisp libraries | 2981 | Qraw_text, because the existing Emacs Lisp libraries |
| 2989 | assume that they receive bare code including a sequence of | 2982 | assume that they receive bare code including a sequence of |
| @@ -3045,7 +3038,7 @@ void set_network_socket_coding_system (Lisp_Object proc, | |||
| 3045 | } | 3038 | } |
| 3046 | 3039 | ||
| 3047 | #ifdef HAVE_GNUTLS | 3040 | #ifdef HAVE_GNUTLS |
| 3048 | void | 3041 | static void |
| 3049 | finish_after_tls_connection (Lisp_Object proc) | 3042 | finish_after_tls_connection (Lisp_Object proc) |
| 3050 | { | 3043 | { |
| 3051 | struct Lisp_Process *p = XPROCESS (proc); | 3044 | struct Lisp_Process *p = XPROCESS (proc); |
| @@ -3081,7 +3074,7 @@ finish_after_tls_connection (Lisp_Object proc) | |||
| 3081 | } | 3074 | } |
| 3082 | #endif | 3075 | #endif |
| 3083 | 3076 | ||
| 3084 | void | 3077 | static void |
| 3085 | connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses) | 3078 | connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses) |
| 3086 | { | 3079 | { |
| 3087 | ptrdiff_t count = SPECPDL_INDEX (); | 3080 | ptrdiff_t count = SPECPDL_INDEX (); |
| @@ -3190,8 +3183,8 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses) | |||
| 3190 | Lisp_Object service; | 3183 | Lisp_Object service; |
| 3191 | service = make_number (ntohs (sa1.sin_port)); | 3184 | service = make_number (ntohs (sa1.sin_port)); |
| 3192 | contact = Fplist_put (contact, QCservice, service); | 3185 | contact = Fplist_put (contact, QCservice, service); |
| 3193 | // Save the port number so that we can stash it in | 3186 | /* Save the port number so that we can stash it in |
| 3194 | // the process object later. | 3187 | the process object later. */ |
| 3195 | ((struct sockaddr_in *)sa)->sin_port = sa1.sin_port; | 3188 | ((struct sockaddr_in *)sa)->sin_port = sa1.sin_port; |
| 3196 | } | 3189 | } |
| 3197 | } | 3190 | } |
| @@ -3422,15 +3415,14 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses) | |||
| 3422 | 3415 | ||
| 3423 | #ifndef HAVE_GETADDRINFO | 3416 | #ifndef HAVE_GETADDRINFO |
| 3424 | static Lisp_Object | 3417 | static Lisp_Object |
| 3425 | conv_numerical_to_lisp (unsigned char *number, unsigned int length, int port) | 3418 | conv_numerical_to_lisp (unsigned char *number, int length, int port) |
| 3426 | { | 3419 | { |
| 3427 | Lisp_Object address = Fmake_vector (make_number (length + 1), Qnil); | 3420 | Lisp_Object address = Fmake_vector (make_number (length + 1), Qnil); |
| 3428 | register struct Lisp_Vector *p = XVECTOR (address); | 3421 | struct Lisp_Vector *p = XVECTOR (address); |
| 3429 | int i; | ||
| 3430 | 3422 | ||
| 3431 | p->contents[length] = make_number (port); | 3423 | p->contents[length] = make_number (port); |
| 3432 | for (i = 0; i < length; i++) | 3424 | for (int i = 0; i < length; i++) |
| 3433 | p->contents[i] = make_number (*(number + i)); | 3425 | p->contents[i] = make_number (number[i]); |
| 3434 | 3426 | ||
| 3435 | return address; | 3427 | return address; |
| 3436 | } | 3428 | } |
| @@ -3606,9 +3598,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3606 | Lisp_Object proc; | 3598 | Lisp_Object proc; |
| 3607 | Lisp_Object contact; | 3599 | Lisp_Object contact; |
| 3608 | struct Lisp_Process *p; | 3600 | struct Lisp_Process *p; |
| 3609 | #if defined(HAVE_GETADDRINFO) || defined(HAVE_GETADDRINFO_A) | 3601 | #if defined HAVE_GETADDRINFO || defined HAVE_GETADDRINFO_A |
| 3610 | struct addrinfo *hints; | ||
| 3611 | const char *portstring; | 3602 | const char *portstring; |
| 3603 | ptrdiff_t portstringlen; | ||
| 3612 | char portbuf[128]; | 3604 | char portbuf[128]; |
| 3613 | #endif | 3605 | #endif |
| 3614 | #ifdef HAVE_LOCAL_SOCKETS | 3606 | #ifdef HAVE_LOCAL_SOCKETS |
| @@ -3623,7 +3615,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3623 | int family = -1; | 3615 | int family = -1; |
| 3624 | int ai_protocol = 0; | 3616 | int ai_protocol = 0; |
| 3625 | #ifdef HAVE_GETADDRINFO_A | 3617 | #ifdef HAVE_GETADDRINFO_A |
| 3626 | struct gaicb **dns_requests = NULL; | 3618 | struct gaicb *dns_request = NULL; |
| 3627 | #endif | 3619 | #endif |
| 3628 | ptrdiff_t count = SPECPDL_INDEX (); | 3620 | ptrdiff_t count = SPECPDL_INDEX (); |
| 3629 | 3621 | ||
| @@ -3673,7 +3665,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3673 | if (!get_lisp_to_sockaddr_size (address, &family)) | 3665 | if (!get_lisp_to_sockaddr_size (address, &family)) |
| 3674 | error ("Malformed :address"); | 3666 | error ("Malformed :address"); |
| 3675 | 3667 | ||
| 3676 | ip_addresses = Fcons (address, Qnil); | 3668 | ip_addresses = list1 (address); |
| 3677 | goto open_socket; | 3669 | goto open_socket; |
| 3678 | } | 3670 | } |
| 3679 | 3671 | ||
| @@ -3737,7 +3729,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3737 | CHECK_STRING (service); | 3729 | CHECK_STRING (service); |
| 3738 | if (sizeof address_un.sun_path <= SBYTES (service)) | 3730 | if (sizeof address_un.sun_path <= SBYTES (service)) |
| 3739 | error ("Service name too long"); | 3731 | error ("Service name too long"); |
| 3740 | ip_addresses = Fcons (service, Qnil); | 3732 | ip_addresses = list1 (service); |
| 3741 | goto open_socket; | 3733 | goto open_socket; |
| 3742 | } | 3734 | } |
| 3743 | #endif | 3735 | #endif |
| @@ -3753,48 +3745,53 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3753 | } | 3745 | } |
| 3754 | #endif | 3746 | #endif |
| 3755 | 3747 | ||
| 3756 | #if defined (HAVE_GETADDRINFO) || defined (HAVE_GETADDRINFO_A) | 3748 | #if defined HAVE_GETADDRINFO || defined HAVE_GETADDRINFO_A |
| 3757 | if (!NILP (host)) | 3749 | if (!NILP (host)) |
| 3758 | { | 3750 | { |
| 3759 | |||
| 3760 | /* SERVICE can either be a string or int. | 3751 | /* SERVICE can either be a string or int. |
| 3761 | Convert to a C string for later use by getaddrinfo. */ | 3752 | Convert to a C string for later use by getaddrinfo. */ |
| 3762 | if (EQ (service, Qt)) | 3753 | if (EQ (service, Qt)) |
| 3763 | portstring = "0"; | 3754 | { |
| 3755 | portstring = "0"; | ||
| 3756 | portstringlen = 1; | ||
| 3757 | } | ||
| 3764 | else if (INTEGERP (service)) | 3758 | else if (INTEGERP (service)) |
| 3765 | { | 3759 | { |
| 3766 | sprintf (portbuf, "%"pI"d", XINT (service)); | ||
| 3767 | portstring = portbuf; | 3760 | portstring = portbuf; |
| 3761 | portstringlen = sprintf (portbuf, "%"pI"d", XINT (service)); | ||
| 3768 | } | 3762 | } |
| 3769 | else | 3763 | else |
| 3770 | { | 3764 | { |
| 3771 | CHECK_STRING (service); | 3765 | CHECK_STRING (service); |
| 3772 | portstring = SSDATA (service); | 3766 | portstring = SSDATA (service); |
| 3767 | portstringlen = SBYTES (service); | ||
| 3773 | } | 3768 | } |
| 3774 | |||
| 3775 | hints = xzalloc (sizeof (struct addrinfo)); | ||
| 3776 | hints->ai_flags = 0; | ||
| 3777 | hints->ai_family = family; | ||
| 3778 | hints->ai_socktype = socktype; | ||
| 3779 | hints->ai_protocol = 0; | ||
| 3780 | } | 3769 | } |
| 3781 | |||
| 3782 | #endif | 3770 | #endif |
| 3783 | 3771 | ||
| 3784 | #ifdef HAVE_GETADDRINFO_A | 3772 | #ifdef HAVE_GETADDRINFO_A |
| 3785 | if (!NILP (Fplist_get (contact, QCnowait)) && | 3773 | if (!NILP (Fplist_get (contact, QCnowait)) && !NILP (host)) |
| 3786 | !NILP (host)) | ||
| 3787 | { | 3774 | { |
| 3788 | int ret; | 3775 | ptrdiff_t hostlen = SBYTES (host); |
| 3789 | 3776 | struct req | |
| 3790 | dns_requests = xmalloc (sizeof (struct gaicb*)); | 3777 | { |
| 3791 | dns_requests[0] = xmalloc (sizeof (struct gaicb)); | 3778 | struct gaicb gaicb; |
| 3792 | dns_requests[0]->ar_name = strdup (SSDATA (host)); | 3779 | struct addrinfo hints; |
| 3793 | dns_requests[0]->ar_service = strdup (portstring); | 3780 | char str[FLEXIBLE_ARRAY_MEMBER]; |
| 3794 | dns_requests[0]->ar_request = hints; | 3781 | } *req = xmalloc (offsetof (struct req, str) |
| 3795 | dns_requests[0]->ar_result = NULL; | 3782 | + hostlen + 1 + portstringlen + 1); |
| 3796 | 3783 | dns_request = &req->gaicb; | |
| 3797 | ret = getaddrinfo_a (GAI_NOWAIT, dns_requests, 1, NULL); | 3784 | dns_request->ar_name = req->str; |
| 3785 | dns_request->ar_service = req->str + hostlen + 1; | ||
| 3786 | dns_request->ar_request = &req->hints; | ||
| 3787 | dns_request->ar_result = NULL; | ||
| 3788 | memset (&req->hints, 0, sizeof req->hints); | ||
| 3789 | req->hints.ai_family = family; | ||
| 3790 | req->hints.ai_socktype = socktype; | ||
| 3791 | strcpy (req->str, SSDATA (host)); | ||
| 3792 | strcpy (req->str + hostlen + 1, portstring); | ||
| 3793 | |||
| 3794 | int ret = getaddrinfo_a (GAI_NOWAIT, &dns_request, 1, NULL); | ||
| 3798 | if (ret) | 3795 | if (ret) |
| 3799 | error ("%s/%s getaddrinfo_a error %d", SSDATA (host), portstring, ret); | 3796 | error ("%s/%s getaddrinfo_a error %d", SSDATA (host), portstring, ret); |
| 3800 | 3797 | ||
| @@ -3818,7 +3815,12 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3818 | res_init (); | 3815 | res_init (); |
| 3819 | #endif | 3816 | #endif |
| 3820 | 3817 | ||
| 3821 | ret = getaddrinfo (SSDATA (host), portstring, hints, &res); | 3818 | struct addrinfo hints; |
| 3819 | memset (&hints, 0, sizeof hints); | ||
| 3820 | hints.ai_family = family; | ||
| 3821 | hints.ai_socktype = socktype; | ||
| 3822 | |||
| 3823 | ret = getaddrinfo (SSDATA (host), portstring, &hints, &res); | ||
| 3822 | if (ret) | 3824 | if (ret) |
| 3823 | #ifdef HAVE_GAI_STRERROR | 3825 | #ifdef HAVE_GAI_STRERROR |
| 3824 | error ("%s/%s %s", SSDATA (host), portstring, gai_strerror (ret)); | 3826 | error ("%s/%s %s", SSDATA (host), portstring, gai_strerror (ret)); |
| @@ -3838,7 +3840,6 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3838 | ip_addresses = Fnreverse (ip_addresses); | 3840 | ip_addresses = Fnreverse (ip_addresses); |
| 3839 | 3841 | ||
| 3840 | freeaddrinfo (res); | 3842 | freeaddrinfo (res); |
| 3841 | xfree (hints); | ||
| 3842 | 3843 | ||
| 3843 | goto open_socket; | 3844 | goto open_socket; |
| 3844 | } | 3845 | } |
| @@ -3866,6 +3867,8 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3866 | if (!NILP (host)) | 3867 | if (!NILP (host)) |
| 3867 | { | 3868 | { |
| 3868 | struct hostent *host_info_ptr; | 3869 | struct hostent *host_info_ptr; |
| 3870 | unsigned char *addr; | ||
| 3871 | int addrlen; | ||
| 3869 | 3872 | ||
| 3870 | /* gethostbyname may fail with TRY_AGAIN, but we don't honor that, | 3873 | /* gethostbyname may fail with TRY_AGAIN, but we don't honor that, |
| 3871 | as it may `hang' Emacs for a very long time. */ | 3874 | as it may `hang' Emacs for a very long time. */ |
| @@ -3881,11 +3884,8 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3881 | 3884 | ||
| 3882 | if (host_info_ptr) | 3885 | if (host_info_ptr) |
| 3883 | { | 3886 | { |
| 3884 | ip_addresses = Fcons (conv_numerical_to_lisp | 3887 | addr = (unsigned char *) host_info_ptr->h_addr; |
| 3885 | ((unsigned char *) host_info_ptr->h_addr, | 3888 | addrlen = host_info_ptr->h_length; |
| 3886 | host_info_ptr->h_length, | ||
| 3887 | port), | ||
| 3888 | Qnil); | ||
| 3889 | } | 3889 | } |
| 3890 | else | 3890 | else |
| 3891 | /* Attempt to interpret host as numeric inet address. This | 3891 | /* Attempt to interpret host as numeric inet address. This |
| @@ -3896,11 +3896,11 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3896 | if (numeric_addr == -1) | 3896 | if (numeric_addr == -1) |
| 3897 | error ("Unknown host \"%s\"", SDATA (host)); | 3897 | error ("Unknown host \"%s\"", SDATA (host)); |
| 3898 | 3898 | ||
| 3899 | ip_addresses = Fcons (conv_numerical_to_lisp | 3899 | addr = (unsigned char *) &numeric_addr; |
| 3900 | ((unsigned char *) &numeric_addr, 4, port), | 3900 | addrlen = 4; |
| 3901 | Qnil); | ||
| 3902 | } | 3901 | } |
| 3903 | 3902 | ||
| 3903 | ip_addresses = list1 (conv_numerical_to_lisp (addr, addrlen, port)); | ||
| 3904 | } | 3904 | } |
| 3905 | #endif /* not HAVE_GETADDRINFO */ | 3905 | #endif /* not HAVE_GETADDRINFO */ |
| 3906 | 3906 | ||
| @@ -3930,7 +3930,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3930 | p->socktype = socktype; | 3930 | p->socktype = socktype; |
| 3931 | p->ai_protocol = ai_protocol; | 3931 | p->ai_protocol = ai_protocol; |
| 3932 | #ifdef HAVE_GETADDRINFO_A | 3932 | #ifdef HAVE_GETADDRINFO_A |
| 3933 | p->dns_requests = NULL; | 3933 | p->dns_request = NULL; |
| 3934 | #endif | 3934 | #endif |
| 3935 | #ifdef HAVE_GNUTLS | 3935 | #ifdef HAVE_GNUTLS |
| 3936 | tem = Fplist_get (contact, QCtls_parameters); | 3936 | tem = Fplist_get (contact, QCtls_parameters); |
| @@ -3969,7 +3969,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3969 | here will be nil, so we postpone connecting to the server. */ | 3969 | here will be nil, so we postpone connecting to the server. */ |
| 3970 | if (!p->is_server && NILP (ip_addresses)) | 3970 | if (!p->is_server && NILP (ip_addresses)) |
| 3971 | { | 3971 | { |
| 3972 | p->dns_requests = dns_requests; | 3972 | p->dns_request = dns_request; |
| 3973 | p->status = Qconnect; | 3973 | p->status = Qconnect; |
| 3974 | } | 3974 | } |
| 3975 | else | 3975 | else |
| @@ -4693,10 +4693,10 @@ check_for_dns (Lisp_Object proc) | |||
| 4693 | int ret = 0; | 4693 | int ret = 0; |
| 4694 | 4694 | ||
| 4695 | /* Sanity check. */ | 4695 | /* Sanity check. */ |
| 4696 | if (! p->dns_requests) | 4696 | if (! p->dns_request) |
| 4697 | return Qnil; | 4697 | return Qnil; |
| 4698 | 4698 | ||
| 4699 | ret = gai_error (p->dns_requests[0]); | 4699 | ret = gai_error (p->dns_request); |
| 4700 | if (ret == EAI_INPROGRESS) | 4700 | if (ret == EAI_INPROGRESS) |
| 4701 | return Qt; | 4701 | return Qt; |
| 4702 | 4702 | ||
| @@ -4705,7 +4705,7 @@ check_for_dns (Lisp_Object proc) | |||
| 4705 | { | 4705 | { |
| 4706 | struct addrinfo *res; | 4706 | struct addrinfo *res; |
| 4707 | 4707 | ||
| 4708 | for (res = p->dns_requests[0]->ar_result; res; res = res->ai_next) | 4708 | for (res = p->dns_request->ar_result; res; res = res->ai_next) |
| 4709 | { | 4709 | { |
| 4710 | ip_addresses = Fcons (conv_sockaddr_to_lisp | 4710 | ip_addresses = Fcons (conv_sockaddr_to_lisp |
| 4711 | (res->ai_addr, res->ai_addrlen), | 4711 | (res->ai_addr, res->ai_addrlen), |
| @@ -4721,7 +4721,7 @@ check_for_dns (Lisp_Object proc) | |||
| 4721 | pset_status (p, (list2 | 4721 | pset_status (p, (list2 |
| 4722 | (Qfailed, | 4722 | (Qfailed, |
| 4723 | concat3 (build_string ("Name lookup of "), | 4723 | concat3 (build_string ("Name lookup of "), |
| 4724 | build_string (p->dns_requests[0]->ar_name), | 4724 | build_string (p->dns_request->ar_name), |
| 4725 | build_string (" failed"))))); | 4725 | build_string (" failed"))))); |
| 4726 | } | 4726 | } |
| 4727 | 4727 | ||
| @@ -4737,10 +4737,10 @@ check_for_dns (Lisp_Object proc) | |||
| 4737 | #endif /* HAVE_GETADDRINFO_A */ | 4737 | #endif /* HAVE_GETADDRINFO_A */ |
| 4738 | 4738 | ||
| 4739 | static void | 4739 | static void |
| 4740 | wait_for_socket_fds (Lisp_Object process, char *name) | 4740 | wait_for_socket_fds (Lisp_Object process, char const *name) |
| 4741 | { | 4741 | { |
| 4742 | while (XPROCESS (process)->infd < 0 && | 4742 | while (XPROCESS (process)->infd < 0 |
| 4743 | EQ (XPROCESS (process)->status, Qconnect)) | 4743 | && EQ (XPROCESS (process)->status, Qconnect)) |
| 4744 | { | 4744 | { |
| 4745 | add_to_log ("Waiting for socket from %s...", build_string (name)); | 4745 | add_to_log ("Waiting for socket from %s...", build_string (name)); |
| 4746 | wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0); | 4746 | wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0); |
| @@ -4761,8 +4761,8 @@ static void | |||
| 4761 | wait_for_tls_negotiation (Lisp_Object process) | 4761 | wait_for_tls_negotiation (Lisp_Object process) |
| 4762 | { | 4762 | { |
| 4763 | #ifdef HAVE_GNUTLS | 4763 | #ifdef HAVE_GNUTLS |
| 4764 | while (XPROCESS (process)->gnutls_p && | 4764 | while (XPROCESS (process)->gnutls_p |
| 4765 | XPROCESS (process)->gnutls_initstage != GNUTLS_STAGE_READY) | 4765 | && XPROCESS (process)->gnutls_initstage != GNUTLS_STAGE_READY) |
| 4766 | { | 4766 | { |
| 4767 | add_to_log ("Waiting for TLS..."); | 4767 | add_to_log ("Waiting for TLS..."); |
| 4768 | wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0); | 4768 | wait_reading_process_output (0, 20 * 1000 * 1000, 0, 0, Qnil, NULL, 0); |
| @@ -4895,7 +4895,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4895 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | 4895 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) |
| 4896 | break; | 4896 | break; |
| 4897 | 4897 | ||
| 4898 | #if defined (HAVE_GETADDRINFO_A) || defined (HAVE_GNUTLS) | 4898 | #if defined HAVE_GETADDRINFO_A || defined HAVE_GNUTLS |
| 4899 | { | 4899 | { |
| 4900 | Lisp_Object ip_addresses; | 4900 | Lisp_Object ip_addresses; |
| 4901 | Lisp_Object process_list_head, aproc; | 4901 | Lisp_Object process_list_head, aproc; |
| @@ -4909,18 +4909,17 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4909 | { | 4909 | { |
| 4910 | #ifdef HAVE_GETADDRINFO_A | 4910 | #ifdef HAVE_GETADDRINFO_A |
| 4911 | /* Check for pending DNS requests. */ | 4911 | /* Check for pending DNS requests. */ |
| 4912 | if (p->dns_requests) | 4912 | if (p->dns_request) |
| 4913 | { | 4913 | { |
| 4914 | ip_addresses = check_for_dns (aproc); | 4914 | ip_addresses = check_for_dns (aproc); |
| 4915 | if (!NILP (ip_addresses) && | 4915 | if (!NILP (ip_addresses) && !EQ (ip_addresses, Qt)) |
| 4916 | !EQ (ip_addresses, Qt)) | ||
| 4917 | connect_network_socket (aproc, ip_addresses); | 4916 | connect_network_socket (aproc, ip_addresses); |
| 4918 | } | 4917 | } |
| 4919 | #endif | 4918 | #endif |
| 4920 | #ifdef HAVE_GNUTLS | 4919 | #ifdef HAVE_GNUTLS |
| 4921 | /* Continue TLS negotiation. */ | 4920 | /* Continue TLS negotiation. */ |
| 4922 | if (p->gnutls_initstage == GNUTLS_STAGE_HANDSHAKE_TRIED && | 4921 | if (p->gnutls_initstage == GNUTLS_STAGE_HANDSHAKE_TRIED |
| 4923 | p->is_non_blocking_client) | 4922 | && p->is_non_blocking_client) |
| 4924 | { | 4923 | { |
| 4925 | gnutls_try_handshake (p); | 4924 | gnutls_try_handshake (p); |
| 4926 | p->gnutls_handshakes_tried++; | 4925 | p->gnutls_handshakes_tried++; |
| @@ -4930,8 +4929,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4930 | gnutls_verify_boot (aproc, Qnil); | 4929 | gnutls_verify_boot (aproc, Qnil); |
| 4931 | finish_after_tls_connection (aproc); | 4930 | finish_after_tls_connection (aproc); |
| 4932 | } | 4931 | } |
| 4933 | else if (p->gnutls_handshakes_tried > | 4932 | else if (p->gnutls_handshakes_tried |
| 4934 | GNUTLS_EMACS_HANDSHAKES_LIMIT) | 4933 | > GNUTLS_EMACS_HANDSHAKES_LIMIT) |
| 4935 | { | 4934 | { |
| 4936 | deactivate_process (aproc); | 4935 | deactivate_process (aproc); |
| 4937 | pset_status (p, list2 (Qfailed, | 4936 | pset_status (p, list2 (Qfailed, |
| @@ -5567,8 +5566,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5567 | /* If we have an incompletely set up TLS connection, | 5566 | /* If we have an incompletely set up TLS connection, |
| 5568 | then defer the sentinel signalling until | 5567 | then defer the sentinel signalling until |
| 5569 | later. */ | 5568 | later. */ |
| 5570 | if (NILP (p->gnutls_boot_parameters) && | 5569 | if (NILP (p->gnutls_boot_parameters) |
| 5571 | !p->gnutls_p) | 5570 | && !p->gnutls_p) |
| 5572 | #endif | 5571 | #endif |
| 5573 | { | 5572 | { |
| 5574 | pset_status (p, Qrun); | 5573 | pset_status (p, Qrun); |
| @@ -6034,10 +6033,11 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, | |||
| 6034 | ssize_t rv; | 6033 | ssize_t rv; |
| 6035 | struct coding_system *coding; | 6034 | struct coding_system *coding; |
| 6036 | 6035 | ||
| 6037 | if (NETCONN_P (proc)) { | 6036 | if (NETCONN_P (proc)) |
| 6038 | wait_while_connecting (proc); | 6037 | { |
| 6039 | wait_for_tls_negotiation (proc); | 6038 | wait_while_connecting (proc); |
| 6040 | } | 6039 | wait_for_tls_negotiation (proc); |
| 6040 | } | ||
| 6041 | 6041 | ||
| 6042 | if (p->raw_status_new) | 6042 | if (p->raw_status_new) |
| 6043 | update_status (p); | 6043 | update_status (p); |
| @@ -6295,10 +6295,8 @@ If PROCESS is a non-blocking network process that hasn't been fully | |||
| 6295 | set up yet, this function will block until socket setup has completed. */) | 6295 | set up yet, this function will block until socket setup has completed. */) |
| 6296 | (Lisp_Object process, Lisp_Object string) | 6296 | (Lisp_Object process, Lisp_Object string) |
| 6297 | { | 6297 | { |
| 6298 | Lisp_Object proc; | ||
| 6299 | CHECK_STRING (string); | 6298 | CHECK_STRING (string); |
| 6300 | proc = get_process (process); | 6299 | Lisp_Object proc = get_process (process); |
| 6301 | |||
| 6302 | send_process (proc, SSDATA (string), | 6300 | send_process (proc, SSDATA (string), |
| 6303 | SBYTES (string), string); | 6301 | SBYTES (string), string); |
| 6304 | return Qnil; | 6302 | return Qnil; |
| @@ -6340,12 +6338,8 @@ process group. */) | |||
| 6340 | { | 6338 | { |
| 6341 | /* Initialize in case ioctl doesn't exist or gives an error, | 6339 | /* Initialize in case ioctl doesn't exist or gives an error, |
| 6342 | in a way that will cause returning t. */ | 6340 | in a way that will cause returning t. */ |
| 6343 | pid_t gid; | 6341 | Lisp_Object proc = get_process (process); |
| 6344 | Lisp_Object proc; | 6342 | struct Lisp_Process *p = XPROCESS (proc); |
| 6345 | struct Lisp_Process *p; | ||
| 6346 | |||
| 6347 | proc = get_process (process); | ||
| 6348 | p = XPROCESS (proc); | ||
| 6349 | 6343 | ||
| 6350 | if (!EQ (p->type, Qreal)) | 6344 | if (!EQ (p->type, Qreal)) |
| 6351 | error ("Process %s is not a subprocess", | 6345 | error ("Process %s is not a subprocess", |
| @@ -6354,7 +6348,7 @@ process group. */) | |||
| 6354 | error ("Process %s is not active", | 6348 | error ("Process %s is not active", |
| 6355 | SDATA (p->name)); | 6349 | SDATA (p->name)); |
| 6356 | 6350 | ||
| 6357 | gid = emacs_get_tty_pgrp (p); | 6351 | pid_t gid = emacs_get_tty_pgrp (p); |
| 6358 | 6352 | ||
| 6359 | if (gid == p->pid) | 6353 | if (gid == p->pid) |
| 6360 | return Qnil; | 6354 | return Qnil; |
| @@ -7170,16 +7164,14 @@ encode subprocess input. | |||
| 7170 | 7164 | ||
| 7171 | If PROCESS is a non-blocking network process that hasn't been fully | 7165 | If PROCESS is a non-blocking network process that hasn't been fully |
| 7172 | set up yet, this function will block until socket setup has completed. */) | 7166 | set up yet, this function will block until socket setup has completed. */) |
| 7173 | (register Lisp_Object process, Lisp_Object decoding, Lisp_Object encoding) | 7167 | (Lisp_Object process, Lisp_Object decoding, Lisp_Object encoding) |
| 7174 | { | 7168 | { |
| 7175 | register struct Lisp_Process *p; | ||
| 7176 | |||
| 7177 | CHECK_PROCESS (process); | 7169 | CHECK_PROCESS (process); |
| 7178 | 7170 | ||
| 7179 | if (NETCONN_P (process)) | 7171 | if (NETCONN_P (process)) |
| 7180 | wait_for_socket_fds (process, "set-process-coding-system"); | 7172 | wait_for_socket_fds (process, "set-process-coding-system"); |
| 7181 | 7173 | ||
| 7182 | p = XPROCESS (process); | 7174 | struct Lisp_Process *p = XPROCESS (process); |
| 7183 | 7175 | ||
| 7184 | if (p->infd < 0) | 7176 | if (p->infd < 0) |
| 7185 | error ("Input file descriptor of %s closed", SDATA (p->name)); | 7177 | error ("Input file descriptor of %s closed", SDATA (p->name)); |
| @@ -7214,14 +7206,12 @@ all character code conversion except for end-of-line conversion is | |||
| 7214 | suppressed. */) | 7206 | suppressed. */) |
| 7215 | (Lisp_Object process, Lisp_Object flag) | 7207 | (Lisp_Object process, Lisp_Object flag) |
| 7216 | { | 7208 | { |
| 7217 | register struct Lisp_Process *p; | ||
| 7218 | |||
| 7219 | CHECK_PROCESS (process); | 7209 | CHECK_PROCESS (process); |
| 7220 | 7210 | ||
| 7221 | if (NETCONN_P (process)) | 7211 | if (NETCONN_P (process)) |
| 7222 | wait_for_socket_fds (process, "set-process-filter-multibyte"); | 7212 | wait_for_socket_fds (process, "set-process-filter-multibyte"); |
| 7223 | 7213 | ||
| 7224 | p = XPROCESS (process); | 7214 | struct Lisp_Process *p = XPROCESS (process); |
| 7225 | if (NILP (flag)) | 7215 | if (NILP (flag)) |
| 7226 | pset_decode_coding_system | 7216 | pset_decode_coding_system |
| 7227 | (p, raw_text_coding_system (p->decode_coding_system)); | 7217 | (p, raw_text_coding_system (p->decode_coding_system)); |
| @@ -7235,14 +7225,11 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p, | |||
| 7235 | doc: /* Return t if a multibyte string is given to PROCESS's filter.*/) | 7225 | doc: /* Return t if a multibyte string is given to PROCESS's filter.*/) |
| 7236 | (Lisp_Object process) | 7226 | (Lisp_Object process) |
| 7237 | { | 7227 | { |
| 7238 | register struct Lisp_Process *p; | ||
| 7239 | struct coding_system *coding; | ||
| 7240 | |||
| 7241 | CHECK_PROCESS (process); | 7228 | CHECK_PROCESS (process); |
| 7242 | p = XPROCESS (process); | 7229 | struct Lisp_Process *p = XPROCESS (process); |
| 7243 | if (p->infd < 0) | 7230 | if (p->infd < 0) |
| 7244 | return Qnil; | 7231 | return Qnil; |
| 7245 | coding = proc_decode_coding_system[p->infd]; | 7232 | struct coding_system *coding = proc_decode_coding_system[p->infd]; |
| 7246 | return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt); | 7233 | return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt); |
| 7247 | } | 7234 | } |
| 7248 | 7235 | ||