Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/lpr/common_source do not sleep on ECONNREFUSED, rat...



details:   https://anonhg.NetBSD.org/src/rev/93f7fecda2aa
branches:  trunk
changeset: 482639:93f7fecda2aa
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Feb 18 03:53:16 2000 +0000

description:
do not sleep on ECONNREFUSED, rather, try the next address first.
the behavior itself has a room for debate.  (why we retry on ECONNREFUSED?)

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

diffstat:

 usr.sbin/lpr/common_source/common.c |  25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diffs (66 lines):

diff -r 8545716100eb -r 93f7fecda2aa usr.sbin/lpr/common_source/common.c
--- a/usr.sbin/lpr/common_source/common.c       Fri Feb 18 03:46:43 2000 +0000
+++ b/usr.sbin/lpr/common_source/common.c       Fri Feb 18 03:53:16 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.17 2000/01/27 05:39:50 itojun Exp $       */
+/*     $NetBSD: common.c,v 1.18 2000/02/18 03:53:16 itojun Exp $       */
 
 /*
  * Copyright (c) 1983, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)common.c   8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: common.c,v 1.17 2000/01/27 05:39:50 itojun Exp $");
+__RCSID("$NetBSD: common.c,v 1.18 2000/02/18 03:53:16 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -132,6 +132,7 @@
        u_int timo = 1;
        int s, lport = IPPORT_RESERVED - 1;
        int error;
+       int refuse, trial;
 
        /*
         * Get the host address and port number to connect to.
@@ -148,9 +149,12 @@
        /*
         * Try connecting to the server.
         */
+retry:
        s = -1;
+       refuse = trial = 0;
        for (r = res; r; r = r->ai_next) {
-retry:
+               trial++;
+retryport:
                seteuid(euid);
                s = rresvport_af(&lport, r->ai_family);
                seteuid(uid);
@@ -163,17 +167,18 @@
                        errno = error;
                        if (errno == EADDRINUSE) {
                                lport--;
-                               goto retry;
-                       }
-                       if (errno == ECONNREFUSED && timo <= 16) {
-                               sleep(timo);
-                               timo *= 2;
-                               goto retry;
-                       }
+                               goto retryport;
+                       } else if (errno == ECONNREFUSED)
+                               refuse++;
                        continue;
                } else
                        break;
        }
+       if (s < 0 && trial == refuse && timo <= 16) {
+               sleep(timo);
+               timo *= 2;
+               goto retry;
+       }
        if (res)
                freeaddrinfo(res);
        return(s);



Home | Main Index | Thread Index | Old Index