diff --git a/os/connection.c b/os/connection.c index bc35a60..68bdf43 100644 --- a/os/connection.c +++ b/os/connection.c @@ -122,6 +122,7 @@ int *ListenTransFds = NULL; int ListenTransCount; +extern int xfd_ffs (fd_mask); static void error_conn_max(XtransConnInfo trans_conn); static void close_fd(OsCommPtr oc); @@ -316,7 +318,7 @@ MakeNewConnections(void) XtransConnInfo trans_conn, new_trans_conn; int status; - curconn = ffs(readyconnections) - 1; + curconn = xfd_ffs(readyconnections) - 1; readyconnections &= ~(1 << curconn); if ((trans_conn = lookup_trans_conn (curconn)) == NULL) @@ -454,7 +456,7 @@ CheckConnections(void) XFD_COPYSET(&AllClients, &mask); for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) { while (mask.fds_bits[i]) { - curclient = ffs(mask.fds_bits[i]) - 1 + (i << 5); + curclient = xfd_ffs(mask.fds_bits[i]) - 1 + (i * (sizeof(fd_mask) * 8)); FD_ZERO(&tmask); FD_SET(curclient, &tmask); r = Select(curclient + 1, &tmask, NULL, NULL, ¬ime); diff --git a/os/io.c b/os/io.c index 13c7fe4..8d9659a 100644 --- a/os/io.c +++ b/os/io.c @@ -86,6 +86,7 @@ static ConnectionInputPtr FreeInputs = (ConnectionInputPtr) NULL; static ConnectionOutputPtr FreeOutputs = (ConnectionOutputPtr) NULL; static OsCommPtr AvailableInput = (OsCommPtr) NULL; +extern int xfd_ffs(fd_mask); static ConnectionInputPtr AllocateInputBuffer(void); static ConnectionOutputPtr AllocateOutputBuffer(void); @@ -524,9 +525,9 @@ FlushAllOutput(void) mask = OutputPending.fds_bits[base]; OutputPending.fds_bits[base] = 0; while (mask) { - index = ffs(mask) - 1; + index = xfd_ffs(mask) - 1; mask &= ~lowbit(mask); - if ((index = ConnectionTranslation[(base << 5) + index]) == 0) + if ((index = ConnectionTranslation[(base * (sizeof(fd_mask) * 8)) + index]) == 0) continue; client = clients[index]; if (client->clientGone == CLIENT_GONE) diff --git a/os/waitfor.c b/os/waitfor.c index 1a29a97..4e80eba 100644 --- a/os/waitfor.c +++ b/os/waitfor.c @@ -67,10 +67,12 @@ in this Software without prior written authorization from The Open Group. #endif long LastReapTime; +int xfd_ffs(fd_mask); + /* like ffs, but uses fd_mask instead of int as argument, so it works when fd_mask is longer than an int, such as common 64-bit platforms */ -static inline int +int xfd_ffs(fd_mask mask) { int i; @@ -195,7 +197,7 @@ WaitForSomething(int *pClientsReady) for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) { while (clientsReadable.fds_bits[i]) { curclient = xfd_ffs(clientsReadable.fds_bits[i]) - 1; - conn = ConnectionTranslation[curclient + (i << 5)]; + conn = ConnectionTranslation[curclient + (i * (sizeof(fd_mask) * 8))]; clientsReadable.fds_bits[i] &= ~(((fd_mask)1L) << curclient); client = clients[conn]; if (!client)