Revision: 75850
          http://sourceforge.net/p/brlcad/code/75850
Author:   starseeker
Date:     2020-05-20 20:02:23 +0000 (Wed, 20 May 2020)
Log Message:
-----------
Adjustments to pkg test client and server - make server listening non-blocking, 
and time out both client and server after 1 second if communications can't be 
established.

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

Modified: brlcad/trunk/regress/pkg/regress_pkg_client.cpp
===================================================================
--- brlcad/trunk/regress/pkg/regress_pkg_client.cpp     2020-05-20 18:41:04 UTC 
(rev 75849)
+++ brlcad/trunk/regress/pkg/regress_pkg_client.cpp     2020-05-20 20:02:23 UTC 
(rev 75850)
@@ -33,10 +33,12 @@
 
 /* interface headers */
 #include "bu/app.h"
+#include "bu/file.h"
+#include "bu/getopt.h"
 #include "bu/log.h"
 #include "bu/malloc.h"
-#include "bu/getopt.h"
-#include "bu/file.h"
+#include "bu/snooze.h"
+#include "bu/time.h"
 #include "bu/vls.h"
 #include "pkg.h"
 #include "regress_pkg_protocol.h"
@@ -91,10 +93,19 @@
     /* fire up the client */
     bu_log("Connecting to %s, port %d\n", server, port);
     snprintf(s_port, MAX_PORT_DIGITS, "%d", port);
+    int64_t timer = bu_gettime();
     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");
+
+       while ((bu_gettime() - timer) / 1000000.0 < 1.0) {
+           bu_snooze(10000);
+           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");
+       }
     }
     connection->pkc_switch = callbacks;
 

Modified: brlcad/trunk/regress/pkg/regress_pkg_server.cpp
===================================================================
--- brlcad/trunk/regress/pkg/regress_pkg_server.cpp     2020-05-20 18:41:04 UTC 
(rev 75849)
+++ brlcad/trunk/regress/pkg/regress_pkg_server.cpp     2020-05-20 20:02:23 UTC 
(rev 75850)
@@ -41,6 +41,7 @@
 #include "bu/getopt.h"
 #include "bu/vls.h"
 #include "bu/snooze.h"
+#include "bu/time.h"
 #include "pkg.h"
 #include "regress_pkg_protocol.h"
 
@@ -110,12 +111,17 @@
      * handshake that waits for a HELO message from the client.  if it
      * doesn't get one, the server continues to wait.
      */
+    int64_t timer = bu_gettime();
     bu_log("Listening on port %d\n", port);
     do {
-       client = pkg_getclient(netfd, callbacks, NULL, 0);
+       client = pkg_getclient(netfd, callbacks, NULL, 1);
        if (client == PKC_NULL) {
+           if ((bu_gettime() - timer) / 1000000.0 > 1.0) {
+               bu_log("Connection inactive for > 1 second, quitting.\n");
+               bu_exit(1, "Timeout - inactive");
+           }
            bu_log("Connection seems to be busy, waiting...\n");
-           bu_snooze(BU_SEC2USEC(10));
+           bu_snooze(100000);
            continue;
        } else if (client == PKC_ERROR) {
            pkg_close(client);
@@ -124,6 +130,9 @@
            continue;
        }
 
+       // Something happened - reset idle timer
+       timer = bu_gettime();
+
        /* got a connection, process it */
        msgbuffer = pkg_bwaitfor (MSG_HELO, client);
        if (msgbuffer == NULL) {

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