aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/src/XlibInt.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/lib/src/XlibInt.c')
-rw-r--r--nx-X11/lib/src/XlibInt.c156
1 files changed, 75 insertions, 81 deletions
diff --git a/nx-X11/lib/src/XlibInt.c b/nx-X11/lib/src/XlibInt.c
index 36e650193..bd97ed0bc 100644
--- a/nx-X11/lib/src/XlibInt.c
+++ b/nx-X11/lib/src/XlibInt.c
@@ -128,20 +128,29 @@ 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
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
@@ -254,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;
}
@@ -283,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
@@ -296,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
@@ -434,15 +436,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 +462,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 +481,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 &&
@@ -521,7 +523,6 @@ _XWaitForWritable(
#ifdef NX_TRANS_SOCKET
{
_XIOError(dpy);
-
return;
}
#else /* NX_TRANS_SOCKET */
@@ -681,7 +682,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 +722,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 +758,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 +972,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,8 +987,8 @@ static void _XFlushInt(
*/
if (dpy->flags & XlibDisplayIOError)
{
-#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_DEBUG)
- fprintf(stderr, "_XFlushInt: Returning with I/O error detected.\n");
+#ifdef NX_TRANS_DEBUG
+ fprintf(stderr, "_XFlushInt: Returning with I/O error detected.\n");
#endif
dpy->bufptr = dpy->buffer;
dpy->last_req = (char *)&_dummy_request;
@@ -1124,7 +1125,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,14 +1171,13 @@ _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)
#ifdef NX_TRANS_SOCKET
{
_XIOError(dpy);
-
return (dpy->qlen);
}
#else
@@ -1199,14 +1199,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);
@@ -1220,7 +1220,6 @@ _XEventsQueued(
#ifdef NX_TRANS_SOCKET
{
_XIOError(dpy);
-
return (dpy->qlen);
}
#else
@@ -1254,7 +1253,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 +1449,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 +1535,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
@@ -1582,12 +1581,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
}
@@ -1664,7 +1661,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 +1681,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,20 +1779,20 @@ _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)
- fprintf(stderr, "_XSend: Sending data with [%d] bytes to write.\n",
- (dpy->bufptr - dpy->buffer));
+#ifdef NX_TRANS_DEBUG
+ fprintf(stderr, "_XSend: Sending data with [%d] bytes to write.\n",
+ (dpy->bufptr - dpy->buffer));
#endif
if (!size || (dpy->flags & XlibDisplayIOError))
{
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 +2142,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 +2173,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);
@@ -2196,9 +2193,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
@@ -2272,8 +2268,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);
@@ -2402,8 +2398,7 @@ _XAsyncReply(
#ifdef NX_TRANS_SOCKET
/*
- * The original code has provision
- * for returning already.
+ * The original code has provision for returning already.
*/
#endif
@@ -2476,7 +2471,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 +2521,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 +2562,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 +2623,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 +2655,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 +2714,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 +2755,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
@@ -3715,11 +3710,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)