Implement nonblocking tpc-connections. rpcgen -m does still

produce backcompatible code.

Reviewed by:	rwatson
Obtained from:	NetBSD
MFC after:	1 day
This commit is contained in:
Martin Blapp 2003-01-16 07:27:30 +00:00
parent cf2acbc3a2
commit bcb53b1606
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109363
8 changed files with 68 additions and 13 deletions

View File

@ -636,6 +636,8 @@ s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
"#include <rpc/pmap_clnt.h> /* for pmap_unset */\n"); "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
f_print (fout, "#include <string.h> /* strcmp */\n"); f_print (fout, "#include <string.h> /* strcmp */\n");
} }
if (tirpcflag)
f_print(fout, "#include <rpc/rpc_com.h>\n");
if (strcmp(svcclosetime, "-1") == 0) if (strcmp(svcclosetime, "-1") == 0)
indefinitewait = 1; indefinitewait = 1;
else if (strcmp(svcclosetime, "0") == 0) else if (strcmp(svcclosetime, "0") == 0)

View File

@ -147,6 +147,11 @@ serviced */\n");
f_print(fout, "\nint\n"); f_print(fout, "\nint\n");
f_print(fout, "main()\n"); f_print(fout, "main()\n");
f_print(fout, "{\n"); f_print(fout, "{\n");
if (tirpcflag) {
if (!inetdflag)
f_print(fout, "\t");
f_print(fout, "\tint maxrec = RPC_MAXDATASIZE;\n");
}
if (inetdflag) { if (inetdflag) {
write_inetmost(infile); write_inetmost(infile);
/* Includes call to write_rpc_svc_fg() */ /* Includes call to write_rpc_svc_fg() */
@ -212,8 +217,15 @@ write_netid_register(transp)
print_err_message(tmpbuf); print_err_message(tmpbuf);
f_print(fout, "%s\t\texit(1);\n", sp); f_print(fout, "%s\t\texit(1);\n", sp);
f_print(fout, "%s\t}\n", sp); f_print(fout, "%s\t}\n", sp);
f_print(fout, "%s\t%s = svc_tli_create(RPC_ANYFD, nconf, 0, 0, 0);\n", if (tirpcflag) {
sp, TRANSP); f_print(fout, "%s\t%s = svc_tli_create(RPC_ANYFD, ",
sp, TRANSP);
f_print(fout,"nconf, 0, RPC_MAXDATASIZE, RPC_MAXDATASIZE);\n");
} else {
f_print(fout,
"%s\t%s = svc_tli_create(RPC_ANYFD, nconf, 0, 0, 0);\n",
sp, TRANSP);
}
f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP); f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
(void) sprintf(_errbuf, "cannot create %s service.", transp); (void) sprintf(_errbuf, "cannot create %s service.", transp);
print_err_message(tmpbuf); print_err_message(tmpbuf);
@ -261,6 +273,10 @@ write_nettype_register(transp)
if (def->def_kind != DEF_PROGRAM) { if (def->def_kind != DEF_PROGRAM) {
continue; continue;
} }
if (tirpcflag) {
f_print(fout,
"\trpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);\n");
}
for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
f_print(fout, "\tif (!svc_create("); f_print(fout, "\tif (!svc_create(");
pvname(def->def_name, vp->vers_num); pvname(def->def_name, vp->vers_num);
@ -937,10 +953,18 @@ getenv(\"NLSPROVIDER\")) == NULL) {\n");
f_print(fout, "\t\t\t}\n"); f_print(fout, "\t\t\t}\n");
f_print(fout, "\t\t}\n"); f_print(fout, "\t\t}\n");
} }
f_print(fout, if (tirpcflag) {
"\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) \ f_print(fout,
== NULL) {\n", "\t\tif ((%s = svc_tli_create(0, nconf, NULL, \
RPC_MAXDATASIZE, RPC_MAXDATASIZE)) \
== NULL) {\n",
TRANSP); TRANSP);
} else {
f_print(fout,
"\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) \
== NULL) {\n",
TRANSP);
}
sprintf(_errbuf, "cannot create server handle"); sprintf(_errbuf, "cannot create server handle");
print_err_message("\t\t\t"); print_err_message("\t\t\t");
f_print(fout, "\t\t\texit(1);\n"); f_print(fout, "\t\t\texit(1);\n");
@ -1079,6 +1103,8 @@ write_inetd_register(transp)
"\tif ((_rpcfdtype == 0) || (_rpcfdtype == %s)) {\n", "\tif ((_rpcfdtype == 0) || (_rpcfdtype == %s)) {\n",
isudp ? "SOCK_DGRAM" : "SOCK_STREAM"); isudp ? "SOCK_DGRAM" : "SOCK_STREAM");
} }
if (tirpcflag)
f_print(fout, "\t\trpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);\n");
f_print(fout, "%s\t%s = svc%s_create(%s", f_print(fout, "%s\t%s = svc%s_create(%s",
sp, TRANSP, transp, inetdflag? "sock": "RPC_ANYSOCK"); sp, TRANSP, transp, inetdflag? "sock": "RPC_ANYSOCK");
if (!isudp) if (!isudp)

