From 91925d70d901b180fffa1f40e0afafbc4b6c560e Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 18 Jan 2020 22:32:07 +0100 Subject: Clarify use of and need for mffs vs. ffs Backport of this xorg-xserver commit: commit 75c51c67b340548286efd41a53882e2acaf74ab5 Author: Alan Coopersmith Date: Thu Jun 18 09:49:12 2009 -0700 Clarify use of and need for mffs vs. ffs Signed-off-by: Alan Coopersmith --- nx-X11/programs/Xserver/os/WaitFor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver/os/WaitFor.c') diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index 3d53335b3..82462b926 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -106,6 +106,8 @@ static unsigned long startTimeInMillis; Windows in the code */ #define GetErrno() errno +/* like ffs, but uses fd_mask instead of int as argument, so it works + when fd_mask is longer than an int, such as common 64-bit platforms */ /* modifications by raphael */ int mffs(fd_mask mask) @@ -480,7 +482,7 @@ WaitForSomething(int *pClientsReady) { int client_index; - curclient = ffs (clientsReadable.fds_bits[i]) - 1; + curclient = mffs (clientsReadable.fds_bits[i]) - 1; client_index = /* raphael: modified */ ConnectionTranslation[curclient + (i * (sizeof(fd_mask) * 8))]; pClientsReady[nready++] = client_index; -- cgit v1.2.3 From d282724c4abda9e59a029c2c485d7d046ff647db Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 18 Jan 2020 21:59:58 +0100 Subject: os/Waitfor.c: simplify macro handling 1. indent ifdefs 2. add some logic at start that unset NX_TRANS_WAKEUP and NX_TRANS_DEBUG if NX_TRANS_SOCKET is unset. This way we only have to check for one macro and not all three. 3. remove redundant macro checks 4. decouple debug printfs by always running the original code and adding the identical check in #ifdef NX_TRANS_DEBUG --- nx-X11/programs/Xserver/os/WaitFor.c | 115 +++++++++++++++++------------------ 1 file changed, 56 insertions(+), 59 deletions(-) (limited to 'nx-X11/programs/Xserver/os/WaitFor.c') diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index 82462b926..c76f8619c 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -96,10 +96,21 @@ SOFTWARE. #include "dpmsproc.h" #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) +/* + * unset defines without NX_TRANS_SOCKET. This allows for shorter + * ifdefs below + */ +#ifndef NX_TRANS_SOCKET +#ifdef NX_TRANS_DEBUG +#undef NX_TRANS_DEBUG +#endif +#ifdef NX_TRANS_WAKEUP +#undef NX_TRANS_WAKEUP +#endif +#endif +#ifdef NX_TRANS_WAKEUP static unsigned long startTimeInMillis; - #endif /* This is just a fallback to errno to hide the differences between unix and @@ -171,17 +182,15 @@ WaitForSomething(int *pClientsReady) Bool someReady = FALSE; Bool someNotifyWriteReady = FALSE; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Got called.\n"); -#endif + #endif FD_ZERO(&clientsReadable); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) - + #ifdef NX_TRANS_WAKEUP startTimeInMillis = GetTimeInMillis(); - -#endif + #endif /* We need a while loop here to handle crashed connections and the screen saver timeout */ @@ -224,44 +233,44 @@ WaitForSomething(int *pClientsReady) if (NewOutputPending) FlushAllOutput(); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) +#ifdef NX_TRANS_WAKEUP /* * If caller has marked the first element of pClientsReady[], - * bail out of select after a short timeout. We need this to - * let the NX agent remove the splash screen when the timeout - * is expired. A better option would be to use the existing - * screen-saver timeout but it can be modified by clients, so - * we would need a special handling. This hack is trivial and - * keeps WaitForSomething() backward compatible with the exis- - * ting servers. + * bail out of select after a short (NX_TRANS_WAKEUP) + * timeout. We need this to let the NX agent remove the splash + * screen when the timeout is expired. A better option would + * be to use the existing screen-saver timeout but it can be + * modified by clients, so we would need a special + * handling. This hack is trivial and keeps WaitForSomething() + * backward compatible with the existing servers. */ if (pClientsReady[0] == -1) { unsigned long timeoutInMillis; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: pClientsReady[0] is [%d], pClientsReady[1] is [%d].\n", - pClientsReady[0], pClientsReady[1]); -#endif + pClientsReady[0], pClientsReady[1]); + #endif timeoutInMillis = GetTimeInMillis(); if (timeoutInMillis - startTimeInMillis >= NX_TRANS_WAKEUP) { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Returning 0 because of wakeup timeout.\n"); -#endif - return 0; + #endif + return 0; } timeoutInMillis = NX_TRANS_WAKEUP - (timeoutInMillis - startTimeInMillis); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Milliseconds to next wakeup are %ld.\n", timeoutInMillis); -#endif + #endif if (wt == NULL || (wt -> tv_sec * MILLI_PER_SECOND + wt -> tv_usec / MILLI_PER_SECOND) > timeoutInMillis) { @@ -274,38 +283,33 @@ WaitForSomething(int *pClientsReady) wt = &waittime; } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Next wakeup timeout set to %ld milliseconds.\n", (waittime.tv_sec * MILLI_PER_SECOND) + (waittime.tv_usec / MILLI_PER_SECOND)); -#endif + #endif } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_WAKEUP) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG else { fprintf(stderr, "WaitForSomething: Using existing timeout of %ld milliseconds.\n", (waittime.tv_sec * MILLI_PER_SECOND) + (waittime.tv_usec / MILLI_PER_SECOND)); } -#endif + #endif } -#endif +#endif /* defined(NX_TRANS_WAKEUP) */ /* keep this check close to select() call to minimize race */ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG if (dispatchException) - { - i = -1; - fprintf(stderr, "WaitForSomething: Value of dispatchException is true. Set i = -1.\n"); - } -#else + #endif if (dispatchException) i = -1; -#endif else if (AnyWritesPending) { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG if (wt == NULL) { fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask and " @@ -317,14 +321,14 @@ WaitForSomething(int *pClientsReady) "clientsWritable, %ld secs and %ld usecs.\n", wt -> tv_sec, wt -> tv_usec); } -#endif + #endif XFD_COPYSET(&ClientsWriteBlocked, &LastSelectWriteMask); XFD_ORSET(&LastSelectWriteMask, &NotifyWriteFds, &LastSelectWriteMask); i = Select(MaxClients, &LastSelectMask, &LastSelectWriteMask, NULL, wt); } else { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG if (wt == NULL) { fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask and null timeout.\n"); @@ -334,17 +338,16 @@ WaitForSomething(int *pClientsReady) fprintf(stderr, "WaitForSomething: Executing select with LastSelectMask, %ld secs and %ld usecs.\n", wt -> tv_sec, wt -> tv_usec); } -#endif + #endif i = Select (MaxClients, &LastSelectMask, NULL, NULL, wt); } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Bailed out with i = [%d] and errno = [%d].\n", i, errno); - if (i < 0) { fprintf(stderr, "WaitForSomething: Error is [%s].\n", strerror(errno)); } -#endif + #endif selecterr = GetErrno(); WakeupHandler(i, (void *)&LastSelectMask); @@ -352,31 +355,29 @@ WaitForSomething(int *pClientsReady) if (i <= 0) /* An error or timeout occurred */ { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG if (dispatchException) { fprintf(stderr, "WaitForSomething: Returning 0 because of (dispatchException).\n"); - return 0; } -#else + #endif if (dispatchException) return 0; -#endif + if (i < 0) { if (selecterr == EBADF) /* Some client disconnected */ { CheckConnections (); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + + #ifdef NX_TRANS_DEBUG if (! XFD_ANYSET (&AllClients)) { fprintf(stderr, "WaitForSomething: Returning 0 because of (! XFD_ANYSET (&AllClients)).\n"); - return 0; } -#else + #endif if (! XFD_ANYSET (&AllClients)) return 0; -#endif } else if (selecterr == EINVAL) { @@ -398,18 +399,14 @@ WaitForSomething(int *pClientsReady) XFD_COPYSET(&ClientsWithInput, &clientsReadable); break; } -#if defined(NX_TRANS_SOCKET) + #ifdef NX_TRANS_DEBUG if (*checkForInput[0] != *checkForInput[1]) { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) fprintf(stderr, "WaitForSomething: Returning 0 because of (*checkForInput[0] != *checkForInput[1]).\n"); -#endif - return 0; } -#else + #endif if (*checkForInput[0] != *checkForInput[1]) return 0; -#endif if (timers) { @@ -490,9 +487,9 @@ WaitForSomething(int *pClientsReady) } } } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) + #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Returning nready.\n"); -#endif + #endif return nready; } -- cgit v1.2.3 From 92ac0d27737cf94e72208817cfd261a412a0e428 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 18 Jan 2020 22:09:44 +0100 Subject: WaitFor.c Implement the intended NX_WAKEUP functionality NX_WAKEUP had been non-effective and its effect had been tied to NX_TRANS_WAKEUP. --- nx-X11/programs/Xserver/os/WaitFor.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'nx-X11/programs/Xserver/os/WaitFor.c') diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c index c76f8619c..9e887c726 100644 --- a/nx-X11/programs/Xserver/os/WaitFor.c +++ b/nx-X11/programs/Xserver/os/WaitFor.c @@ -237,13 +237,15 @@ WaitForSomething(int *pClientsReady) /* * If caller has marked the first element of pClientsReady[], - * bail out of select after a short (NX_TRANS_WAKEUP) - * timeout. We need this to let the NX agent remove the splash - * screen when the timeout is expired. A better option would - * be to use the existing screen-saver timeout but it can be - * modified by clients, so we would need a special - * handling. This hack is trivial and keeps WaitForSomething() - * backward compatible with the existing servers. + * bail out of select after the timeout given in the second + * element. We need this to let the NX agent remove the splash + * screen when the timeout is expired even if there's no + * client. Otherwise WaitForSomething would block. A better + * option would be to use the existing screen-saver timeout + * but it can be modified by clients, so we would need a + * special handling. This hack is trivial and keeps + * WaitForSomething() backward compatible with the existing + * servers. */ if (pClientsReady[0] == -1) @@ -257,7 +259,7 @@ WaitForSomething(int *pClientsReady) timeoutInMillis = GetTimeInMillis(); - if (timeoutInMillis - startTimeInMillis >= NX_TRANS_WAKEUP) + if (timeoutInMillis - startTimeInMillis >= pClientsReady[1]) { #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Returning 0 because of wakeup timeout.\n"); @@ -265,7 +267,7 @@ WaitForSomething(int *pClientsReady) return 0; } - timeoutInMillis = NX_TRANS_WAKEUP - (timeoutInMillis - startTimeInMillis); + timeoutInMillis = pClientsReady[1] - (timeoutInMillis - startTimeInMillis); #ifdef NX_TRANS_DEBUG fprintf(stderr, "WaitForSomething: Milliseconds to next wakeup are %ld.\n", -- cgit v1.2.3