Conserve sockets: Reuse RPC transports.
authorchip <chip>
Mon, 13 Mar 2000 22:23:26 +0000 (22:23 +0000)
committerchip <chip>
Mon, 13 Mar 2000 22:23:26 +0000 (22:23 +0000)
ChangeLog
support/nfs/rpcmisc.c

index 0daf977..753a073 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2000-03-13 H.J. Lu <hjl@lucon.org>
+2000-03-12  Chip Salzenberg  <chip@valinux.com>
+           Neil Brown  <neilb@cse.unsw.edu.au>
+
+       * support/nfs/rpcmisc.c (rpc_init): Share transports.
+
+Wed Mar  8 09:42:43 EST 2000 Neil Brown <neilb@cse.unsw.edu.au>
 
        * etc/redhat/nfsd.init: Updated.
 
index 7b182fd..b994fb1 100644 (file)
@@ -65,35 +65,53 @@ rpc_init(char *name, int prog, int vers, void (*dispatch)(), int defport,
        }
 
        if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
-               if (_rpcfdtype == 0 && defport != 0 &&
-                   ((sock = makesock(defport, IPPROTO_UDP, bufsiz)) < 0)) {
-                       xlog(L_FATAL, "%s: could not make a UDP socket\n",
-                                       name);
+               static SVCXPRT *last_transp = NULL;
+               if (_rpcfdtype == 0 && defport != 0) {
+                       if (last_transp && last_transp->xp_port == defport) {
+                               transp = last_transp;
+                               goto udp_transport;
+                       }
+                       if ((sock = makesock(defport, IPPROTO_UDP, bufsiz)) < 0) {
+                               xlog(L_FATAL, "%s: cannot make a UDP socket\n",
+                                               name);
+                       }
                }
                transp = svcudp_create(sock);
                if (transp == NULL) {
                        xlog(L_FATAL, "cannot create udp service.");
                }
+      udp_transport:
                if (!svc_register(transp, prog, vers, dispatch, IPPROTO_UDP)) {
                        xlog(L_FATAL, "unable to register (%s, %d, udp).",
                                        name, vers);
                }
+               last_transp = transp;
        }
 
        if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
-               if (_rpcfdtype == 0 && defport != 0 &&
-                   ((sock = makesock(defport, IPPROTO_TCP, bufsiz)) < 0)) {
-                       xlog(L_FATAL, "%s: could not make a TCP socket\n",
-                                       name);
+               static SVCXPRT *last_transp = NULL;
+
+               if (_rpcfdtype == 0 && defport != 0) {
+                       if (last_transp && last_transp->xp_port == defport) {
+                               transp = last_transp;
+                               goto tcp_transport;
+                       }
+                       if ((sock = makesock(defport, IPPROTO_TCP, bufsiz)) < 0) {
+                               xlog(L_FATAL, "%s: cannot make a TCP socket\n",
+                                               name);
+                       }
                }
                transp = svctcp_create(sock, 0, 0);
                if (transp == NULL) {
                        xlog(L_FATAL, "cannot create tcp service.");
                }
+      tcp_transport:
                if (!svc_register(transp, prog, vers, dispatch, IPPROTO_TCP)) {
                        xlog(L_FATAL, "unable to register (%s, %d, tcp).",
                                        name, vers);
                }
+               last_transp = transp;
        }
 
        if (_rpcpmstart) {