[PATCH 1/3] os: Reshuffle the connection translation ifdefs

Adam Jackson ajax at redhat.com
Mon Dec 14 12:19:47 PST 2009


Use the wrapper functions consistently instead of hardcoding unix
knowledge everywhere directly.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 os/WaitFor.c    |    3 +--
 os/connection.c |   44 ++++++++++++++++++++------------------------
 os/io.c         |    2 +-
 os/osdep.h      |    6 +-----
 4 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/os/WaitFor.c b/os/WaitFor.c
index dfe85e5..7d10183 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -338,8 +338,7 @@ WaitForSomething(int *pClientsReady)
 	        int client_priority, client_index;
 
 		curclient = mffs (clientsReadable.fds_bits[i]) - 1;
-		client_index = /* raphael: modified */
-			ConnectionTranslation[curclient + (i * (sizeof(fd_mask) * 8))];
+                client_index = GetConnectionTranslation(curclient);
 #else
 	int highest_priority = 0;
 	fd_set savedClientsReadable;
diff --git a/os/connection.c b/os/connection.c
index 3ff93bb..bf16f6a 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -159,7 +159,7 @@ static fd_set SavedClientsWithInput;
 int GrabInProgress = 0;
 
 #if !defined(WIN32)
-int *ConnectionTranslation = NULL;
+static int *ConnectionTranslation = NULL;
 #else
 /*
  * On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is
@@ -179,15 +179,24 @@ struct _ct_node {
     int value;
 };
 
-struct _ct_node *ct_head[256];
+static struct _ct_node *ct_head[256];
+#endif
 
 void InitConnectionTranslation(void)
 {
+#ifndef WIN32
+    if (!ConnectionTranslation)
+        ConnectionTranslation = xnfalloc(sizeof(int)*(lastfdesc + 1));
+#else
     bzero(ct_head, sizeof(ct_head));
+#endif
 }
 
 int GetConnectionTranslation(int conn)
 {
+#ifndef WIN32
+    return ConnectionTranslation[conn];
+#else
     struct _ct_node *node = ct_head[conn & 0xff];
     while (node != NULL)
     {
@@ -196,10 +205,14 @@ int GetConnectionTranslation(int conn)
         node = node->next;
     }
     return 0;
+#endif
 }
 
 void SetConnectionTranslation(int conn, int client)
 {
+#ifndef WIN32
+    ConnectionTranslation[conn] = client;
+#else
     struct _ct_node **node = ct_head + (conn & 0xff);
     if (client == 0) /* remove entry */
     {
@@ -232,10 +245,14 @@ void SetConnectionTranslation(int conn, int client)
         (*node)->value = client;
         return;
     }
+#endif
 }
 
 void ClearConnectionTranslation(void)
 {
+#ifndef WIN32
+    for (i=0; i<MaxClients; i++) ConnectionTranslation[i] = 0;
+#else
     unsigned i;
     for (i = 0; i < 256; i++)
     {
@@ -247,8 +264,8 @@ void ClearConnectionTranslation(void)
             xfree(temp);
         }
     }
-}
 #endif
+}
 
 static XtransConnInfo 	*ListenTransConns = NULL;
 static int	       	*ListenTransFds = NULL;
@@ -314,12 +331,7 @@ InitConnectionLimits(void)
     ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients);
 #endif
 
-#if !defined(WIN32)
-    if (!ConnectionTranslation)
-        ConnectionTranslation = (int *)xnfalloc(sizeof(int)*(lastfdesc + 1));
-#else
     InitConnectionTranslation();
-#endif
 }
 
 /*
@@ -377,11 +389,7 @@ CreateWellKnownSockets(void)
     FD_ZERO(&LastSelectMask);
     FD_ZERO(&ClientsWithInput);
 
-#if !defined(WIN32)
-    for (i=0; i<MaxClients; i++) ConnectionTranslation[i] = 0;
-#else
     ClearConnectionTranslation();
-#endif
 
     FD_ZERO (&WellKnownConnections);
 
@@ -751,11 +759,7 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time)
 	xfree (oc);
 	return NullClient;
     }
-#if !defined(WIN32)
-    ConnectionTranslation[fd] = client->index;
-#else
     SetConnectionTranslation(fd, client->index);
-#endif
     if (GrabInProgress)
     {
         FD_SET(fd, &SavedAllClients);
@@ -845,11 +849,7 @@ EstablishNewConnections(ClientPtr clientUnused, pointer closure)
 	if (newconn < lastfdesc)
 	{
 		int clientid;
-#if !defined(WIN32)
-  		clientid = ConnectionTranslation[newconn];
-#else
   		clientid = GetConnectionTranslation(newconn);
-#endif
 		if(clientid && (client = clients[clientid]))
  			CloseDownClient(client);
 	}
@@ -938,11 +938,7 @@ CloseDownFileDescriptor(OsCommPtr oc)
 	_XSERVTransDisconnect(oc->trans_conn);
 	_XSERVTransClose(oc->trans_conn);
     }
-#ifndef WIN32
-    ConnectionTranslation[connection] = 0;
-#else
     SetConnectionTranslation(connection, 0);
-#endif    
     FD_CLR(connection, &AllSockets);
     FD_CLR(connection, &AllClients);
     FD_CLR(connection, &ClientsWithInput);
diff --git a/os/io.c b/os/io.c
index 64b64ae..2e8d1a0 100644
--- a/os/io.c
+++ b/os/io.c
@@ -633,7 +633,7 @@ FlushAllOutput(void)
 	{
 	    index = ffs(mask) - 1;
 	    mask &= ~lowbit(mask);
-	    if ((index = ConnectionTranslation[(base * (sizeof(fd_mask)*8)) + index]) == 0)
+            if ((index = GetConnectionTranslation(index)) == 0)
 		continue;
 	    client = clients[index];
 	    if (client->clientGone)
diff --git a/os/osdep.h b/os/osdep.h
index 3d75bba..4ebe0e9 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -195,13 +195,9 @@ extern fd_set ClientsWriteBlocked;
 extern fd_set OutputPending;
 extern fd_set IgnoredClientsWithInput;
 
-#ifndef WIN32
-extern int *ConnectionTranslation;
-#else
 extern int GetConnectionTranslation(int conn);
 extern void SetConnectionTranslation(int conn, int client);
-extern void ClearConnectionTranslation();
-#endif
+extern void ClearConnectionTranslation(void);
  
 extern Bool NewOutputPending;
 extern Bool AnyClientsWriteBlocked;
-- 
1.6.5.2



More information about the xorg-devel mailing list