View File

@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include <sys/module.h> #include <sys/module.h>
#include <rpc/rpc.h> #include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#include <rpc/pmap_clnt.h> #include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h> #include <rpc/pmap_prot.h>
#include <rpcsvc/mount.h> #include <rpcsvc/mount.h>
@ -273,6 +274,7 @@ main(argc, argv)
struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf; struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
int udpsock, tcpsock, udp6sock, tcp6sock; int udpsock, tcpsock, udp6sock, tcp6sock;
int xcreated = 0, s; int xcreated = 0, s;
int maxrec = RPC_MAXDATASIZE;
int one = 1; int one = 1;
int c; int c;
@ -354,6 +356,9 @@ main(argc, argv)
tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); tcpsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
udpconf = getnetconfigent("udp"); udpconf = getnetconfigent("udp");
tcpconf = getnetconfigent("tcp"); tcpconf = getnetconfigent("tcp");
rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
if (!have_v6) if (!have_v6)
goto skip_v6; goto skip_v6;
udp6sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); udp6sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
@ -408,7 +413,7 @@ skip_v6:
if (tcpsock != -1 && tcpconf != NULL) { if (tcpsock != -1 && tcpconf != NULL) {
bindresvport(tcpsock, NULL); bindresvport(tcpsock, NULL);
listen(tcpsock, SOMAXCONN); listen(tcpsock, SOMAXCONN);
tcptransp = svc_vc_create(tcpsock, 0, 0); tcptransp = svc_vc_create(tcpsock, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
if (tcptransp != NULL) { if (tcptransp != NULL) {
if (!svc_reg(tcptransp, RPCPROG_MNT, RPCMNT_VER1, if (!svc_reg(tcptransp, RPCPROG_MNT, RPCMNT_VER1,
mntsrv, tcpconf)) mntsrv, tcpconf))
@ -449,7 +454,7 @@ skip_v6:
if (have_v6 && tcp6sock != -1 && tcp6conf != NULL) { if (have_v6 && tcp6sock != -1 && tcp6conf != NULL) {
bindresvport(tcp6sock, NULL); bindresvport(tcp6sock, NULL);
listen(tcp6sock, SOMAXCONN); listen(tcp6sock, SOMAXCONN);
tcp6transp = svc_vc_create(tcp6sock, 0, 0); tcp6transp = svc_vc_create(tcp6sock, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
if (tcp6transp != NULL) { if (tcp6transp != NULL) {
if (!svc_reg(tcp6transp, RPCPROG_MNT, RPCMNT_VER1, if (!svc_reg(tcp6transp, RPCPROG_MNT, RPCMNT_VER1,
mntsrv, tcp6conf)) mntsrv, tcp6conf))

View File

@ -61,6 +61,7 @@ __RCSID("$NetBSD: lockd.c,v 1.7 2000/08/12 18:08:44 thorpej Exp $");
#include <netconfig.h> #include <netconfig.h>
#include <rpc/rpc.h> #include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#include <rpcsvc/sm_inter.h> #include <rpcsvc/sm_inter.h>
#include "lockd.h" #include "lockd.h"
@ -95,6 +96,7 @@ main(argc, argv)
struct sigaction sigalarm; struct sigaction sigalarm;
int grace_period = 30; int grace_period = 30;
struct netconfig *nconf; struct netconfig *nconf;
int maxrec = RPC_MAXDATASIZE;
while ((ch = getopt(argc, argv, "d:g:")) != (-1)) { while ((ch = getopt(argc, argv, "d:g:")) != (-1)) {
switch (ch) { switch (ch) {
@ -139,13 +141,16 @@ main(argc, argv)
maxindex = 4; maxindex = 4;
} }
rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
for (i = 0; i < maxindex; i++) { for (i = 0; i < maxindex; i++) {
nconf = getnetconfigent(transports[i]); nconf = getnetconfigent(transports[i]);
if (nconf == NULL) if (nconf == NULL)
errx(1, "cannot get %s netconf: %s.", transports[i], errx(1, "cannot get %s netconf: %s.", transports[i],
nc_sperror()); nc_sperror());
transp = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0); transp = svc_tli_create(RPC_ANYFD, nconf, NULL,
RPC_MAXDATASIZE, RPC_MAXDATASIZE);
if (transp == NULL) { if (transp == NULL) {
errx(1, "cannot create %s service.", transports[i]); errx(1, "cannot create %s service.", transports[i]);
/* NOTREACHED */ /* NOTREACHED */

View File

@ -44,6 +44,7 @@ static const char rcsid[] =
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <rpc/rpc.h> #include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#include <string.h> #include <string.h>
#include <syslog.h> #include <syslog.h>
#include <sys/types.h> #include <sys/types.h>
@ -61,6 +62,7 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct sigaction sa; struct sigaction sa;
int maxrec = RPC_MAXDATASIZE;
if (argc > 1) if (argc > 1)
{ {
@ -71,6 +73,8 @@ main(int argc, char **argv)
(void)rpcb_unset(SM_PROG, SM_VERS, NULL); (void)rpcb_unset(SM_PROG, SM_VERS, NULL);
rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "udp")) if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "udp"))
errx(1, "cannot create udp service"); errx(1, "cannot create udp service");
if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "tcp")) if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "tcp"))

View File

@ -56,6 +56,7 @@ static const char rcsid[] =
#include <unistd.h> #include <unistd.h>
#include <rpc/rpc.h> #include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#include <rpc/pmap_clnt.h> /* for pmap_unset */ #include <rpc/pmap_clnt.h> /* for pmap_unset */
#include <rpcsvc/yp.h> #include <rpcsvc/yp.h>
struct dom_binding {}; struct dom_binding {};
@ -171,6 +172,7 @@ main(int argc, char *argv[])
int ch; int ch;
char *mastername; char *mastername;
char myname[MAXHOSTNAMELEN + 2]; char myname[MAXHOSTNAMELEN + 2];
int maxrec = RPC_MAXDATASIZE;
extern int debug; extern int debug;
@ -273,6 +275,8 @@ the %s domain -- aborting", yppasswd_domain);
rpcb_unset(YPPASSWDPROG, YPPASSWDVERS, NULL); rpcb_unset(YPPASSWDPROG, YPPASSWDVERS, NULL);
rpcb_unset(MASTER_YPPASSWDPROG, MASTER_YPPASSWDVERS, NULL); rpcb_unset(MASTER_YPPASSWDPROG, MASTER_YPPASSWDVERS, NULL);
rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
if (svc_create(yppasswdprog_1, YPPASSWDPROG, YPPASSWDVERS, "netpath") == 0) { if (svc_create(yppasswdprog_1, YPPASSWDPROG, YPPASSWDVERS, "netpath") == 0) {
yp_error("cannot create yppasswd service."); yp_error("cannot create yppasswd service.");
exit(1); exit(1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpcb_svc_com.c,v 1.6 2000/08/03 00:07:22 fvdl Exp $ */ /* $NetBSD: rpcb_svc_com.c,v 1.9 2002/11/08 00:16:39 fvdl Exp $ */
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
@ -1073,6 +1073,7 @@ netbuffree(struct netbuf *ap)
#define MASKVAL (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND) #define MASKVAL (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)
extern bool_t __svc_clean_idle(fd_set *, int, bool_t);
void void
my_svc_run() my_svc_run()
@ -1085,6 +1086,7 @@ my_svc_run()
int i; int i;
#endif #endif
register struct pollfd *p; register struct pollfd *p;
fd_set cleanfds;
for (;;) { for (;;) {
p = pollfds; p = pollfds;
@ -1106,7 +1108,7 @@ my_svc_run()
fprintf(stderr, ">\n"); fprintf(stderr, ">\n");
} }
#endif #endif
switch (poll_ret = poll(pollfds, nfds, INFTIM)) { switch (poll_ret = poll(pollfds, nfds, 30 * 1000)) {
case -1: case -1:
/* /*
* We ignore all errors, continuing with the assumption * We ignore all errors, continuing with the assumption
@ -1114,6 +1116,8 @@ my_svc_run()
* other outside event) and not caused by poll(). * other outside event) and not caused by poll().
*/ */
case 0: case 0:
cleanfds = svc_fdset;
__svc_clean_idle(&cleanfds, 30, FALSE);
continue; continue;
default: default:
#ifdef SVC_RUN_DEBUG #ifdef SVC_RUN_DEBUG

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpcbind.c,v 1.1 2000/06/02 23:15:42 fvdl Exp $ */ /* $NetBSD: rpcbind.c,v 1.3 2002/11/08 00:16:40 fvdl Exp $ */
/* $FreeBSD$ */ /* $FreeBSD$ */
/* /*
@ -57,6 +57,7 @@ static char sccsid[] = "@(#)rpcbind.c 1.35 89/04/21 Copyr 1984 Sun Micro";
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <rpc/rpc.h> #include <rpc/rpc.h>
#include <rpc/rpc_com.h>
#ifdef PORTMAP #ifdef PORTMAP
#include <netinet/in.h> #include <netinet/in.h>
#endif #endif
@ -124,6 +125,7 @@ main(int argc, char *argv[])
struct netconfig *nconf; struct netconfig *nconf;
void *nc_handle; /* Net config handle */ void *nc_handle; /* Net config handle */
struct rlimit rl; struct rlimit rl;
int maxrec = RPC_MAXDATASIZE;
parseargs(argc, argv); parseargs(argc, argv);
@ -165,6 +167,9 @@ main(int argc, char *argv[])
syslog(LOG_ERR, "%s: can't find local transport\n", argv[0]); syslog(LOG_ERR, "%s: can't find local transport\n", argv[0]);
exit(1); exit(1);
} }
rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
init_transport(nconf); init_transport(nconf);
while ((nconf = getnetconfig(nc_handle))) { while ((nconf = getnetconfig(nc_handle))) {
@ -431,7 +436,7 @@ init_transport(struct netconfig *nconf)
listen(fd, SOMAXCONN); listen(fd, SOMAXCONN);
my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr,
0, 0); RPC_MAXDATASIZE, RPC_MAXDATASIZE);
if (my_xprt == (SVCXPRT *)NULL) { if (my_xprt == (SVCXPRT *)NULL) {
syslog(LOG_ERR, "%s: could not create service", syslog(LOG_ERR, "%s: could not create service",
nconf->nc_netid); nconf->nc_netid);
@ -491,7 +496,7 @@ init_transport(struct netconfig *nconf)
if (nconf->nc_semantics != NC_TPI_CLTS) if (nconf->nc_semantics != NC_TPI_CLTS)
listen(fd, SOMAXCONN); listen(fd, SOMAXCONN);
my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, 0, 0); my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
if (my_xprt == (SVCXPRT *)NULL) { if (my_xprt == (SVCXPRT *)NULL) {
syslog(LOG_ERR, "%s: could not create service", syslog(LOG_ERR, "%s: could not create service",
nconf->nc_netid); nconf->nc_netid);