From 6051dec4a1ae6decd9123a3310098baf43f45c49 Mon Sep 17 00:00:00 2001 From: Mihai Moldovan <ïonic@ionic.de> Date: Fri, 17 Jun 2016 01:45:40 +0000 Subject: {nx-X11/programs/Xserver/hw/nxagent/{{Args,Handlers,Image,Options}.c,Options.h},nxcomp/{Loop,Misc}.cpp}: add configurable sleep delay if session is suspended. --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 38 ++++++++++++++++++++++ nx-X11/programs/Xserver/hw/nxagent/Handlers.c | 46 +++++++++++++++++++-------- nx-X11/programs/Xserver/hw/nxagent/Image.c | 14 ++------ nx-X11/programs/Xserver/hw/nxagent/Options.c | 2 ++ nx-X11/programs/Xserver/hw/nxagent/Options.h | 7 ++++ 5 files changed, 83 insertions(+), 24 deletions(-) (limited to 'nx-X11/programs') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index 59d3deb63..2590dd6c3 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -1339,6 +1339,44 @@ static void nxagentParseOptions(char *name, char *value) nxagentChangeOption(Clipboard, ClipboardBoth); } } + else if (!strcmp(name, "sleep")) + { + long sleep_parse = 0; + + errno = 0; + sleep_parse = strtol(value, NULL, 10); + + if ((errno) && (0 == sleep_parse)) + { + fprintf(stderr, "nxagentParseOptions: Unable to convert value [%s] of option [%s]. " + "Ignoring option.\n", + validateString(value), validateString(name)); + + return; + } + + if ((long) UINT_MAX < sleep_parse) + { + sleep_parse = UINT_MAX; + + fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of option [%s] " + "out of range, clamped to [%u].\n", + validateString(value), validateString(name), sleep_parse); + } + + if (0 > sleep_parse) + { + sleep_parse = 0; + + fprintf(stderr, "nxagentParseOptions: Warning: value [%s] of option [%s] " + "out of range, clamped to [%u].\n", + validateString(value), validateString(name), sleep_parse); + } + + nxagentChangeOption(SleepTime, sleep_parse); + + return; + } else { #ifdef DEBUG diff --git a/nx-X11/programs/Xserver/hw/nxagent/Handlers.c b/nx-X11/programs/Xserver/hw/nxagent/Handlers.c index 1beff090b..ba4034255 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Handlers.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Handlers.c @@ -62,14 +62,6 @@ #define FLUSH_AFTER_MULTIPLE_READS -/* - * Introduce a small delay after each - * loop if the session is down. The - * value is in milliseconds. - */ - -#define LOOP_DELAY_IF_DOWN 50 - /* * The soft limit should roughly match * the size of the Xlib I/O buffer. @@ -246,12 +238,21 @@ void nxagentBlockHandler(void * data, struct timeval **timeout, void * mask) * not connected to a valid display. */ - if (NXDisplayError(nxagentDisplay) == 1 && nxagentShadowCounter == 0) + if (NXDisplayError(nxagentDisplay) == 1 && nxagentShadowCounter == 0 && nxagentOption(SleepTime) > 0) { - usleep(LOOP_DELAY_IF_DOWN * 1000); +#ifdef TEST + fprintf(stderr, "nxagentBlockHandler: sleeping for %d milliseconds for slowdown.\n", + nxagentOption(SleepTime)); +#endif + usleep(nxagentOption(SleepTime) * 1000); now = GetTimeInMillis(); } +#ifdef TEST + else if (0 == nxagentOption(SleepTime)) { + fprintf(stderr, "nxagentBlockHandler: not sleeping for slowdown.\n"); + } +#endif /* * Update the shadow display. This is @@ -743,9 +744,17 @@ void nxagentShadowBlockHandler(void * data, struct timeval **timeout, void * mas nxagentHandleConnectionChanges(); } - if (nxagentSessionState == SESSION_DOWN) + if (nxagentSessionState == SESSION_DOWN && nxagentOption(SleepTime) > 0) { - usleep(50 * 1000); +#ifdef TEST + fprintf(stderr, "nxagentBlockHandler: sleeping for %d milliseconds for slowdown.\n", + nxagentOption(SleepTime)); +#endif + usleep(nxagentOption(SleepTime) * 1000); + } +#ifdef TEST + else if (0 == nxagentOption(SleepTime)) { + fprintf(stderr, "nxagentBlockHandler: not sleeping for slowdown.\n"); } #ifndef __CYGWIN32__ @@ -826,7 +835,18 @@ FIXME: Must queue multiple writes and handle #ifdef __CYGWIN32__ - usleep(50 * 1000); + if (nxagentOption(SleepTime) > 0) { +#ifdef TEST + fprintf(stderr, "nxagentShadowBlockHandler: sleeping for %d milliseconds for slowdown.\n", + nxagentOption(SleepTime)); +#endif + usleep(nxagentOption(SleepTime) * 1000); + } +#ifdef TEST + else if (0 == nxagentOption(SleepTime)) { + fprintf(stderr, "nxagentShadowBlockHandler: not sleeping for slowdown.\n"); + } +#endif (*timeout) -> tv_sec = 0; (*timeout) -> tv_usec = 50 * 1000; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Image.c b/nx-X11/programs/Xserver/hw/nxagent/Image.c index 6a7d46c35..a158a11db 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Image.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Image.c @@ -68,15 +68,6 @@ #define IMAGE_UNIQUE_RATIO 10 -/* - * Introduce a small delay after each image - * operation if the session is down. Value - * is in microseconds and is multiplied by - * the image data size in kilobytes. - */ - -#define IMAGE_DELAY_IF_DOWN 250 - /* * Preferred pack and split parameters we * got from the NX transport. @@ -521,11 +512,12 @@ void nxagentPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, length = nxagentImageLength(dstWidth, dstHeight, format, leftPad, depth); if (nxagentShadowCounter == 0 && - NXDisplayError(nxagentDisplay) == 1) + NXDisplayError(nxagentDisplay) == 1 && + nxagentOption(SleepTime) > 0) { int us; - us = IMAGE_DELAY_IF_DOWN * (length / 1024); + us = nxagentOption(SleepTime) * 4 * (length / 1024); us = (us < 10000 ? 10000 : (us > 1000000 ? 1000000 : us)); diff --git a/nx-X11/programs/Xserver/hw/nxagent/Options.c b/nx-X11/programs/Xserver/hw/nxagent/Options.c index dbe200273..8a3275c64 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Options.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Options.c @@ -156,6 +156,8 @@ void nxagentInitOptions() nxagentOptions.ImageRateLimit = 0; nxagentOptions.Xinerama = 0; + + nxagentOptions.SleepTime = DEFAULT_SLEEP_TIME; } /* diff --git a/nx-X11/programs/Xserver/hw/nxagent/Options.h b/nx-X11/programs/Xserver/hw/nxagent/Options.h index 5bf1597d5..02b886242 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Options.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Options.h @@ -28,6 +28,7 @@ #define UNDEFINED -1 #define COPY_UNLIMITED -1 +#define DEFAULT_SLEEP_TIME 50 extern unsigned int nxagentPrintGeometryFlags; @@ -399,6 +400,12 @@ typedef struct _AgentOptions int Xinerama; + /* + * Sleep delay in microseconds. + */ + + unsigned int SleepTime; + } AgentOptionsRec; typedef AgentOptionsRec *AgentOptionsPtr; -- cgit v1.2.3