summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-05-24 20:51:31 -0700
committerAdam Jackson <ajax@redhat.com>2016-07-18 15:25:59 -0400
commitc3fea428aed919826130ef8ebdb2cceb445a845b (patch)
tree42c18aed06b1135cba0ac3c8c579432830132e97 /os
parent559aac2d71250e3137aaa582e2a59a918ddf21b7 (diff)
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 <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'os')
-rw-r--r--os/connection.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/os/connection.c b/os/connection.c
index 4c1ba4b6d..d001b98ee 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -863,7 +863,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
ErrorConnMax(new_trans_conn);
- _XSERVTransClose(new_trans_conn);
}
return TRUE;
}
@@ -881,37 +880,27 @@ QueueNewConnections(int fd, int ready, void *data)
* Fail a connection due to lack of client or file descriptor space
************/
-#define BOTIMEOUT 200 /* in milliseconds */
-
static void
-ErrorConnMax(XtransConnInfo trans_conn)
+ConnMaxNotify(int fd, int events, void *data)
{
- int fd = _XSERVTransGetConnectionNumber(trans_conn);
- xConnSetupPrefix csp;
- char pad[3] = { 0, 0, 0 };
- 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;
csp.majorVersion = X_PROTOCOL;
csp.minorVersion = X_PROTOCOL_REVISION;
- if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
- (!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
+ if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
+ (!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
swaps(&csp.majorVersion);
swaps(&csp.minorVersion);
swaps(&csp.length);
@@ -924,6 +913,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);
}
/************
@@ -1426,7 +1424,6 @@ AddClientOnOpenFD(int fd)
if (!AllocNewConnection(ciptr, fd, connect_time)) {
ErrorConnMax(ciptr);
- _XSERVTransClose(ciptr);
return FALSE;
}