With no code depending on the range of file descriptors, checking for that can be eliminated.
Signed-off-by: Keith Packard <kei...@keithp.com> --- os/connection.c | 81 ++++++++++++--------------------------------------------- os/osdep.h | 43 +++++------------------------- 2 files changed, 23 insertions(+), 101 deletions(-) diff --git a/os/connection.c b/os/connection.c index 1ae50b1..24ad109 100644 --- a/os/connection.c +++ b/os/connection.c @@ -103,7 +103,6 @@ SOFTWARE. #endif /* WIN32 */ #include "misc.h" /* for typedef of pointer */ #include "osdep.h" -#include <X11/Xpoll.h> #include "opaque.h" #include "dixstruct.h" #include "xace.h" @@ -119,7 +118,6 @@ SOFTWARE. #include "probes.h" -static int lastfdesc; /* maximum file descriptor */ struct ospoll *server_poll; int MaxClients = 0; @@ -133,8 +131,6 @@ static char dynamic_display[7]; /* display name */ Bool PartialNetwork; /* continue even if unable to bind all addrs */ static Pid_t ParentProcess; -static Bool debug_conns = FALSE; - int GrabInProgress = 0; static void @@ -148,19 +144,15 @@ set_poll_clients(void); #if !defined(WIN32) int *ConnectionTranslation = NULL; +int ConnectionTranslationSize = 0; #else /* - * On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is + * On NT fds are not small integers, they are unrelated, and there is * not even a known maximum value, so use something quite arbitrary for now. * Do storage is a hash table of size 256. Collisions are handled in a linked * list. */ -#undef MAXSOCKS -#define MAXSOCKS 512 -#undef MAXSELECT -#define MAXSELECT 512 - struct _ct_node { struct _ct_node *next; int key; @@ -265,47 +257,17 @@ lookup_trans_conn(int fd) void InitConnectionLimits(void) { - lastfdesc = -1; - -#ifndef __CYGWIN__ - -#if !defined(XNO_SYSCONF) && defined(_SC_OPEN_MAX) - lastfdesc = sysconf(_SC_OPEN_MAX) - 1; -#endif - -#ifdef HAVE_GETDTABLESIZE - if (lastfdesc < 0) - lastfdesc = getdtablesize() - 1; -#endif - -#ifdef _NFILE - if (lastfdesc < 0) - lastfdesc = _NFILE - 1; -#endif - -#endif /* __CYGWIN__ */ - - /* This is the fallback */ - if (lastfdesc < 0) - lastfdesc = MAXSOCKS; - - if (lastfdesc > MAXSELECT) - lastfdesc = MAXSELECT; - - if (lastfdesc > MAXCLIENTS) { - lastfdesc = MAXCLIENTS; - if (debug_conns) - ErrorF("REACHED MAXIMUM CLIENTS LIMIT %d\n", LimitClients); - } - MaxClients = lastfdesc; + MaxClients = MAXCLIENTS; #ifdef DEBUG ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients); #endif #if !defined(WIN32) - if (!ConnectionTranslation) - ConnectionTranslation = xnfallocarray(lastfdesc + 1, sizeof(int)); + if (!ConnectionTranslation) { + ConnectionTranslation = xnfallocarray(MaxClients, sizeof(int)); + ConnectionTranslationSize = MaxClients; + } #else InitConnectionTranslation(); #endif @@ -388,7 +350,7 @@ CreateWellKnownSockets(void) FatalError("failed to allocate poll structure"); #if !defined(WIN32) - for (i = 0; i < MaxClients; i++) + for (i = 0; i < ConnectionTranslationSize; i++) ConnectionTranslation[i] = 0; #else ClearConnectionTranslation(); @@ -762,14 +724,6 @@ AllocNewConnection(XtransConnInfo trans_conn, int fd, CARD32 conn_time) OsCommPtr oc; ClientPtr client; - if ( -#ifndef WIN32 - fd >= lastfdesc -#else - XFD_SETCOUNT(&AllClients) >= MaxClients -#endif - ) - return NullClient; oc = malloc(sizeof(OsCommRec)); if (!oc) return NullClient; @@ -786,6 +740,10 @@ AllocNewConnection(XtransConnInfo trans_conn, int fd, CARD32 conn_time) } client->local = ComputeLocalClient(client); #if !defined(WIN32) + if (fd >= ConnectionTranslationSize) { + ConnectionTranslationSize *= 2; + ConnectionTranslation = xnfreallocarray(ConnectionTranslation, ConnectionTranslationSize, sizeof (int)); + } ConnectionTranslation[fd] = client->index; #else SetConnectionTranslation(fd, client->index); @@ -825,6 +783,7 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure) OsCommPtr oc; XtransConnInfo trans_conn, new_trans_conn; int status; + int clientid; connect_time = GetTimeInMillis(); /* kill off stragglers */ @@ -846,17 +805,9 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure) newconn = _XSERVTransGetConnectionNumber(new_trans_conn); - if (newconn < lastfdesc) { - int clientid; - -#if !defined(WIN32) - clientid = ConnectionTranslation[newconn]; -#else - clientid = GetConnectionTranslation(newconn); -#endif - if (clientid && (client = clients[clientid])) - CloseDownClient(client); - } + clientid = GetConnectionTranslation(newconn); + if (clientid && (client = clients[clientid])) + CloseDownClient(client); _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1); diff --git a/os/osdep.h b/os/osdep.h index d44df76..8d89f35 100644 --- a/os/osdep.h +++ b/os/osdep.h @@ -64,43 +64,8 @@ SOFTWARE. #endif #include <poll.h> - -#ifndef OPEN_MAX -#ifdef SVR4 -#define OPEN_MAX 512 -#else -#include <sys/param.h> -#ifndef OPEN_MAX -#if defined(NOFILE) && !defined(NOFILES_MAX) -#define OPEN_MAX NOFILE -#else -#if !defined(WIN32) || defined(__CYGWIN__) -#define OPEN_MAX NOFILES_MAX -#else -#define OPEN_MAX 512 -#endif -#endif -#endif -#endif -#endif - -#include <X11/Xpoll.h> - -/* - * MAXSOCKS is used only for initialising MaxClients when no other method - * like sysconf(_SC_OPEN_MAX) is not supported. - */ - -#if OPEN_MAX <= 512 -#define MAXSOCKS (OPEN_MAX - 1) -#else -#define MAXSOCKS 512 -#endif - -/* MAXSELECT is the number of fds that select() can handle */ -#define MAXSELECT (sizeof(fd_set) * NBBY) - #include <stddef.h> +#include <X11/Xos.h> #if defined(XDMCP) || defined(HASXDMAUTH) typedef Bool (*ValidatorFunc) (ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type); @@ -175,6 +140,12 @@ listen_to_client(ClientPtr client); #if !defined(WIN32) || defined(__CYGWIN__) extern int *ConnectionTranslation; +extern int ConnectionTranslationSize; +static inline int GetConnectionTranslation(int conn) { + if (conn >= ConnectionTranslationSize) + return 0; + return ConnectionTranslation[conn]; +} #else extern int GetConnectionTranslation(int conn); extern void SetConnectionTranslation(int conn, int client); -- 2.8.0.rc3 _______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: https://lists.x.org/mailman/listinfo/xorg-devel