os: Eliminate ConnectionTranslation

This infrastructure is no longer read, only written; the mapping
from fd to client is now handled by ospoll.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2017-05-17 09:57:25 -07:00 committed by Adam Jackson
parent c86fc56b10
commit 5d941ccb0b
2 changed files with 1 additions and 140 deletions

View File

@ -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);
}

View File

@ -141,20 +141,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;