summary refs log tree commit diff
path: root/nis/nis_findserv.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-12-13 03:40:19 +0000
committerUlrich Drepper <drepper@redhat.com>2001-12-13 03:40:19 +0000
commit495818ceb43678769e35c5ec0a0dc2a27eb62111 (patch)
tree5408ca4ddda3557ce2ff757a4b12617bd25f08fa /nis/nis_findserv.c
parent122484e4cd78c0748c8f90e5ebeee9c9fa28ebf4 (diff)
downloadglibc-495818ceb43678769e35c5ec0a0dc2a27eb62111.tar.gz
glibc-495818ceb43678769e35c5ec0a0dc2a27eb62111.tar.xz
glibc-495818ceb43678769e35c5ec0a0dc2a27eb62111.zip
Update.
2001-12-12  Ulrich Drepper  <drepper@redhat.com>

	* nis/nis_findserv.c (__nis_findfastest_with_timeout): Mostly the code
	from __nis_findfastest.  Take timeout value from parameter.
	(__nis_findfastest): Call __nis_findfastest_with_timeout repeatedly.
	* nis/nis_intern.h: Define parameters controlling __nis_findfastest.
	Patch by Alexander Belopolsky <alexb@rentec.com>.

	* sysdeps/arm/dl-machine.h (elf_machine_rela): Fix typo in last patch.
Diffstat (limited to 'nis/nis_findserv.c')
-rw-r--r--nis/nis_findserv.c85
1 files changed, 43 insertions, 42 deletions
diff --git a/nis/nis_findserv.c b/nis/nis_findserv.c
index a82c1154ab..472a2bf529 100644
--- a/nis/nis_findserv.c
+++ b/nis/nis_findserv.c
@@ -110,28 +110,12 @@ struct findserv_req
   u_int server_ep;
 };
 
-long
-__nis_findfastest (dir_binding *bind)
-{
-#if 0
-  unsigned long i, j;
 
-  for (i = 0; i < bind->server_len; i++)
-    for (j = 0; j < bind->server_val[i].ep.ep_len; ++j)
-      if (strcmp (bind->server_val[i].ep.ep_val[j].family, "inet") == 0)
-	if ((bind->server_val[i].ep.ep_val[j].proto == NULL) ||
-	    (bind->server_val[i].ep.ep_val[j].proto[0] ==  '-') ||
-	    (bind->server_val[i].ep.ep_val[j].proto[0] == '\0'))
-	  {
-	    bind->server_used = i;
-	    bind->current_ep = j;
-	    return 1;
-	  }
-
-  return 0;
-#else
-  const struct timeval TIMEOUT50 = {5, 0};
-  const struct timeval TIMEOUT00 = {0, 0};
+static long int
+__nis_findfastest_with_timeout (dir_binding *bind,
+				const struct timeval *timeout)
+{
+  static const struct timeval TIMEOUT00 = { 0, 0 };
   struct findserv_req *pings;
   struct sockaddr_in sin, saved_sin;
   int found = -1;
@@ -201,7 +185,7 @@ __nis_findfastest (dir_binding *bind)
 
   /* Create RPC handle */
   sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-  clnt = clntudp_create (&saved_sin, NIS_PROG, NIS_VERSION, TIMEOUT50, &sock);
+  clnt = clntudp_create (&saved_sin, NIS_PROG, NIS_VERSION, *timeout, &sock);
   if (clnt == NULL)
     {
       close (sock);
@@ -211,9 +195,7 @@ __nis_findfastest (dir_binding *bind)
   auth_destroy (clnt->cl_auth);
   clnt->cl_auth = authunix_create_default ();
   cu = (struct cu_data *) clnt->cl_private;
-  clnt_control (clnt, CLSET_TIMEOUT, (char *) &TIMEOUT00);
   ioctl (sock, FIONBIO, &dontblock);
-
   /* Send to all servers the NULLPROC */
   for (i = 0; i < pings_count; ++i)
     {
@@ -222,30 +204,31 @@ __nis_findfastest (dir_binding *bind)
       memcpy ((char *) &cu->cu_raddr, (char *) &pings[i].sin,
 	      sizeof (struct sockaddr_in));
       /* Transmit to NULLPROC, return immediately. */
-      clnt_call (clnt, NULLPROC, 
+      clnt_call (clnt, NULLPROC,
 		 (xdrproc_t) xdr_void, (caddr_t) 0,
 		 (xdrproc_t) xdr_void, (caddr_t) 0, TIMEOUT00);
     }
-  
-  /* Receive reply from NULLPROC asynchronously */
-  while (RPC_SUCCESS == clnt_call (clnt, NULLPROC,
-				   (xdrproc_t) NULL, (caddr_t) 0,
-				   (xdrproc_t) xdr_void, (caddr_t) 0,
-				   TIMEOUT00))
-    {
+
+  while (found == -1) {
+    /* Receive reply from NULLPROC asynchronously. Note null inproc. */
+    int rc = clnt_call (clnt, NULLPROC,
+			(xdrproc_t) NULL, (caddr_t) 0,
+			(xdrproc_t) xdr_void, (caddr_t) 0,
+			*timeout);
+    if (RPC_SUCCESS == rc) {
       fastest = *((u_int32_t *) (cu->cu_inbuf)) - xid_seed;
       if (fastest < pings_count) {
-	break;
+	bind->server_used = pings[fastest].server_nr;
+	bind->current_ep = pings[fastest].server_ep;
+	found = 1;
       }
+    } else {
+      /*      clnt_perror(clnt, "__nis_findfastest"); */
+      break;
     }
-  
-  if (fastest < pings_count)
-    {
-      bind->server_used = pings[fastest].server_nr;
-      bind->current_ep = pings[fastest].server_ep;
-      found = 1;
-    }
-  
+  }
+
+
   auth_destroy (clnt->cl_auth);
   clnt_destroy (clnt);
   close (sock);
@@ -253,5 +236,23 @@ __nis_findfastest (dir_binding *bind)
   free (pings);
 
   return found;
-#endif
+}
+
+
+long int
+__nis_findfastest (dir_binding *bind)
+{
+  struct timeval timeout = { __NIS_PING_TIMEOUT_START, 0 };
+  long int found = -1;
+  long int retry = __NIS_PING_RETRY + 1;
+
+  while (retry--)
+    {
+      found = __nis_findfastest_with_timeout (bind, &timeout);
+      if (found != -1)
+	break;
+      timeout.tv_sec += __NIS_PING_TIMEOUT_INCREMENT;
+    }
+
+  return found;
 }