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>
This commit is contained in:
parent
559aac2d71
commit
c3fea428ae
|
@ -863,7 +863,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
||||||
|
|
||||||
if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
|
if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
|
||||||
ErrorConnMax(new_trans_conn);
|
ErrorConnMax(new_trans_conn);
|
||||||
_XSERVTransClose(new_trans_conn);
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
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
|
* Fail a connection due to lack of client or file descriptor space
|
||||||
************/
|
************/
|
||||||
|
|
||||||
#define BOTIMEOUT 200 /* in milliseconds */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ErrorConnMax(XtransConnInfo trans_conn)
|
ConnMaxNotify(int fd, int events, void *data)
|
||||||
{
|
{
|
||||||
int fd = _XSERVTransGetConnectionNumber(trans_conn);
|
XtransConnInfo trans_conn = data;
|
||||||
xConnSetupPrefix csp;
|
|
||||||
char pad[3] = { 0, 0, 0 };
|
|
||||||
struct iovec iov[3];
|
|
||||||
char order = 0;
|
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 */
|
/* try to read the byte-order of the connection */
|
||||||
(void) _XSERVTransRead(trans_conn, &order, 1);
|
(void) _XSERVTransRead(trans_conn, &order, 1);
|
||||||
if (order == 'l' || order == 'B' || order == 'r' || order == 'R') {
|
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.success = xFalse;
|
||||||
csp.lengthReason = sizeof(NOROOM) - 1;
|
csp.lengthReason = sizeof(NOROOM) - 1;
|
||||||
csp.length = (sizeof(NOROOM) + 2) >> 2;
|
csp.length = (sizeof(NOROOM) + 2) >> 2;
|
||||||
csp.majorVersion = X_PROTOCOL;
|
csp.majorVersion = X_PROTOCOL;
|
||||||
csp.minorVersion = X_PROTOCOL_REVISION;
|
csp.minorVersion = X_PROTOCOL_REVISION;
|
||||||
if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
|
if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
|
||||||
(!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
|
(!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
|
||||||
swaps(&csp.majorVersion);
|
swaps(&csp.majorVersion);
|
||||||
swaps(&csp.minorVersion);
|
swaps(&csp.minorVersion);
|
||||||
swaps(&csp.length);
|
swaps(&csp.length);
|
||||||
|
@ -924,6 +913,15 @@ ErrorConnMax(XtransConnInfo trans_conn)
|
||||||
iov[2].iov_base = pad;
|
iov[2].iov_base = pad;
|
||||||
(void) _XSERVTransWritev(trans_conn, iov, 3);
|
(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)) {
|
if (!AllocNewConnection(ciptr, fd, connect_time)) {
|
||||||
ErrorConnMax(ciptr);
|
ErrorConnMax(ciptr);
|
||||||
_XSERVTransClose(ciptr);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue