Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net do not perform sleep() every time we get ECONNR...



details:   https://anonhg.NetBSD.org/src/rev/cd9d125fe961
branches:  trunk
changeset: 482640:cd9d125fe961
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Feb 18 04:16:54 2000 +0000

description:
do not perform sleep() every time we get ECONNREFUSED.
try all the set of addresses before go to sleep() and retry.

not sure if we still need sleep() - retry logic.  why is it so persistent
in connecting?

From: SHIMIZU Ryo <ryo%misakimix.org@localhost>

diffstat:

 lib/libc/net/rcmd.c |  21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diffs (63 lines):

diff -r 93f7fecda2aa -r cd9d125fe961 lib/libc/net/rcmd.c
--- a/lib/libc/net/rcmd.c       Fri Feb 18 03:53:16 2000 +0000
+++ b/lib/libc/net/rcmd.c       Fri Feb 18 04:16:54 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rcmd.c,v 1.38 2000/01/31 10:23:03 itojun Exp $ */
+/*     $NetBSD: rcmd.c,v 1.39 2000/02/18 04:16:54 itojun Exp $ */
 
 /*
  * Copyright (c) 1997 Matthew R. Green.
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)rcmd.c     8.3 (Berkeley) 3/26/94";
 #else
-__RCSID("$NetBSD: rcmd.c,v 1.38 2000/01/31 10:23:03 itojun Exp $");
+__RCSID("$NetBSD: rcmd.c,v 1.39 2000/02/18 04:16:54 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -221,6 +221,7 @@
        int s, lport, timo;
        int pollr;
        char c;
+       int refused;
 
        _DIAGASSERT(res != NULL);
        _DIAGASSERT(ahost != NULL);
@@ -230,6 +231,7 @@
        /* fd2p may be NULL */
 
        r = res;
+       refused = 0;
        pid = getpid();
        sigemptyset(&nmask);
        sigaddset(&nmask, SIGURG);
@@ -257,12 +259,8 @@
                if (errno == EADDRINUSE) {
                        lport--;
                        continue;
-               }
-               if (errno == ECONNREFUSED && timo <= 16) {
-                       (void)sleep((unsigned int)timo);
-                       timo *= 2;
-                       continue;
-               }
+               } else if (errno == ECONNREFUSED)
+                       refused++;
                if (r->ai_next) {
                        int oerrno = errno;
                        char hbuf[NI_MAXHOST];
@@ -287,6 +285,13 @@
                        (void)fprintf(stderr, "Trying %s...\n", hbuf);
                        continue;
                }
+               if (refused && timo <= 16) {
+                       (void)sleep((unsigned int)timo);
+                       timo *= 2;
+                       r = res;
+                       refused = 0;
+                       continue;
+               }
                (void)fprintf(stderr, "%s: %s\n", res->ai_canonname,
                    strerror(errno));
                (void)sigprocmask(SIG_SETMASK, &omask, NULL);



Home | Main Index | Thread Index | Old Index