From eb49996116fd3beeff66ddf192bfc80e117086d1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 15 Mar 2017 11:42:30 +0100 Subject: os: Use NotifyFd for ErrorConnMax commit c3fea428aed919826130ef8ebdb2cceb445a845b Author: Keith Packard Date: Tue May 24 20:51:31 2016 -0700 os: Use NotifyFd for ErrorConnMax Instead of open-coding a single FD wait, use NotifyFd to wait for the FD to become readable before returning the error message. Signed-off-by: Keith Packard Reviewed-by: Adam Jackson Backported-to-NX-by: Mike Gabriel --- nx-X11/programs/Xserver/os/connection.c | 36 +++++++++++++++++---------------- nx-X11/programs/Xserver/os/osdep.h | 1 - 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c index 172ed6f4c..2fa8ad12d 100644 --- a/nx-X11/programs/Xserver/os/connection.c +++ b/nx-X11/programs/Xserver/os/connection.c @@ -74,6 +74,7 @@ SOFTWARE. #define TRANS_SERVER #define TRANS_REOPEN #include +#include #include #include #include @@ -874,7 +875,6 @@ EstablishNewConnections(ClientPtr clientUnused, void * closure) )) { ErrorConnMax(new_trans_conn); - _XSERVTransClose(new_trans_conn); } } #ifndef WIN32 @@ -891,28 +891,21 @@ EstablishNewConnections(ClientPtr clientUnused, void * closure) ************/ static void -ErrorConnMax(XtransConnInfo trans_conn) +ConnMaxNotify(int fd, int events, void *data) { - int fd = _XSERVTransGetConnectionNumber (trans_conn); - xConnSetupPrefix csp; - char pad[3]; - struct iovec iov[3]; + XtransConnInfo trans_conn = data; char order = 0; - int whichbyte = 1; - struct timeval waittime; - fd_set mask; - - /* if these seems like a lot of trouble to go to, it probably is */ - waittime.tv_sec = BOTIMEOUT / MILLI_PER_SECOND; - waittime.tv_usec = (BOTIMEOUT % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - FD_ZERO(&mask); - FD_SET(fd, &mask); - (void)Select(fd + 1, &mask, NULL, NULL, &waittime); + /* try to read the byte-order of the connection */ (void)_XSERVTransRead(trans_conn, &order, 1); if (order == 'l' || order == 'B' || order == 'r' || order == 'R') { + + xConnSetupPrefix csp; + char pad[3] = { 0, 0, 0 }; + int whichbyte = 1; + struct iovec iov[3]; + csp.success = xFalse; csp.lengthReason = sizeof(NOROOM) - 1; csp.length = (sizeof(NOROOM) + 2) >> 2; @@ -933,6 +926,15 @@ ErrorConnMax(XtransConnInfo trans_conn) iov[2].iov_base = pad; (void)_XSERVTransWritev(trans_conn, iov, 3); } + RemoveNotifyFd(trans_conn->fd); + _XSERVTransClose(trans_conn); +} + +static void +ErrorConnMax(XtransConnInfo trans_conn) +{ + if (!SetNotifyFd(trans_conn->fd, ConnMaxNotify, X_NOTIFY_READ, trans_conn)) + _XSERVTransClose(trans_conn); } /************ diff --git a/nx-X11/programs/Xserver/os/osdep.h b/nx-X11/programs/Xserver/os/osdep.h index fdd8c7174..d3e9d0b33 100644 --- a/nx-X11/programs/Xserver/os/osdep.h +++ b/nx-X11/programs/Xserver/os/osdep.h @@ -52,7 +52,6 @@ SOFTWARE. #ifndef _OSDEP_H_ #define _OSDEP_H_ 1 -#define BOTIMEOUT 200 /* in milliseconds */ #define BUFSIZE 4096 #define BUFWATERMARK 8192 #ifndef MAXBUFSIZE -- cgit v1.2.3