From e9f628fd250dc943f2d7ae5005f790c7f6a27b5f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 4 Feb 2020 19:06:33 +0100 Subject: XlibInt.c: simplify handling of NX_TRANS_{CHANGE,DEBUG} macros --- nx-X11/lib/src/XlibInt.c | 85 +++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 37 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/src/XlibInt.c b/nx-X11/lib/src/XlibInt.c index 36e650193..02c1394d2 100644 --- a/nx-X11/lib/src/XlibInt.c +++ b/nx-X11/lib/src/XlibInt.c @@ -142,6 +142,17 @@ static struct timeval retry; extern int _X11TransSocketCongestionChange(XtransConnInfo, int *); #endif +#else +/* + * unifdef to simplify subsequent checks. IF NX_TRANS_CHANGE is set it + * is safe to assume NX_TRANS_SOCKET is also set. Same for NX_TRANS_DEBUG. + */ +# ifdef NX_TRANS_CHANGE +# undef NX_TRANS_CHANGE +# endif +# ifdef NX_TRANS_DEBUG +# undef NX_TRANS_DEBUG +# endif #endif /* #ifdef NX_TRANS_SOCKET */ /* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX @@ -434,15 +445,15 @@ _XWaitForWritable( #endif /* #ifdef NX_TRANS_SOCKET */ UnlockDisplay(dpy); #ifdef USE_POLL -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XWaitForWritable: Calling poll().\n"); #endif nfound = poll (&filedes, 1, -1); #else /* USE_POLL */ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XWaitForWritable: Calling select() after [%ld] ms.\n", NXTransTime()); -#endif /* defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) */ +#endif /* ifdef NX_TRANS_DEBUG */ #ifdef NX_TRANS_SOCKET /* * Give a chance to the callback to detect @@ -460,7 +471,7 @@ _XWaitForWritable( #else /* NX_TRANS_SOCKET */ nfound = Select (dpy->fd + 1, &r_mask, &w_mask, NULL, NULL); #endif /* NX_TRANS_SOCKET */ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XWaitForWritable: Out of select() with [%d] after [%ld] ms.\n", nfound, NXTransTime()); @@ -479,16 +490,16 @@ _XWaitForWritable( fprintf(stderr, "_XWaitForWritable: Descriptor [%d] has become writable.\n\n", dpy->fd); } -#endif /* defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) */ +#endif /* ifdef NX_TRANS_DEBUG */ #endif /* USE_POLL */ InternalLockDisplay(dpy, cv != NULL); #ifdef NX_TRANS_SOCKET -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE if (_NXDisplayCongestionFunction != NULL && _X11TransSocketCongestionChange(dpy->trans_conn, &congestion) == 1) { (*_NXDisplayCongestionFunction)(dpy, congestion); } -#endif /* defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) */ +#endif /* ifdef NX_TRANS_CHANGE */ if (nfound <= 0) { if ((nfound == -1 && !(ECHECK(EINTR) || ETEST())) || (_NXDisplayErrorFunction != NULL && @@ -681,7 +692,7 @@ _XWaitForReadable( int highest_fd = fd; #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE int congestion; #endif #ifdef NX_TRANS_SOCKET @@ -721,14 +732,14 @@ _XWaitForReadable( #endif /* USE_POLL */ UnlockDisplay(dpy); #ifdef USE_POLL -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XWaitForReadable: Calling poll().\n"); #endif result = poll(filedes, (dpy->flags & XlibDisplayProcConni) ? 1 : 1+dpy->im_fd_length, -1); #else /* USE_POLL */ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XWaitForReadable: Calling select().\n"); #endif #ifdef NX_TRANS_SOCKET @@ -757,12 +768,12 @@ _XWaitForReadable( result = Select(highest_fd + 1, &r_mask, NULL, NULL, NULL); #endif /* NX_TRANS_SOCKET */ #endif /* USE_POLL */ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XWaitForReadable: Out of select with result [%d] and errno [%d].\n", result, (result < 0 ? errno : 0)); #endif InternalLockDisplay(dpy, dpy->flags & XlibDisplayReply); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE if (_NXDisplayCongestionFunction != NULL && _X11TransSocketCongestionChange(dpy->trans_conn, &congestion) == 1) { (*_NXDisplayCongestionFunction)(dpy, congestion); @@ -971,11 +982,11 @@ static void _XFlushInt( register int write_stat; register char *bufindex; _XExtension *ext; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE int congestion; #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XFlushInt: Entering flush with [%d] bytes to write.\n", (dpy->bufptr - dpy->buffer)); #endif @@ -986,7 +997,7 @@ static void _XFlushInt( */ if (dpy->flags & XlibDisplayIOError) { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XFlushInt: Returning with I/O error detected.\n"); #endif dpy->bufptr = dpy->buffer; @@ -1124,7 +1135,7 @@ _XEventsQueued( if (dpy->qlen) return(dpy->qlen); } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG if (dpy->flags & XlibDisplayIOError) { fprintf(stderr, "_XEventsQueued: Returning [%d] after display failure.\n", dpy->qlen); @@ -1170,7 +1181,7 @@ _XEventsQueued( } #endif /* XTHREADS*/ -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XEventsQueued: Checking bytes readable.\n"); #endif if (_X11TransBytesReadable(dpy->trans_conn, &pend) < 0) @@ -1199,14 +1210,14 @@ _XEventsQueued( dpy->conn_checker = 0; #ifdef USE_POLL -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XEventsQueued: Calling poll().\n"); #endif filedes.fd = dpy->fd; filedes.events = POLLIN; if ((result = poll(&filedes, 1, 0))) #else -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XEventsQueued: Calling select().\n"); #endif FD_ZERO(&r_mask); @@ -1254,7 +1265,7 @@ _XEventsQueued( { UnlockNextEventReader(dpy); } -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XEventsQueued: Returning [%d].\n", dpy->qlen); #endif return(dpy->qlen); @@ -1450,7 +1461,7 @@ void _XReadEvents( #ifdef NX_TRANS_SOCKET if (dpy->flags & XlibDisplayIOError) { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XReadEvents: Returning with I/O error detected.\n"); #endif return; @@ -1536,14 +1547,14 @@ int _XRead( #ifdef XTHREADS int original_size = size; #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE int congestion; #endif if ((dpy->flags & XlibDisplayIOError) || size == 0) return 0; ESET(0); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE while (1) { /* * Need to check the congestion state @@ -1664,7 +1675,7 @@ void _XReadPad( #ifdef XTHREADS int original_size; #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE int congestion; #endif @@ -1684,7 +1695,7 @@ void _XReadPad( original_size = size; #endif ESET(0); -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE while (1) { bytes_read = _X11TransReadv (dpy->trans_conn, iov, 2); if (_NXDisplayCongestionFunction != NULL && @@ -1782,12 +1793,12 @@ _XSend ( long skip, dbufsize, padsize, total, todo; _XExtension *ext; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_CHANGE) +#ifdef NX_TRANS_CHANGE int congestion; #endif #ifdef NX_TRANS_SOCKET -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XSend: Sending data with [%d] bytes to write.\n", (dpy->bufptr - dpy->buffer)); #endif @@ -1795,7 +1806,7 @@ _XSend ( { if (dpy->flags & XlibDisplayIOError) { -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XSend: Returning with I/O error detected.\n"); #endif dpy->bufptr = dpy->buffer; @@ -2145,7 +2156,7 @@ _XReply ( #ifdef XTHREADS struct _XCVList *cvl; #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XReply: Going to wait for an X reply.\n"); #endif @@ -2176,7 +2187,7 @@ _XReply ( XThread_Self(), cvl); #endif -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XReply: Going to flush the display buffer.\n"); #endif _XFlushInt(dpy, cvl ? cvl->cv : NULL); @@ -2476,7 +2487,7 @@ _XRegisterInternalConnection( struct _XConnWatchInfo *watchers; XPointer *wd; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XRegisterInternalConnection: Got called.\n"); #endif new_conni = Xmalloc(sizeof(struct _XConnectionInfo)); @@ -2526,7 +2537,7 @@ _XUnregisterInternalConnection( struct _XConnWatchInfo *watch; XPointer *wd; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XUnregisterInternalConnection: Got called.\n"); #endif for (prev = &dpy->im_fd_info; (info_list = *prev); @@ -2567,7 +2578,7 @@ XInternalConnectionNumbers( struct _XConnectionInfo *info_list; int *fd_list; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "XInternalConnectionNumbers: Got called.\n"); #endif LockDisplay(dpy); @@ -2628,7 +2639,7 @@ XProcessInternalConnection( { struct _XConnectionInfo *info_list; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "XProcessInternalConnection: Got called.\n"); #endif @@ -2660,7 +2671,7 @@ XAddConnectionWatch( struct _XConnectionInfo *info_list; XPointer *wd_array; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "XAddConnectionWatch: Got called.\n"); #endif LockDisplay(dpy); @@ -2719,7 +2730,7 @@ XRemoveConnectionWatch( struct _XConnectionInfo *conni; int counter = 0; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "XRemoveConnectionWatch: Got called.\n"); #endif LockDisplay(dpy); @@ -2760,7 +2771,7 @@ void _XEatData( #define SCRATCHSIZE 2048 char buf[SCRATCHSIZE]; -#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG) +#ifdef NX_TRANS_DEBUG fprintf(stderr, "_XEatData: Going to eat [%ld] bytes of data from descriptor [%d].\n", n, dpy->fd); #endif -- cgit v1.2.3 From 17ab45b921c2e17437d585cb3e9d62ca73ab04c5 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 4 Feb 2020 19:15:31 +0100 Subject: XlibInt.c: reformat some comments --- nx-X11/lib/src/XlibInt.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/src/XlibInt.c b/nx-X11/lib/src/XlibInt.c index 02c1394d2..0c27f34da 100644 --- a/nx-X11/lib/src/XlibInt.c +++ b/nx-X11/lib/src/XlibInt.c @@ -128,14 +128,12 @@ xthread_t (*_Xthread_self_fn)(void) = NULL; static struct timeval retry; /* - * From Xtranssock.c. Presently the congestion state - * is reported by the proxy to the application, by - * invoking the callback directly. The function will - * be possibly used in the future, to be able to track - * the bandwidth usage even when the NX transport is - * not running. Note that in this sample implementation - * the congestion state is checked very often and can - * be surely optimized. + * From Xtranssock.c. Presently the congestion state is reported by + * the proxy to the application, by invoking the callback + * directly. The function will be possibly used in the future, to be + * able to track the bandwidth usage even when the NX transport is not + * running. Note that in this sample implementation the congestion + * state is checked very often and can be surely optimized. */ #ifdef NX_TRANS_CHANGE @@ -2207,9 +2205,8 @@ _XReply ( #ifdef NX_TRANS_SOCKET /* - * We are going to block waiting for the remote - * X server. Be sure that the proxy has flushed - * all the data. + * We are going to block waiting for the remote X server. Be sure + * that the proxy has flushed all the data. */ #ifdef NX_TRANS_TEST @@ -2283,8 +2280,8 @@ _XReply ( UnlockNextReplyReader(dpy); #ifdef NX_TRANS_SOCKET /* - * The original code has provision - * for returning already. + * The original code has provision for returning + * already. */ #endif _XIOError (dpy); @@ -2413,8 +2410,7 @@ _XAsyncReply( #ifdef NX_TRANS_SOCKET /* - * The original code has provision - * for returning already. + * The original code has provision for returning already. */ #endif @@ -3726,11 +3722,10 @@ _XIOError ( _XDefaultIOError(dpy); #ifdef NX_TRANS_SOCKET /* - * Check if we are supposed to return in the case - * of a display failure. The client which originated - * the X operation will have to check the value of - * the XlibDisplayIOError flag and handle appropria- - * tely the display disconnection. + * Check if we are supposed to return in the case of a display + * failure. The client which originated the X operation will have + * to check the value of the XlibDisplayIOError flag and handle + * appropriately the display disconnection. */ if (_NXHandleDisplayError == 0) -- cgit v1.2.3 From 52a458282a50bf54b54eacf071a15a26ab6e8547 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 4 Feb 2020 19:15:47 +0100 Subject: XlibInt.c: simplify NX code insertion --- nx-X11/lib/src/XlibInt.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/src/XlibInt.c b/nx-X11/lib/src/XlibInt.c index 0c27f34da..5a481c9ab 100644 --- a/nx-X11/lib/src/XlibInt.c +++ b/nx-X11/lib/src/XlibInt.c @@ -530,7 +530,6 @@ _XWaitForWritable( #ifdef NX_TRANS_SOCKET { _XIOError(dpy); - return; } #else /* NX_TRANS_SOCKET */ @@ -996,7 +995,7 @@ static void _XFlushInt( if (dpy->flags & XlibDisplayIOError) { #ifdef NX_TRANS_DEBUG - fprintf(stderr, "_XFlushInt: Returning with I/O error detected.\n"); + fprintf(stderr, "_XFlushInt: Returning with I/O error detected.\n"); #endif dpy->bufptr = dpy->buffer; dpy->last_req = (char *)&_dummy_request; @@ -1186,7 +1185,6 @@ _XEventsQueued( #ifdef NX_TRANS_SOCKET { _XIOError(dpy); - return (dpy->qlen); } #else @@ -1229,7 +1227,6 @@ _XEventsQueued( #ifdef NX_TRANS_SOCKET { _XIOError(dpy); - return (dpy->qlen); } #else @@ -1591,12 +1588,10 @@ int _XRead( else if (bytes_read == 0) { /* Read failed because of end of file! */ ESET(EPIPE); -#ifdef NX_TRANS_SOCKET - _XIOError(dpy); - return -1; -#else _XIOError(dpy); +#ifdef NX_TRANS_SOCKET + return -1; #endif } @@ -1797,8 +1792,8 @@ _XSend ( #ifdef NX_TRANS_SOCKET #ifdef NX_TRANS_DEBUG - fprintf(stderr, "_XSend: Sending data with [%d] bytes to write.\n", - (dpy->bufptr - dpy->buffer)); + fprintf(stderr, "_XSend: Sending data with [%d] bytes to write.\n", + (dpy->bufptr - dpy->buffer)); #endif if (!size || (dpy->flags & XlibDisplayIOError)) { -- cgit v1.2.3 From f3473e38ca4b4132303cb76e06fe06889ae5c131 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 5 Feb 2020 23:56:08 +0100 Subject: XlibInt.c: scope improvements/reformat --- nx-X11/lib/src/XlibInt.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'nx-X11/lib') diff --git a/nx-X11/lib/src/XlibInt.c b/nx-X11/lib/src/XlibInt.c index 5a481c9ab..bd97ed0bc 100644 --- a/nx-X11/lib/src/XlibInt.c +++ b/nx-X11/lib/src/XlibInt.c @@ -263,28 +263,22 @@ int _XSelect(int maxfds, fd_set *readfds, fd_set *writefds, fd_set t_readfds, t_writefds; struct timeval t_timeout; - int n, r, e; - #ifdef NX_TRANS_TEST - if (exceptfds != NULL) { fprintf(stderr, "_XSelect: WARNING! Can't handle exception fds in select.\n"); } - #endif if (readfds == NULL) { FD_ZERO(&t_readfds); - readfds = &t_readfds; } if (writefds == NULL) { FD_ZERO(&t_writefds); - writefds = &t_writefds; } @@ -292,11 +286,10 @@ int _XSelect(int maxfds, fd_set *readfds, fd_set *writefds, { t_timeout.tv_sec = 10; t_timeout.tv_usec = 0; - timeout = &t_timeout; } - n = maxfds; + int n = maxfds; /* * If the transport is gone avoid @@ -305,17 +298,17 @@ int _XSelect(int maxfds, fd_set *readfds, fd_set *writefds, if (NXTransPrepare(&n, readfds, writefds, timeout) != 0) { - NXTransSelect(&r, &e, &n, readfds, writefds, timeout); + int r, e; - NXTransExecute(&r, &e, &n, readfds, writefds, timeout); + NXTransSelect(&r, &e, &n, readfds, writefds, timeout); + NXTransExecute(&r, &e, &n, readfds, writefds, timeout); + errno = e; - errno = e; - - return r; + return r; } else { - return 0; + return 0; } } else -- cgit v1.2.3