[PATCH xserver 1/5] os: Eliminate ConnectionTranslation
Keith Packard
keithp at keithp.com
Wed May 17 16:57:25 UTC 2017
This infrastructure is no longer read, only written; the mapping
from fd to client is now handled by ospoll.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
os/connection.c | 127 +-------------------------------------------------------
os/osdep.h | 14 -------
2 files changed, 1 insertion(+), 140 deletions(-)
diff --git a/os/connection.c b/os/connection.c
index 62e298072..66cb61070 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -142,96 +142,6 @@ set_poll_client(ClientPtr client);
static void
set_poll_clients(void);
-#if !defined(WIN32)
-int *ConnectionTranslation = NULL;
-int ConnectionTranslationSize = 0;
-#else
-/*
- * 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.
- */
-
-struct _ct_node {
- struct _ct_node *next;
- int key;
- int value;
-};
-
-struct _ct_node *ct_head[256];
-
-void
-InitConnectionTranslation(void)
-{
- memset(ct_head, 0, sizeof(ct_head));
-}
-
-int
-GetConnectionTranslation(int conn)
-{
- struct _ct_node *node = ct_head[conn & 0xff];
-
- while (node != NULL) {
- if (node->key == conn)
- return node->value;
- node = node->next;
- }
- return 0;
-}
-
-void
-SetConnectionTranslation(int conn, int client)
-{
- struct _ct_node **node = ct_head + (conn & 0xff);
-
- if (client == 0) { /* remove entry */
- while (*node != NULL) {
- if ((*node)->key == conn) {
- struct _ct_node *temp = *node;
-
- *node = (*node)->next;
- free(temp);
- return;
- }
- node = &((*node)->next);
- }
- return;
- }
- else {
- while (*node != NULL) {
- if ((*node)->key == conn) {
- (*node)->value = client;
- return;
- }
- node = &((*node)->next);
- }
- *node = malloc(sizeof(struct _ct_node));
- (*node)->next = NULL;
- (*node)->key = conn;
- (*node)->value = client;
- return;
- }
-}
-
-void
-ClearConnectionTranslation(void)
-{
- unsigned i;
-
- for (i = 0; i < 256; i++) {
- struct _ct_node *node = ct_head[i];
-
- while (node != NULL) {
- struct _ct_node *temp = node;
-
- node = node->next;
- free(temp);
- }
- }
-}
-#endif
-
static XtransConnInfo *ListenTransConns = NULL;
static int *ListenTransFds = NULL;
static int ListenTransCount;
@@ -252,7 +162,7 @@ lookup_trans_conn(int fd)
return NULL;
}
-/* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */
+/* Set MaxClients */
void
InitConnectionLimits(void)
@@ -262,15 +172,6 @@ InitConnectionLimits(void)
#ifdef DEBUG
ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients);
#endif
-
-#if !defined(WIN32)
- if (!ConnectionTranslation) {
- ConnectionTranslation = xnfallocarray(MaxClients, sizeof(int));
- ConnectionTranslationSize = MaxClients;
- }
-#else
- InitConnectionTranslation();
-#endif
}
/*
@@ -345,13 +246,6 @@ CreateWellKnownSockets(void)
int i;
int partial;
-#if !defined(WIN32)
- for (i = 0; i < ConnectionTranslationSize; i++)
- ConnectionTranslation[i] = 0;
-#else
- ClearConnectionTranslation();
-#endif
-
/* display is initialized to "0" by main(). It is then set to the display
* number if specified on the command line. */
@@ -737,15 +631,6 @@ AllocNewConnection(XtransConnInfo trans_conn, int fd, CARD32 conn_time)
return NullClient;
}
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);
-#endif
ospoll_add(server_poll, fd,
ospoll_trigger_edge,
ClientReady,
@@ -781,7 +666,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
OsCommPtr oc;
XtransConnInfo trans_conn, new_trans_conn;
int status;
- int clientid;
connect_time = GetTimeInMillis();
/* kill off stragglers */
@@ -803,10 +687,6 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
newconn = _XSERVTransGetConnectionNumber(new_trans_conn);
- clientid = GetConnectionTranslation(newconn);
- if (clientid && (client = clients[clientid]))
- CloseDownClient(client);
-
_XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1);
if (trans_conn->flags & TRANS_NOXAUTH)
@@ -889,11 +769,6 @@ CloseDownFileDescriptor(OsCommPtr oc)
_XSERVTransDisconnect(oc->trans_conn);
_XSERVTransClose(oc->trans_conn);
}
-#ifndef WIN32
- ConnectionTranslation[connection] = 0;
-#else
- SetConnectionTranslation(connection, 0);
-#endif
ospoll_remove(server_poll, connection);
}
diff --git a/os/osdep.h b/os/osdep.h
index a0d57b8db..5545dd6bd 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -148,20 +148,6 @@ extern struct ospoll *server_poll;
Bool
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);
-extern void ClearConnectionTranslation(void);
-#endif
-
extern Bool NewOutputPending;
extern WorkQueuePtr workQueue;
--
2.11.0
More information about the xorg-devel
mailing list