mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 08:04:30 +00:00
os: connection: simplify connection error sending
It's such a cold and rarely used path, we really don't need writev() for efficiency, so instead doing two trivial write()'s. And the complex size calculation as well as extra padding isn't necessary, if we just make the string of size 4*n. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
committed by
Enrico Weigelt
parent
8ad4b6a309
commit
a3a068d6d3
@@ -701,8 +701,6 @@ EstablishNewConnections(int curconn, int ready, void *data)
|
||||
return;
|
||||
}
|
||||
|
||||
#define NOROOM "Maximum number of clients reached"
|
||||
|
||||
/************
|
||||
* ErrorConnMax
|
||||
* Fail a connection due to lack of client or file descriptor space
|
||||
@@ -717,29 +715,28 @@ ConnMaxNotify(int fd, int events, void *data)
|
||||
/* 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;
|
||||
/* 36 bytes (with zero) -- needs to be padded to 4*n */
|
||||
#define ERR_TEXT "Maximum number of clients reached\0\0"
|
||||
|
||||
xConnSetupPrefix csp = {
|
||||
.success = xFalse,
|
||||
.lengthReason = sizeof(ERR_TEXT),
|
||||
.length = sizeof(ERR_TEXT) >> 2,
|
||||
.majorVersion = X_PROTOCOL,
|
||||
.minorVersion = X_PROTOCOL_REVISION,
|
||||
};
|
||||
|
||||
if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
|
||||
(!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
|
||||
swaps(&csp.majorVersion);
|
||||
swaps(&csp.minorVersion);
|
||||
swaps(&csp.length);
|
||||
}
|
||||
iov[0].iov_len = sz_xConnSetupPrefix;
|
||||
iov[0].iov_base = (char *) &csp;
|
||||
iov[1].iov_len = csp.lengthReason;
|
||||
iov[1].iov_base = (void *) NOROOM;
|
||||
iov[2].iov_len = (4 - (csp.lengthReason & 3)) & 3;
|
||||
iov[2].iov_base = pad;
|
||||
(void) _XSERVTransWritev(trans_conn, iov, 3);
|
||||
|
||||
_XSERVTransWrite(trans_conn, (const char*)&csp, sizeof(csp));
|
||||
_XSERVTransWrite(trans_conn, ERR_TEXT, sizeof(ERR_TEXT));
|
||||
}
|
||||
RemoveNotifyFd(trans_conn->fd);
|
||||
_XSERVTransClose(trans_conn);
|
||||
|
||||
Reference in New Issue
Block a user