Revision: 75854
          http://sourceforge.net/p/brlcad/code/75854
Author:   brlcad
Date:     2020-05-20 21:09:16 +0000 (Wed, 20 May 2020)
Log Message:
-----------
simplify the looping.  wait for up to 5 secs, checking 10 times.

Modified Paths:
--------------
    brlcad/trunk/regress/pkg/CMakeLists.txt
    brlcad/trunk/regress/pkg/regress_pkg_client.cpp
    brlcad/trunk/regress/pkg/regress_pkg_server.cpp

Modified: brlcad/trunk/regress/pkg/CMakeLists.txt
===================================================================
--- brlcad/trunk/regress/pkg/CMakeLists.txt     2020-05-20 20:53:01 UTC (rev 
75853)
+++ brlcad/trunk/regress/pkg/CMakeLists.txt     2020-05-20 21:09:16 UTC (rev 
75854)
@@ -30,6 +30,7 @@
   add_custom_target(regress-pkg COMMAND ${CMAKE_CTEST_COMMAND} -R ^regress-pkg 
--output-on-failure)
 endif (CMAKE_CONFIGURATION_TYPES)
 add_dependencies(regress-pkg libbu libpkg)
+
 set_target_properties(regress-pkg PROPERTIES FOLDER "BRL-CAD Regression Tests")
 set_target_properties(regress-pkg PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
 

Modified: brlcad/trunk/regress/pkg/regress_pkg_client.cpp
===================================================================
--- brlcad/trunk/regress/pkg/regress_pkg_client.cpp     2020-05-20 20:53:01 UTC 
(rev 75853)
+++ brlcad/trunk/regress/pkg/regress_pkg_client.cpp     2020-05-20 21:09:16 UTC 
(rev 75854)
@@ -72,7 +72,7 @@
     int port = 2000;
     const char *server = "127.0.0.1";
     struct bu_vls all_msgs = BU_VLS_INIT_ZERO;
-    struct pkg_conn *connection;
+    struct pkg_conn *connection = PKC_ERROR;
     char s_port[MAX_PORT_DIGITS + 1] = {0};
     long bytes = 0;
     int pkg_result = 0;
@@ -93,21 +93,21 @@
     /* fire up the client */
     bu_log("Connecting to %s, port %d\n", server, port);
     snprintf(s_port, MAX_PORT_DIGITS, "%d", port);
+
+    int wait_time = 5;
     int64_t timer = bu_gettime();
+
     connection = pkg_open(server, s_port, "tcp", NULL, NULL, NULL, NULL);
+    while (connection == PKC_ERROR && (bu_gettime() - timer) < 
BU_SEC2USEC(wait_time)) {
+       bu_snooze(BU_SEC2USEC((double)wait_time / 10.0));
+       connection = pkg_open(server, s_port, "tcp", NULL, NULL, NULL, NULL);
+    }
+
     if (connection == PKC_ERROR) {
+       bu_log("Connection to %s, port %d, failed.\n", server, port);
+       bu_exit(-1, "ERROR: tried for 1 second - unable to open a connection to 
the server\n");
+    }
 
-       while ((bu_gettime() - timer) < BU_SEC2USEC(10.0)) {
-           // To avoid constant polling, sleep for a short interval
-           bu_snooze(BU_SEC2USEC(0.1));
-           connection = pkg_open(server, s_port, "tcp", NULL, NULL, NULL, 
NULL);
-       }
-
-       if (connection == PKC_ERROR) {
-           bu_log("Connection to %s, port %d, failed.\n", server, port);
-           bu_exit(-1, "ERROR: unable to open a connection to the server\n");
-       }
-    }
     connection->pkc_switch = callbacks;
 
     /* let the server know we're cool. */

Modified: brlcad/trunk/regress/pkg/regress_pkg_server.cpp
===================================================================
--- brlcad/trunk/regress/pkg/regress_pkg_server.cpp     2020-05-20 20:53:01 UTC 
(rev 75853)
+++ brlcad/trunk/regress/pkg/regress_pkg_server.cpp     2020-05-20 21:09:16 UTC 
(rev 75854)
@@ -116,14 +116,13 @@
     do {
        client = pkg_getclient(netfd, callbacks, NULL, 1);
        if (client == PKC_NULL) {
-           // If we've been trying for more than 10 seconds, something
-           // went wrong with the test.
-           if ((bu_gettime() - timer) > BU_SEC2USEC(10.0)) {
-               bu_log("Connection inactive for >10 seconds, quitting.\n");
+           int wait_time = 5;
+           if ((bu_gettime() - timer) > BU_SEC2USEC(wait_time)) {
+               bu_log("Connection inactive for > %d seconds, quitting.\n", 
wait_time);
                bu_exit(1, "Timeout - inactive");
            }
            bu_log("No client input available, waiting...\n");
-           bu_snooze(BU_SEC2USEC(0.1));
+           bu_snooze(BU_SEC2USEC((double)wait_time / 10.0));
            continue;
        } else if (client == PKC_ERROR) {
            pkg_close(client);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to