]> git.saurik.com Git - apple/libinfo.git/blobdiff - rpc.subproj/svc_tcp.c
Libinfo-222.3.3.tar.gz
[apple/libinfo.git] / rpc.subproj / svc_tcp.c
index 8828b639327b2c67a739c57bd04e7a9c0bef881f..59303fe07717af8f1df51acebac10277fc4168d4 100644 (file)
@@ -53,7 +53,7 @@
 #if defined(LIBC_SCCS) && !defined(lint)
 /*static char *sccsid = "from: @(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
 /*static char *sccsid = "from: @(#)svc_tcp.c   2.2 88/08/01 4.0 RPCSRC";*/
-static char *rcsid = "$Id: svc_tcp.c,v 1.2 1999/10/14 21:56:54 wsanchez Exp $";
+static char *rcsid = "$Id: svc_tcp.c,v 1.6 2004/06/11 16:28:07 majka Exp $";
 #endif
 
 /*
@@ -67,11 +67,16 @@ static char *rcsid = "$Id: svc_tcp.c,v 1.2 1999/10/14 21:56:54 wsanchez Exp $";
  */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include <rpc/rpc.h>
 #include <sys/socket.h>
 #include <errno.h>
-extern bool_t abort();
-extern errno;
+
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+
+extern int             bindresvport();
 
 /*
  * Ops vector for TCP/IP based rpc service handle
@@ -95,15 +100,16 @@ static struct xp_ops svctcp_op = {
 /*
  * Ops vector for TCP/IP rendezvous handler
  */
+static bool_t          rendezvous_abort();
 static bool_t          rendezvous_request();
 static enum xprt_stat  rendezvous_stat();
 
 static struct xp_ops svctcp_rendezvous_op = {
        rendezvous_request,
        rendezvous_stat,
-       abort,
-       abort,
-       abort,
+       rendezvous_abort,
+       rendezvous_abort,
+       rendezvous_abort,
        svctcp_destroy
 };
 
@@ -246,6 +252,13 @@ makefd_xprt(fd, sendsize, recvsize)
        return (xprt);
 }
 
+static bool_t
+rendezvous_abort()
+{       
+       abort();
+       return (FALSE);
+}
+
 static bool_t
 rendezvous_request(xprt)
        register SVCXPRT *xprt;
@@ -305,6 +318,8 @@ svctcp_destroy(xprt)
  */
 static struct timeval wait_per_try = { 35, 0 };
 
+extern int svc_maxfd;
+
 /*
  * reads data from the tcp conection.
  * any error is fatal and the connection is closed.
@@ -317,27 +332,29 @@ readtcp(xprt, buf, len)
        register int len;
 {
        register int sock = xprt->xp_sock;
-       fd_set mask;
        fd_set readfds;
-
-       FD_ZERO(&mask);
-       FD_SET(sock, &mask);
-       do {
-               readfds = mask;
-               if (select(sock+1, &readfds, (int*)NULL, (int*)NULL, 
-                          &wait_per_try) <= 0) {
-                       if (errno == EINTR) {
-                               continue;
-                       }
+       bool_t ready = FALSE;
+
+       do
+       {
+               FD_COPY(&svc_fdset, &readfds);
+               FD_SET(sock, &readfds);
+               if (select(max(svc_maxfd, sock) + 1, &readfds, NULL, NULL, &wait_per_try) <= 0)
+               {
+                       if (errno == EINTR) continue;
                        goto fatal_err;
                }
-       } while (!FD_ISSET(sock, &readfds));
-       if ((len = read(sock, buf, len)) > 0) {
-               return (len);
-       }
+               else if (FD_ISSET(sock, &readfds))
+               {
+                       ready = TRUE;
+               }
+       } while (!ready);
+
+       if ((len = read(sock, buf, len)) > 0) return len;
+
 fatal_err:
        ((struct tcp_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED;
-       return (-1);
+       return -1;
 }
 
 /*