]> git.openfabrics.org - ~ardavis/dapl.git/commitdiff
dtestcm: add client retry, give server time to queue up all listens
authorAmir Hanania <amir.hanania@intel.com>
Tue, 29 Nov 2016 23:48:58 +0000 (15:48 -0800)
committerArlin Davis <arlin.r.davis@intel.com>
Tue, 29 Nov 2016 23:48:58 +0000 (15:48 -0800)
From: Amir Hanania <amir.hanania@intel.com>

Signed-off-by: Amir Hanania <amir.hanania@intel.com>
Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
test/dtest/dtestcm.c

index 93ea48c5dd27b81b3b147294ed6539eaf2959c7b..e08dc3fff2b46806e1db1c3dc3bf2ecf06a519d8 100644 (file)
@@ -177,7 +177,7 @@ static DAT_RETURN destroy_events(void);
 #define CONN_PORT 15828
 #define CONN_MSG_SIZE 128
 #define CONN_MSG_FMT "%04hx:%08x:%08x:%08x:%s"
-
+#define CONN_MAX_RETRY 10
 #define LOGPRINTF if (verbose) printf
 
 static void flush_evds(void)
@@ -223,7 +223,7 @@ static int conn_client_connect(const char *servername, int port)
                .ai_socktype = SOCK_STREAM
        };
        char *service;
-       int n;
+       int n, retry;
        int sockfd = -1;
 
        if (asprintf(&service, "%d", port) < 0)
@@ -237,14 +237,20 @@ static int conn_client_connect(const char *servername, int port)
                return n;
        }
 
-       for (t = res; t; t = t->ai_next) {
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
-               if (sockfd >= 0) {
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))
-                               break;
-                       close(sockfd);
-                       sockfd = -1;
+       for (retry = CONN_MAX_RETRY; retry > 0; retry--) {
+               for (t = res; t; t = t->ai_next) {
+                       sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
+                       if (sockfd >= 0) {
+                               if (!connect(sockfd, t->ai_addr, t->ai_addrlen))
+                                       break;
+                               close(sockfd);
+                               sockfd = -1;
+                       }
                }
+               if (sockfd < 0)
+                       sleep (1);
+               else
+                       break;
        }
 
        freeaddrinfo(res);