Mercurial > hg > xemacs-beta
diff src/process-unix.c @ 5814:a216b3c2b09e
Add TLS support. See xemacs-patches message with ID
<CAHCOHQk6FNm2xf=XiGEpPq43+7WOzNZ=SuD9V79o3wb9WVCTrQ@mail.gmail.com>.
author | Jerry James <james@xemacs.org> |
---|---|
date | Tue, 07 Oct 2014 21:16:10 -0600 |
parents | 56144c8593a8 |
children | 08cfc8f77fb6 4949ccab25f1 |
line wrap: on
line diff
--- a/src/process-unix.c Thu Oct 02 10:19:00 2014 +0200 +++ b/src/process-unix.c Tue Oct 07 21:16:10 2014 -0600 @@ -43,6 +43,7 @@ #include "sysdep.h" #include "window.h" #include "file-coding.h" +#include "tls.h" #include <setjmp.h> #include "sysdir.h" @@ -1857,10 +1858,12 @@ static void unix_open_network_stream (Lisp_Object name, Lisp_Object host, Lisp_Object service, Lisp_Object protocol, - void **vinfd, void **voutfd) + void **vinfd, void **voutfd, Boolint tls) { EMACS_INT inch; EMACS_INT outch; + tls_state_t *tls_state = NULL; + Extbyte *ext_host = NULL; volatile int s = -1; volatile int port; volatile int retry = 0; @@ -1869,6 +1872,7 @@ int retval; CHECK_STRING (host); + ext_host = LISP_STRING_TO_EXTERNAL (host, Qunix_host_name_encoding); if (!EQ (protocol, Qtcp) && !EQ (protocol, Qudp)) invalid_constant ("Unsupported protocol", protocol); @@ -1879,7 +1883,6 @@ struct addrinfo hints, *res; struct addrinfo * volatile lres; Extbyte *portstring; - Extbyte *ext_host; Extbyte portbuf[128]; /* * Caution: service can either be a string or int. @@ -1907,7 +1910,6 @@ else /* EQ (protocol, Qudp) */ hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = 0; - ext_host = LISP_STRING_TO_EXTERNAL (host, Qunix_host_name_encoding); retval = getaddrinfo (ext_host, portstring, &hints, &res); if (retval != 0) { @@ -1960,16 +1962,19 @@ int family = address.sin_family; #endif - if (EQ (protocol, Qtcp)) - s = socket (family, SOCK_STREAM, 0); - else /* EQ (protocol, Qudp) */ - s = socket (family, SOCK_DGRAM, 0); + if (!tls || TLS_SETUP_SOCK) + { + if (EQ (protocol, Qtcp)) + s = socket (family, SOCK_STREAM, 0); + else /* EQ (protocol, Qudp) */ + s = socket (family, SOCK_DGRAM, 0); - if (s < 0) - { - xerrno = errno; - failed_connect = 0; - continue; + if (s < 0) + { + xerrno = errno; + failed_connect = 0; + continue; + } } loop: @@ -1988,10 +1993,20 @@ can_break_system_calls = 1; #ifdef USE_GETADDRINFO - retval = connect (s, lres->ai_addr, lres->ai_addrlen); + retval = (!tls || TLS_SETUP_SOCK) + ? connect (s, lres->ai_addr, lres->ai_addrlen) + : 0; #else - retval = connect (s, (struct sockaddr *) &address, sizeof (address)); + retval = (!tls || TLS_SETUP_SOCK) + ? connect (s, (struct sockaddr *) &address, sizeof (address)) + : 0; #endif + if (retval == 0 && tls) + { + tls_state = tls_open (s, ext_host); + retval = (tls_state == NULL) ? -1 : 0; + } + can_break_system_calls = 0; if (retval == -1 && errno != EISCONN) { @@ -2020,8 +2035,11 @@ } failed_connect = 1; - retry_close (s); - s = -1; + if (!tls || TLS_SETUP_SOCK) + { + retry_close (s); + s = -1; + } continue; } @@ -2052,7 +2070,7 @@ freeaddrinfo (res); #endif - if (s < 0) + if ((!tls && s < 0) || (tls && tls_state == NULL)) { errno = xerrno; @@ -2064,6 +2082,14 @@ } } + if (tls) + { + set_socket_nonblocking_maybe (tls_get_fd (tls_state), port, "tcp"); + *vinfd = (void *) tls_state; + *voutfd = (void *) tls_state; + return; + } + inch = s; outch = dup (s); if (outch < 0)