csa/agent.c: use select rather than poll
authorJon Trulson <jon@radscan.com>
Tue, 19 Jun 2012 22:51:25 +0000 (16:51 -0600)
committerJon Trulson <jon@radscan.com>
Tue, 19 Jun 2012 22:51:25 +0000 (16:51 -0600)
cde/lib/csa/agent.c

index 1fe9b833632d2bec426748a171cfb020700fb97b..b775b4113920345f753226b92e9cdd2525072af0 100644 (file)
 #include <unistd.h>
 #include <signal.h>
 #include <rpc/rpc.h>
-#if defined(linux)
+#if !defined(linux) && !defined(CSRG_BASED)
 # include <sys/poll.h>
-#else
-# include <poll.h>
 #endif
 #if defined(SunOS) || defined(USL) || defined(__uxp__)
 #include <netconfig.h>
@@ -203,6 +201,30 @@ _DtCm_destroy_agent()
 extern void
 _DtCm_process_updates()
 {
+#if defined(CSRG_BASED) || defined(linux) 
+        int     i, nfd;
+        fd_set  rpc_bits;
+
+        while (B_TRUE) {
+          rpc_bits = svc_fdset;
+
+          nfd = select(FD_SETSIZE, &rpc_bits, NULL, NULL, NULL);
+
+          if (nfd <= 0)
+            /* done */
+            return;
+
+          
+          for (i = 0; i < FD_SETSIZE; i++) {
+            if (FD_ISSET(i, &rpc_bits)) {
+              svc_getreqset(&rpc_bits);
+              break;
+            }
+          }
+        }
+
+#else
+
        int     i, j, nfd;
        fd_set  rpc_bits;
        fd_mask fmask, *inbits;
@@ -215,11 +237,7 @@ _DtCm_process_updates()
                rpc_bits = svc_fdset;
 
                /* convert to pollfd structure */
-#if defined(linux)
-               inbits = rpc_bits.__fds_bits;
-#else
                inbits = rpc_bits.fds_bits;
-#endif
                p = pfd;
                for (i = 0; i < FD_SETSIZE; i += NFDBITS) {
                        fmask = *inbits;
@@ -253,11 +271,7 @@ _DtCm_process_updates()
                for (p = pfd; i-- > 0; p++) {
                        j = p->fd / NFDBITS;
                        if (j != last) {
-#if defined(linux)
-                               inbits = &rpc_bits.__fds_bits[j];
-#else
                                inbits = &rpc_bits.fds_bits[j];
-#endif
                                last = j;
                        }
                        if (p->revents & POLLIN) {
@@ -269,6 +283,7 @@ _DtCm_process_updates()
                if (do_rpc)
                        svc_getreqset(&rpc_bits);
        }
+#endif /* CSRG_BASED || linux */
 }
 
 /*
@@ -397,7 +412,8 @@ gettransient (u_long version)
 static u_long
 gettransient (int proto, u_long vers, int *sockp)
 {
-       int s, len, socktype;
+        unsigned int len;
+       int s, socktype;
        struct sockaddr_in addr;
 
        switch (proto) {