* svctcp_create():

- bump listen backlog to a modern value (should fix [lib/6379])
	- always check if sock should be closed
	- provide more informative error messages
* svctcp_rev(); set strm_stat = XPRT_DIED if error (from freebsd)
This commit is contained in:
lukem 1999-01-20 08:40:13 +00:00
parent ec6c46ef02
commit 774097a310
1 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: svc_tcp.c,v 1.19 1998/11/15 17:32:46 christos Exp $ */ /* $NetBSD: svc_tcp.c,v 1.20 1999/01/20 08:40:13 lukem Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@ -35,7 +35,7 @@
static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC"; static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";
#else #else
__RCSID("$NetBSD: svc_tcp.c,v 1.19 1998/11/15 17:32:46 christos Exp $"); __RCSID("$NetBSD: svc_tcp.c,v 1.20 1999/01/20 08:40:13 lukem Exp $");
#endif #endif
#endif #endif
@ -152,8 +152,8 @@ svctcp_create(sock, sendsize, recvsize)
if (sock == RPC_ANYSOCK) { if (sock == RPC_ANYSOCK) {
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
warnx("svctcp_create - udp socket creation problem"); warn("svctcp_create - udp socket creation problem");
return ((SVCXPRT *)NULL); goto cleanup_svctcp_create;
} }
madesock = TRUE; madesock = TRUE;
} }
@ -164,24 +164,25 @@ svctcp_create(sock, sendsize, recvsize)
addr.sin_port = 0; addr.sin_port = 0;
(void)bind(sock, (struct sockaddr *)(void *)&addr, len); (void)bind(sock, (struct sockaddr *)(void *)&addr, len);
} }
if ((getsockname(sock, (struct sockaddr *)(void *)&addr, &len) != 0) || if (getsockname(sock, (struct sockaddr *)(void *)&addr, &len) != 0) {
(listen(sock, 2) != 0)) { warn("svctcp_create - cannot getsockname");
warnx("svctcp_create - cannot getsockname or listen"); goto cleanup_svctcp_create;
if (madesock) }
(void)close(sock); if (listen(sock, SOMAXCONN) != 0) {
return ((SVCXPRT *)NULL); warn("svctcp_create - cannot listen");
goto cleanup_svctcp_create;
} }
r = (struct tcp_rendezvous *)mem_alloc(sizeof(*r)); r = (struct tcp_rendezvous *)mem_alloc(sizeof(*r));
if (r == NULL) { if (r == NULL) {
warnx("svctcp_create: out of memory"); warnx("svctcp_create: out of memory");
return (NULL); goto cleanup_svctcp_create;
} }
r->sendsize = sendsize; r->sendsize = sendsize;
r->recvsize = recvsize; r->recvsize = recvsize;
xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT)); xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
if (xprt == NULL) { if (xprt == NULL) {
warnx("svctcp_create: out of memory"); warnx("svctcp_create: out of memory");
return (NULL); goto cleanup_svctcp_create;
} }
xprt->xp_p2 = NULL; xprt->xp_p2 = NULL;
xprt->xp_p1 = (caddr_t)(void *)r; xprt->xp_p1 = (caddr_t)(void *)r;
@ -191,6 +192,10 @@ svctcp_create(sock, sendsize, recvsize)
xprt->xp_sock = sock; xprt->xp_sock = sock;
xprt_register(xprt); xprt_register(xprt);
return (xprt); return (xprt);
cleanup_svctcp_create:
if (madesock)
(void)close(sock);
return ((SVCXPRT *)NULL);
} }
/* /*
@ -394,6 +399,7 @@ svctcp_recv(xprt, msg)
cd->x_id = msg->rm_xid; cd->x_id = msg->rm_xid;
return (TRUE); return (TRUE);
} }
cd->strm_stat = XPRT_DIED;
return (FALSE); return (FALSE);
} }