From 41b44a67088179ec6be967bd2b5f729309845f1f Mon Sep 17 00:00:00 2001 From: Florian Rhiem Date: Wed, 13 Feb 2019 16:39:43 +0100 Subject: [PATCH] Improved timeout logic in quartzplugin When GKSTerm is in the background, its response time can vary wildly and it can exceed the current 50ms timeout. The changes in this commit reduce the time between checking for a response from 10ms to 1ms and increase the timeout for the GKSTerm 'is running' response from 50ms to 500ms after the first succesful 'is running' check. --- lib/gks/plugin/quartzplugin.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/gks/plugin/quartzplugin.m b/lib/gks/plugin/quartzplugin.m index 6be94651d..add57c2ca 100644 --- a/lib/gks/plugin/quartzplugin.m +++ b/lib/gks/plugin/quartzplugin.m @@ -37,8 +37,10 @@ DLLEXPORT void gks_quartzplugin(int fctid, int dx, int dy, int dimx, int *i_arr, #endif #define GKSTERM_DEFAULT_TIMEOUT 5000 + +static int gksterm_has_run_before = 0; /* Timeout for is running is short so that GKSTerm will be started quickly. */ -#define GKSTERM_IS_RUNNING_TIMEOUT 50 +#define GKSTERM_IS_RUNNING_TIMEOUT (gksterm_has_run_before ? 500 : 50) static gks_state_list_t *gkss; @@ -93,7 +95,7 @@ static void gksterm_communicate(const char *request, size_t request_len, int tim } if (rc == -1 && errno == EAGAIN) { - usleep(10000); + usleep(1000); } rc = zmq_msg_send(&message, socket, ZMQ_DONTWAIT); } @@ -115,7 +117,7 @@ static void gksterm_communicate(const char *request, size_t request_len, int tim } if (rc == -1 && errno == EAGAIN) { - usleep(10000); + usleep(1000); } rc = zmq_msg_recv(&message, socket, ZMQ_DONTWAIT); } @@ -148,6 +150,7 @@ static bool gksterm_is_running() { return false; } + gksterm_has_run_before = 1; return true; }