From c2e124a95b5f1dcb7d8e7f2ea1549d30fd54bc17 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Thu, 4 Nov 2010 15:53:28 -0400 Subject: [PATCH 1/3] Backport 2010-03-25T08:48:52Z!mituharu@math.s.chiba-u.ac.jp from trunk --- src/ChangeLog | 5 +++++ src/process.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 077385d6f6c..f3bbfe05dac 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-03-25 Helmut Eller + + * process.c (Fmake_network_process): Call `select' for interrupted + `connect' rather than creating new socket (Bug#5173). + 2010-11-04 Kenichi Handa * font.c (font_delete_unmatched): Check Vface_ignored_fonts. diff --git a/src/process.c b/src/process.c index 567300e2f64..77490adaa79 100644 --- a/src/process.c +++ b/src/process.c @@ -3573,8 +3573,6 @@ usage: (make-network-process &rest ARGS) */) { int optn, optbits; - retry_connect: - s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol); if (s < 0) { @@ -3691,6 +3689,38 @@ usage: (make-network-process &rest ARGS) */) #endif #endif #endif + if (xerrno == EINTR) + { + /* Unlike most other syscalls connect() cannot be called + again. (That would return EALREADY.) The proper way to + wait for completion is select(). */ + int sc; + SELECT_TYPE fdset; + retry_select: + FD_ZERO (&fdset); + FD_SET (s, &fdset); + QUIT; + sc = select (s + 1, (SELECT_TYPE *)0, &fdset, (SELECT_TYPE *)0, + (EMACS_TIME *)0); + if (sc == -1) + { + if (errno == EINTR) + goto retry_select; + else + report_file_error ("select failed", Qnil); + } + eassert (sc > 0); + { + int len = sizeof xerrno; + eassert (FD_ISSET (s, &fdset)); + if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) == -1) + report_file_error ("getsockopt failed", Qnil); + if (xerrno != 0) + errno = xerrno, report_file_error ("error during connect", Qnil); + else + break; + } + } immediate_quit = 0; @@ -3698,9 +3728,6 @@ usage: (make-network-process &rest ARGS) */) specpdl_ptr = specpdl + count1; emacs_close (s); s = -1; - - if (xerrno == EINTR) - goto retry_connect; } if (s >= 0) From bd80a88673b755ccf9d850b907e65fec5308e6b4 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Thu, 4 Nov 2010 15:54:14 -0400 Subject: [PATCH 2/3] Backport 2010-03-25T08:56:15Z!mituharu@math.s.chiba-u.ac.jp from trunk --- src/ChangeLog | 5 +++++ src/process.c | 14 -------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f3bbfe05dac..1420114ea5b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-03-25 YAMAMOTO Mitsuharu + + * process.c (Fmake_network_process): Don't call turn_on_atimers around + `connect' (Bug#5723). + 2010-03-25 Helmut Eller * process.c (Fmake_network_process): Call `select' for interrupted diff --git a/src/process.c b/src/process.c index 77490adaa79..e3622c79386 100644 --- a/src/process.c +++ b/src/process.c @@ -3654,23 +3654,9 @@ usage: (make-network-process &rest ARGS) */) immediate_quit = 1; QUIT; - /* This turns off all alarm-based interrupts; the - bind_polling_period call above doesn't always turn all the - short-interval ones off, especially if interrupt_input is - set. - - It'd be nice to be able to control the connect timeout - though. Would non-blocking connect calls be portable? - - This used to be conditioned by HAVE_GETADDRINFO. Why? */ - - turn_on_atimers (0); - ret = connect (s, lres->ai_addr, lres->ai_addrlen); xerrno = errno; - turn_on_atimers (1); - if (ret == 0 || xerrno == EISCONN) { /* The unwind-protect will be discarded afterwards. From 184765cc7a4f8c0ff5e7522ee4e1584b441b742f Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Thu, 4 Nov 2010 15:54:28 -0400 Subject: [PATCH 3/3] Backport 2010-03-27T00:45:32Z!cyd@stupidchicken.com from trunk --- src/ChangeLog | 5 +++++ src/process.c | 35 ++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1420114ea5b..16703ef5201 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-03-27 Chong Yidong + + * process.c (Fmake_network_process): Don't apply Bug#5173 fix for + Windows. + 2010-03-25 YAMAMOTO Mitsuharu * process.c (Fmake_network_process): Don't call turn_on_atimers around diff --git a/src/process.c b/src/process.c index e3622c79386..df30adcf0be 100644 --- a/src/process.c +++ b/src/process.c @@ -3573,6 +3573,8 @@ usage: (make-network-process &rest ARGS) */) { int optn, optbits; + retry_connect: + s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol); if (s < 0) { @@ -3675,12 +3677,14 @@ usage: (make-network-process &rest ARGS) */) #endif #endif #endif + +#ifndef WINDOWSNT if (xerrno == EINTR) { /* Unlike most other syscalls connect() cannot be called again. (That would return EALREADY.) The proper way to wait for completion is select(). */ - int sc; + int sc, len; SELECT_TYPE fdset; retry_select: FD_ZERO (&fdset); @@ -3690,23 +3694,23 @@ usage: (make-network-process &rest ARGS) */) (EMACS_TIME *)0); if (sc == -1) { - if (errno == EINTR) + if (errno == EINTR) goto retry_select; - else + else report_file_error ("select failed", Qnil); } eassert (sc > 0); - { - int len = sizeof xerrno; - eassert (FD_ISSET (s, &fdset)); - if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) == -1) - report_file_error ("getsockopt failed", Qnil); - if (xerrno != 0) - errno = xerrno, report_file_error ("error during connect", Qnil); - else - break; - } + + len = sizeof xerrno; + eassert (FD_ISSET (s, &fdset)); + if (getsockopt (s, SOL_SOCKET, SO_ERROR, &xerrno, &len) == -1) + report_file_error ("getsockopt failed", Qnil); + if (xerrno) + errno = xerrno, report_file_error ("error during connect", Qnil); + else + break; } +#endif /* !WINDOWSNT */ immediate_quit = 0; @@ -3714,6 +3718,11 @@ usage: (make-network-process &rest ARGS) */) specpdl_ptr = specpdl + count1; emacs_close (s); s = -1; + +#ifdef WINDOWSNT + if (xerrno == EINTR) + goto retry_connect; +#endif } if (s >= 0)