From: chip Date: Mon, 13 Mar 2000 22:23:26 +0000 (+0000) Subject: Conserve sockets: Reuse RPC transports. X-Git-Tag: nfs-utils-0-1-7-1~5 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=6a66bb69d8fdb43f0abb58fd74566461f0e96633;p=nfs-utils.git Conserve sockets: Reuse RPC transports. --- diff --git a/ChangeLog b/ChangeLog index 0daf977..753a073 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2000-03-13 H.J. Lu +2000-03-12 Chip Salzenberg + Neil Brown + + * support/nfs/rpcmisc.c (rpc_init): Share transports. + +Wed Mar 8 09:42:43 EST 2000 Neil Brown * etc/redhat/nfsd.init: Updated. diff --git a/support/nfs/rpcmisc.c b/support/nfs/rpcmisc.c index 7b182fd..b994fb1 100644 --- a/support/nfs/rpcmisc.c +++ b/support/nfs/rpcmisc.c @@ -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) {