use poll() instead of select()
This commit is contained in:
parent
c66d855eb2
commit
f6c91ed9ca
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clnt_tcp.c,v 1.4 1995/02/25 03:01:41 cgd Exp $ */
|
||||
/* $NetBSD: clnt_tcp.c,v 1.5 1996/12/17 03:55:20 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
|
@ -32,7 +32,7 @@
|
|||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
/*static char *sccsid = "from: @(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";*/
|
||||
/*static char *sccsid = "from: @(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC";*/
|
||||
static char *rcsid = "$NetBSD: clnt_tcp.c,v 1.4 1995/02/25 03:01:41 cgd Exp $";
|
||||
static char *rcsid = "$NetBSD: clnt_tcp.c,v 1.5 1996/12/17 03:55:20 mrg Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -54,6 +54,9 @@ static char *rcsid = "$NetBSD: clnt_tcp.c,v 1.4 1995/02/25 03:01:41 cgd Exp $";
|
|||
* Now go hang yourself.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
@ -400,17 +403,16 @@ readtcp(ct, buf, len)
|
|||
caddr_t buf;
|
||||
register int len;
|
||||
{
|
||||
fd_set mask;
|
||||
fd_set readfds;
|
||||
struct pollfd fd;
|
||||
int milliseconds = (ct->ct_wait.tv_sec * 1000) +
|
||||
(ct->ct_wait.tv_usec / 1000);
|
||||
|
||||
if (len == 0)
|
||||
return (0);
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(ct->ct_sock, &mask);
|
||||
fd.fd = ct->ct_sock;
|
||||
fd.events = fd.revents = POLLIN;
|
||||
while (TRUE) {
|
||||
readfds = mask;
|
||||
switch (select(ct->ct_sock+1, &readfds, (int*)NULL, (int*)NULL,
|
||||
&(ct->ct_wait))) {
|
||||
switch (poll(&fd, 1, milliseconds)) {
|
||||
case 0:
|
||||
ct->ct_error.re_status = RPC_TIMEDOUT;
|
||||
return (-1);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clnt_udp.c,v 1.4 1995/02/25 03:01:42 cgd Exp $ */
|
||||
/* $NetBSD: clnt_udp.c,v 1.5 1996/12/17 03:55:27 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
|
@ -32,7 +32,7 @@
|
|||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
/*static char *sccsid = "from: @(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";*/
|
||||
/*static char *sccsid = "from: @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC";*/
|
||||
static char *rcsid = "$NetBSD: clnt_udp.c,v 1.4 1995/02/25 03:01:42 cgd Exp $";
|
||||
static char *rcsid = "$NetBSD: clnt_udp.c,v 1.5 1996/12/17 03:55:27 mrg Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -41,6 +41,9 @@ static char *rcsid = "$NetBSD: clnt_udp.c,v 1.4 1995/02/25 03:01:42 cgd Exp $";
|
|||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
@ -222,8 +225,9 @@ clntudp_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
|
|||
register int outlen;
|
||||
register int inlen;
|
||||
int fromlen;
|
||||
fd_set readfds;
|
||||
fd_set mask;
|
||||
struct pollfd fd;
|
||||
int milliseconds = (cu->cu_wait.tv_sec * 1000) +
|
||||
(cu->cu_wait.tv_usec / 1000);
|
||||
struct sockaddr_in from;
|
||||
struct rpc_msg reply_msg;
|
||||
XDR reply_xdrs;
|
||||
|
@ -276,13 +280,10 @@ send_again:
|
|||
reply_msg.acpted_rply.ar_verf = _null_auth;
|
||||
reply_msg.acpted_rply.ar_results.where = resultsp;
|
||||
reply_msg.acpted_rply.ar_results.proc = xresults;
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(cu->cu_sock, &mask);
|
||||
fd.fd = cu->cu_sock;
|
||||
fd.events = fd.revents = POLLIN;
|
||||
for (;;) {
|
||||
readfds = mask;
|
||||
switch (select(cu->cu_sock+1, &readfds, (int *)NULL,
|
||||
(int *)NULL, &(cu->cu_wait))) {
|
||||
|
||||
switch (poll(&fd, 1, milliseconds)) {
|
||||
case 0:
|
||||
time_waited.tv_sec += cu->cu_wait.tv_sec;
|
||||
time_waited.tv_usec += cu->cu_wait.tv_usec;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pmap_rmt.c,v 1.6 1995/06/03 22:37:25 mycroft Exp $ */
|
||||
/* $NetBSD: pmap_rmt.c,v 1.7 1996/12/17 03:55:32 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
|
@ -32,7 +32,7 @@
|
|||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
/*static char *sccsid = "from: @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";*/
|
||||
/*static char *sccsid = "from: @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";*/
|
||||
static char *rcsid = "$NetBSD: pmap_rmt.c,v 1.6 1995/06/03 22:37:25 mycroft Exp $";
|
||||
static char *rcsid = "$NetBSD: pmap_rmt.c,v 1.7 1996/12/17 03:55:32 mrg Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -43,6 +43,9 @@ static char *rcsid = "$NetBSD: pmap_rmt.c,v 1.6 1995/06/03 22:37:25 mycroft Exp
|
|||
* Copyright (C) 1984, Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_prot.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
|
@ -234,8 +237,7 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
|
|||
int outlen, inlen, fromlen, nets;
|
||||
register int sock;
|
||||
int on = 1;
|
||||
fd_set mask;
|
||||
fd_set readfds;
|
||||
struct pollfd fd;
|
||||
register int i;
|
||||
bool_t done = FALSE;
|
||||
register u_long xid;
|
||||
|
@ -246,6 +248,7 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
|
|||
struct rmtcallres r;
|
||||
struct rpc_msg msg;
|
||||
struct timeval t;
|
||||
int milliseconds;
|
||||
char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
|
||||
|
||||
/*
|
||||
|
@ -264,8 +267,8 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
|
|||
goto done_broad;
|
||||
}
|
||||
#endif /* def SO_BROADCAST */
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(sock, &mask);
|
||||
fd.fd = sock;
|
||||
fd.events = fd.revents = POLLIN;
|
||||
nets = getbroadcastnets(addrs, sock, inbuf);
|
||||
memset(&baddr, 0, sizeof (baddr));
|
||||
baddr.sin_len = sizeof(struct sockaddr_in);
|
||||
|
@ -318,12 +321,11 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
|
|||
goto done_broad;
|
||||
}
|
||||
recv_again:
|
||||
milliseconds = t.tv_sec * 1000 + t.tv_usec / 1000;
|
||||
msg.acpted_rply.ar_verf = _null_auth;
|
||||
msg.acpted_rply.ar_results.where = (caddr_t)&r;
|
||||
msg.acpted_rply.ar_results.proc = xdr_rmtcallres;
|
||||
readfds = mask;
|
||||
switch (select(sock+1, &readfds, (int *)NULL,
|
||||
(int *)NULL, &t)) {
|
||||
switch (poll(&fd, 1, milliseconds)) {
|
||||
|
||||
case 0: /* timed out */
|
||||
stat = RPC_TIMEDOUT;
|
||||
|
@ -332,11 +334,11 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
|
|||
case -1: /* some kind of error */
|
||||
if (errno == EINTR)
|
||||
goto recv_again;
|
||||
perror("Broadcast select problem");
|
||||
perror("Broadcast poll problem");
|
||||
stat = RPC_CANTRECV;
|
||||
goto done_broad;
|
||||
|
||||
} /* end of select results switch */
|
||||
} /* end of poll results switch */
|
||||
try_again:
|
||||
fromlen = sizeof(struct sockaddr);
|
||||
inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: svc_tcp.c,v 1.6 1995/06/03 22:37:27 mycroft Exp $ */
|
||||
/* $NetBSD: svc_tcp.c,v 1.7 1996/12/17 03:55:38 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
|
@ -32,7 +32,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 = "$NetBSD: svc_tcp.c,v 1.6 1995/06/03 22:37:27 mycroft Exp $";
|
||||
static char *rcsid = "$NetBSD: svc_tcp.c,v 1.7 1996/12/17 03:55:38 mrg Exp $";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -45,6 +45,9 @@ static char *rcsid = "$NetBSD: svc_tcp.c,v 1.6 1995/06/03 22:37:27 mycroft Exp $
|
|||
* and a record/tcp stream.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -279,16 +282,13 @@ svctcp_destroy(xprt)
|
|||
mem_free((caddr_t)xprt, sizeof(SVCXPRT));
|
||||
}
|
||||
|
||||
/*
|
||||
* All read operations timeout after 35 seconds.
|
||||
* A timeout is fatal for the connection.
|
||||
*/
|
||||
static struct timeval wait_per_try = { 35, 0 };
|
||||
|
||||
/*
|
||||
* reads data from the tcp conection.
|
||||
* any error is fatal and the connection is closed.
|
||||
* (And a read of zero bytes is a half closed stream => error.)
|
||||
* All read operations timeout after 35 seconds. A timeout is
|
||||
* fatal for the connection.
|
||||
*/
|
||||
static int
|
||||
readtcp(xprt, buf, len)
|
||||
|
@ -297,21 +297,19 @@ readtcp(xprt, buf, len)
|
|||
register int len;
|
||||
{
|
||||
register int sock = xprt->xp_sock;
|
||||
fd_set mask;
|
||||
fd_set readfds;
|
||||
int milliseconds = 35 * 1000;
|
||||
struct pollfd pollfd;
|
||||
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(sock, &mask);
|
||||
do {
|
||||
readfds = mask;
|
||||
if (select(sock+1, &readfds, (int*)NULL, (int*)NULL,
|
||||
&wait_per_try) <= 0) {
|
||||
pollfd.fd = sock;
|
||||
pollfd.events = pollfd.revents = POLLIN;
|
||||
if (poll(&pollfd, 1, milliseconds)) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
goto fatal_err;
|
||||
}
|
||||
} while (!FD_ISSET(sock, &readfds));
|
||||
} while ((pollfd.revents & POLLIN) == 0);
|
||||
if ((len = read(sock, buf, len)) > 0) {
|
||||
return (len);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue