os: Use NotifyFd interface for listen descriptors
Replace the custom path for dealing with new incoming connections with the general-purpose NotifyFd API. Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
1df07dc36c
commit
7b02f0b87e
|
@ -139,9 +139,6 @@ extern _X_EXPORT const char *ClientAuthorized(ClientPtr /*client */ ,
|
||||||
unsigned int /*string_n */ ,
|
unsigned int /*string_n */ ,
|
||||||
char * /*auth_string */ );
|
char * /*auth_string */ );
|
||||||
|
|
||||||
extern _X_EXPORT Bool EstablishNewConnections(ClientPtr clientUnused,
|
|
||||||
void *closure);
|
|
||||||
|
|
||||||
extern _X_EXPORT void CheckConnections(void);
|
extern _X_EXPORT void CheckConnections(void);
|
||||||
|
|
||||||
extern _X_EXPORT void CloseDownConnection(ClientPtr /*client */ );
|
extern _X_EXPORT void CloseDownConnection(ClientPtr /*client */ );
|
||||||
|
|
|
@ -311,10 +311,6 @@ WaitForSomething(int *pClientsReady)
|
||||||
|
|
||||||
XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices);
|
XFD_ANDSET(&devicesReadable, &LastSelectMask, &EnabledDevices);
|
||||||
XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients);
|
XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients);
|
||||||
XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections);
|
|
||||||
if (XFD_ANYSET(&tmp_set))
|
|
||||||
QueueWorkProc(EstablishNewConnections, NULL,
|
|
||||||
(void *) &LastSelectMask);
|
|
||||||
|
|
||||||
XFD_ANDSET(&tmp_set, &LastSelectMask, &NotifyReadFds);
|
XFD_ANDSET(&tmp_set, &LastSelectMask, &NotifyReadFds);
|
||||||
if (XFD_ANYSET(&tmp_set) || someNotifyWriteReady)
|
if (XFD_ANYSET(&tmp_set) || someNotifyWriteReady)
|
||||||
|
|
|
@ -121,7 +121,6 @@ SOFTWARE.
|
||||||
|
|
||||||
static int lastfdesc; /* maximum file descriptor */
|
static int lastfdesc; /* maximum file descriptor */
|
||||||
|
|
||||||
fd_set WellKnownConnections; /* Listener mask */
|
|
||||||
fd_set EnabledDevices; /* mask for input devices that are on */
|
fd_set EnabledDevices; /* mask for input devices that are on */
|
||||||
fd_set NotifyReadFds; /* mask for other file descriptors */
|
fd_set NotifyReadFds; /* mask for other file descriptors */
|
||||||
fd_set NotifyWriteFds; /* mask for other write file descriptors */
|
fd_set NotifyWriteFds; /* mask for other write file descriptors */
|
||||||
|
@ -154,6 +153,9 @@ static fd_set SavedAllSockets;
|
||||||
static fd_set SavedClientsWithInput;
|
static fd_set SavedClientsWithInput;
|
||||||
int GrabInProgress = 0;
|
int GrabInProgress = 0;
|
||||||
|
|
||||||
|
static void
|
||||||
|
QueueNewConnections(int curconn, int ready, void *data);
|
||||||
|
|
||||||
#if !defined(WIN32)
|
#if !defined(WIN32)
|
||||||
int *ConnectionTranslation = NULL;
|
int *ConnectionTranslation = NULL;
|
||||||
#else
|
#else
|
||||||
|
@ -403,8 +405,6 @@ CreateWellKnownSockets(void)
|
||||||
ClearConnectionTranslation();
|
ClearConnectionTranslation();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FD_ZERO(&WellKnownConnections);
|
|
||||||
|
|
||||||
/* display is initialized to "0" by main(). It is then set to the display
|
/* display is initialized to "0" by main(). It is then set to the display
|
||||||
* number if specified on the command line. */
|
* number if specified on the command line. */
|
||||||
|
|
||||||
|
@ -441,13 +441,13 @@ CreateWellKnownSockets(void)
|
||||||
int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
||||||
|
|
||||||
ListenTransFds[i] = fd;
|
ListenTransFds[i] = fd;
|
||||||
FD_SET(fd, &WellKnownConnections);
|
SetNotifyFd(fd, QueueNewConnections, X_NOTIFY_READ, NULL);
|
||||||
|
|
||||||
if (!_XSERVTransIsLocal(ListenTransConns[i]))
|
if (!_XSERVTransIsLocal(ListenTransConns[i]))
|
||||||
DefineSelf (fd);
|
DefineSelf (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!XFD_ANYSET(&WellKnownConnections) && !NoListenAll)
|
if (ListenTransCount == 0 && !NoListenAll)
|
||||||
FatalError
|
FatalError
|
||||||
("Cannot establish any listening sockets - Make sure an X server isn't already running");
|
("Cannot establish any listening sockets - Make sure an X server isn't already running");
|
||||||
|
|
||||||
|
@ -457,7 +457,6 @@ CreateWellKnownSockets(void)
|
||||||
#endif
|
#endif
|
||||||
OsSignal(SIGINT, GiveUp);
|
OsSignal(SIGINT, GiveUp);
|
||||||
OsSignal(SIGTERM, GiveUp);
|
OsSignal(SIGTERM, GiveUp);
|
||||||
XFD_COPYSET(&WellKnownConnections, &AllSockets);
|
|
||||||
ResetHosts(display);
|
ResetHosts(display);
|
||||||
|
|
||||||
InitParentProcess();
|
InitParentProcess();
|
||||||
|
@ -484,7 +483,7 @@ ResetWellKnownSockets(void)
|
||||||
* Remove it from out list.
|
* Remove it from out list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FD_CLR(ListenTransFds[i], &WellKnownConnections);
|
RemoveNotifyFd(ListenTransFds[i]);
|
||||||
ListenTransFds[i] = ListenTransFds[ListenTransCount - 1];
|
ListenTransFds[i] = ListenTransFds[ListenTransCount - 1];
|
||||||
ListenTransConns[i] = ListenTransConns[ListenTransCount - 1];
|
ListenTransConns[i] = ListenTransConns[ListenTransCount - 1];
|
||||||
ListenTransCount -= 1;
|
ListenTransCount -= 1;
|
||||||
|
@ -497,12 +496,12 @@ ResetWellKnownSockets(void)
|
||||||
|
|
||||||
int newfd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
int newfd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
||||||
|
|
||||||
FD_CLR(ListenTransFds[i], &WellKnownConnections);
|
|
||||||
ListenTransFds[i] = newfd;
|
ListenTransFds[i] = newfd;
|
||||||
FD_SET(newfd, &WellKnownConnections);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (i = 0; i < ListenTransCount; i++)
|
||||||
|
SetNotifyFd(ListenTransFds[i], QueueNewConnections, X_NOTIFY_READ, NULL);
|
||||||
|
|
||||||
ResetAuthorization();
|
ResetAuthorization();
|
||||||
ResetHosts(display);
|
ResetHosts(display);
|
||||||
|
@ -523,6 +522,7 @@ CloseWellKnownConnections(void)
|
||||||
if (ListenTransConns[i] != NULL) {
|
if (ListenTransConns[i] != NULL) {
|
||||||
_XSERVTransClose(ListenTransConns[i]);
|
_XSERVTransClose(ListenTransConns[i]);
|
||||||
ListenTransConns[i] = NULL;
|
ListenTransConns[i] = NULL;
|
||||||
|
RemoveNotifyFd(ListenTransFds[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListenTransCount = 0;
|
ListenTransCount = 0;
|
||||||
|
@ -810,22 +810,18 @@ AllocNewConnection(XtransConnInfo trans_conn, int fd, CARD32 conn_time)
|
||||||
* and AllSockets.
|
* and AllSockets.
|
||||||
*****************/
|
*****************/
|
||||||
|
|
||||||
/*ARGSUSED*/ Bool
|
static Bool
|
||||||
EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
||||||
{
|
{
|
||||||
fd_set readyconnections; /* set of listeners that are ready */
|
int curconn = (int) (intptr_t) closure;
|
||||||
int curconn; /* fd of listener that's ready */
|
int newconn; /* fd of new client */
|
||||||
register int newconn; /* fd of new client */
|
|
||||||
CARD32 connect_time;
|
CARD32 connect_time;
|
||||||
register int i;
|
int i;
|
||||||
register ClientPtr client;
|
ClientPtr client;
|
||||||
register OsCommPtr oc;
|
OsCommPtr oc;
|
||||||
fd_set tmask;
|
XtransConnInfo trans_conn, new_trans_conn;
|
||||||
|
int status;
|
||||||
|
|
||||||
XFD_ANDSET(&tmask, (fd_set *) closure, &WellKnownConnections);
|
|
||||||
XFD_COPYSET(&tmask, &readyconnections);
|
|
||||||
if (!XFD_ANYSET(&readyconnections))
|
|
||||||
return TRUE;
|
|
||||||
connect_time = GetTimeInMillis();
|
connect_time = GetTimeInMillis();
|
||||||
/* kill off stragglers */
|
/* kill off stragglers */
|
||||||
for (i = 1; i < currentMaxClients; i++) {
|
for (i = 1; i < currentMaxClients; i++) {
|
||||||
|
@ -837,29 +833,12 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
||||||
CloseDownClient(client);
|
CloseDownClient(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef WIN32
|
|
||||||
for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
|
|
||||||
while (readyconnections.fds_bits[i])
|
|
||||||
#else
|
|
||||||
for (i = 0; i < XFD_SETCOUNT(&readyconnections); i++)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
XtransConnInfo trans_conn, new_trans_conn;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
curconn = mffs(readyconnections.fds_bits[i]) - 1;
|
|
||||||
readyconnections.fds_bits[i] &= ~((fd_mask) 1 << curconn);
|
|
||||||
curconn += (i * (sizeof(fd_mask) * 8));
|
|
||||||
#else
|
|
||||||
curconn = XFD_FD(&readyconnections, i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((trans_conn = lookup_trans_conn(curconn)) == NULL)
|
if ((trans_conn = lookup_trans_conn(curconn)) == NULL)
|
||||||
continue;
|
return TRUE;
|
||||||
|
|
||||||
if ((new_trans_conn = _XSERVTransAccept(trans_conn, &status)) == NULL)
|
if ((new_trans_conn = _XSERVTransAccept(trans_conn, &status)) == NULL)
|
||||||
continue;
|
return TRUE;
|
||||||
|
|
||||||
newconn = _XSERVTransGetConnectionNumber(new_trans_conn);
|
newconn = _XSERVTransGetConnectionNumber(new_trans_conn);
|
||||||
|
|
||||||
|
@ -884,13 +863,15 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
||||||
ErrorConnMax(new_trans_conn);
|
ErrorConnMax(new_trans_conn);
|
||||||
_XSERVTransClose(new_trans_conn);
|
_XSERVTransClose(new_trans_conn);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#ifndef WIN32
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
QueueNewConnections(int fd, int ready, void *data)
|
||||||
|
{
|
||||||
|
QueueWorkProc(EstablishNewConnections, NULL, (void *) (intptr_t) fd);
|
||||||
|
}
|
||||||
|
|
||||||
#define NOROOM "Maximum number of clients reached"
|
#define NOROOM "Maximum number of clients reached"
|
||||||
|
|
||||||
/************
|
/************
|
||||||
|
@ -1417,8 +1398,7 @@ ListenOnOpenFD(int fd, int noxauth)
|
||||||
ListenTransConns[ListenTransCount] = ciptr;
|
ListenTransConns[ListenTransCount] = ciptr;
|
||||||
ListenTransFds[ListenTransCount] = fd;
|
ListenTransFds[ListenTransCount] = fd;
|
||||||
|
|
||||||
FD_SET(fd, &WellKnownConnections);
|
SetNotifyFd(fd, QueueNewConnections, X_NOTIFY_READ, NULL);
|
||||||
FD_SET(fd, &AllSockets);
|
|
||||||
|
|
||||||
/* Increment the count */
|
/* Increment the count */
|
||||||
ListenTransCount++;
|
ListenTransCount++;
|
||||||
|
|
Loading…
Reference in New Issue