comparison src/process.c @ 25262:ccf83ed7326a

(Fopen_network_stream): Fix previous change.
author Karl Heuer <kwzh@gnu.org>
date Sat, 14 Aug 1999 04:36:10 +0000
parents f0fc8443bdbb
children 5db69f7aadca
comparison
equal deleted inserted replaced
25261:89be69860eeb 25262:ccf83ed7326a
1822 struct hostent *host_info_ptr, host_info; 1822 struct hostent *host_info_ptr, host_info;
1823 char *(addr_list[2]); 1823 char *(addr_list[2]);
1824 IN_ADDR numeric_addr; 1824 IN_ADDR numeric_addr;
1825 struct hostent host_info_fixed; 1825 struct hostent host_info_fixed;
1826 int port; 1826 int port;
1827 #else /* ! HAVE_GETADDRINFO */ 1827 #else /* HAVE_GETADDRINFO */
1828 struct addrinfo hints, *res, *lres; 1828 struct addrinfo hints, *res, *lres;
1829 int ret = 0; 1829 int ret = 0;
1830 int xerrno = 0; 1830 int xerrno = 0;
1831 char *portstring, portbuf [128]; 1831 char *portstring, portbuf[128];
1832 #endif /* ! HAVE_GETADDRINFO */ 1832 #endif /* HAVE_GETADDRINFO */
1833 int s, outch, inch; 1833 int s = -1, outch, inch;
1834 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1834 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
1835 int retry = 0; 1835 int retry = 0;
1836 int count = specpdl_ptr - specpdl; 1836 int count = specpdl_ptr - specpdl;
1837 1837
1838 #ifdef WINDOWSNT 1838 #ifdef WINDOWSNT
1884 #ifdef HAVE_GETADDRINFO 1884 #ifdef HAVE_GETADDRINFO
1885 { 1885 {
1886 immediate_quit = 1; 1886 immediate_quit = 1;
1887 QUIT; 1887 QUIT;
1888 memset (&hints, 0, sizeof (hints)); 1888 memset (&hints, 0, sizeof (hints));
1889 hints.ai_flags = AI_NUMERICHOST; 1889 hints.ai_flags = 0;
1890 hints.ai_family = AF_UNSPEC; 1890 hints.ai_family = AF_UNSPEC;
1891 hints.ai_socktype = SOCK_STREAM; 1891 hints.ai_socktype = SOCK_STREAM;
1892 hints.ai_protocol = 0; 1892 hints.ai_protocol = 0;
1893 ret = getaddrinfo (XSTRING (host)->data, portstring, &hints, &res); 1893 ret = getaddrinfo (XSTRING (host)->data, portstring, &hints, &res);
1894 if (!ret) /* numeric */
1895 {
1896 freeaddrinfo (res);
1897 hints.ai_flags = AI_CANONNAME;
1898 }
1899 else /* non-numeric */
1900 {
1901 hints.ai_flags = 0;
1902 }
1903 ret = getaddrinfo (XSTRING (host)->data, portstring, &hints, &res);
1904 if (ret) 1894 if (ret)
1905 { 1895 {
1906 error ("%s/%s %s", XSTRING (host)->data, portstring, 1896 error ("%s/%s %s", XSTRING (host)->data, portstring,
1907 gai_strerror (ret)); 1897 gai_strerror (ret));
1908 } 1898 }
1909 immediate_quit = 0; 1899 immediate_quit = 0;
1910 } 1900 }
1911 1901
1912 for (lres = res; lres ; lres = lres->ai_next) 1902 for (lres = res; lres; lres = lres->ai_next)
1913 { 1903 {
1914 s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol); 1904 s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol);
1915 if (s < 0) 1905 if (s < 0)
1916 report_file_error ("error creating socket", Fcons (name, Qnil)); 1906 continue;
1917 1907
1918 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR) 1908 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
1919 when connect is interrupted. So let's not let it get interrupted. 1909 when connect is interrupted. So let's not let it get interrupted.
1920 Note we do not turn off polling, because polling is only used 1910 Note we do not turn off polling, because polling is only used
1921 when not interrupt_input, and thus not normally used on the systems 1911 when not interrupt_input, and thus not normally used on the systems
1922 which have this bug. On systems which use polling, there's no way 1912 which have this bug. On systems which use polling, there's no way
1923 to quit if polling is turned off. */ 1913 to quit if polling is turned off. */
1924 if (interrupt_input) 1914 if (interrupt_input)
1925 unrequest_sigio (); 1915 unrequest_sigio ();
1926 1916
1927 loop:
1928
1929 immediate_quit = 1; 1917 immediate_quit = 1;
1930 QUIT; 1918 QUIT;
1931 1919
1932 ret = connect (s, lres->ai_addr, lres->ai_addrlen); 1920 ret = connect (s, lres->ai_addr, lres->ai_addrlen);
1933 1921 if (ret == 0)
1934 if (ret == -1 && errno != EISCONN)
1935 {
1936 xerrno = errno;
1937
1938 immediate_quit = 0;
1939
1940 if (errno == EINTR)
1941 goto loop;
1942 if (errno == EADDRINUSE && retry < 20)
1943 {
1944 /* A delay here is needed on some FreeBSD systems,
1945 and it is harmless, since this retrying takes time anyway
1946 and should be infrequent. */
1947 Fsleep_for (make_number (1), Qnil);
1948 retry++;
1949 goto loop;
1950 }
1951
1952 close (s);
1953 }
1954 if (ret == 0) /* We got a valid connect */
1955 break; 1922 break;
1956 } /* address loop */ 1923 close (s);
1924 s = -1;
1925 }
1926
1957 freeaddrinfo (res); 1927 freeaddrinfo (res);
1958 if (ret != 0) 1928 if (s < 0)
1959 { 1929 {
1960 if (interrupt_input) 1930 if (interrupt_input)
1961 request_sigio (); 1931 request_sigio ();
1962 1932
1963 errno = xerrno; 1933 errno = xerrno;