[PATCH xserver 25/25] os: eliminate fd value limits for clients

Keith Packard keithp at keithp.com
Wed May 25 05:39:02 UTC 2016


With no code depending on the range of file descriptors, checking
for that can be eliminated.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 os/connection.c | 74 ++++++++++++---------------------------------------------
 os/osdep.h      | 37 ++++++-----------------------
 2 files changed, 22 insertions(+), 89 deletions(-)

diff --git a/os/connection.c b/os/connection.c
index c9e56b7..96f6971 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,12 +118,9 @@ SOFTWARE.
 
 #include "probes.h"
 
-static int lastfdesc;           /* maximum file descriptor */
-
 struct ospoll   server_poll;
 
 int MaxClients = 0;
-int NumNotifyWriteFd;           /* Number of NotifyFd members with write set */
 Bool NewOutputPending;          /* not yet attempted to write some new output */
 Bool NoListenAll;               /* Don't establish any listening sockets */
 
@@ -135,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
@@ -150,6 +144,7 @@ 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
@@ -264,44 +259,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 > 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
@@ -382,7 +350,7 @@ CreateWellKnownSockets(void)
     ospoll_fd_init(&server_poll);
 
 #if !defined(WIN32)
-    for (i = 0; i < MaxClients; i++)
+    for (i = 0; i < ConnectionTranslationSize; i++)
         ConnectionTranslation[i] = 0;
 #else
     ClearConnectionTranslation();
@@ -741,14 +709,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;
@@ -765,6 +725,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);
@@ -801,6 +765,7 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
     OsCommPtr oc;
     XtransConnInfo trans_conn, new_trans_conn;
     int status;
+    int clientid;
 
     connect_time = GetTimeInMillis();
     /* kill off stragglers */
@@ -822,17 +787,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);
 
@@ -1002,7 +959,6 @@ InitNotifyFds(void)
             RemoveNotifyFd(s->fd);
 
     xorg_list_init(&notify_fds);
-    NumNotifyWriteFd = 0;
     been_here = 1;
 }
 
diff --git a/os/osdep.h b/os/osdep.h
index ec8158e..1b87c0f 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -64,37 +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.
- */
-
-#define MAXSOCKS OPEN_MAX
-#define MAXSELECT MAXSOCKS
-
 #include <stddef.h>
+#include <X11/Xos.h>
 
 #if defined(XDMCP) || defined(HASXDMAUTH)
 typedef Bool (*ValidatorFunc) (ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type);
@@ -199,6 +170,12 @@ ospoll_fd_revents(struct ospoll *ospoll, int fd);
 
 #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



More information about the xorg-devel mailing list