select() -> poll()

This commit is contained in:
mycroft 2002-09-18 19:16:09 +00:00
parent 1bf9916dae
commit 675b884ce8
2 changed files with 21 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ctl_transact.c,v 1.5 2001/06/12 15:17:30 wiz Exp $ */
/* $NetBSD: ctl_transact.c,v 1.6 2002/09/18 19:16:09 mycroft Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,11 +38,12 @@
#if 0
static char sccsid[] = "@(#)ctl_transact.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: ctl_transact.c,v 1.5 2001/06/12 15:17:30 wiz Exp $");
__RCSID("$NetBSD: ctl_transact.c,v 1.6 2002/09/18 19:16:09 mycroft Exp $");
#endif /* not lint */
#include "talk.h"
#include <sys/time.h>
#include <sys/poll.h>
#include <errno.h>
#include <unistd.h>
#include "talk_ctl.h"
@ -61,24 +62,21 @@ ctl_transact(target, msg, type, rp)
int type;
CTL_RESPONSE *rp;
{
fd_set read_mask, ctl_mask;
struct pollfd set[1];
int nready, cc;
struct timeval wait;
nready = 0;
msg.type = type;
daemon_addr.sin_addr = target;
daemon_addr.sin_port = daemon_port;
FD_ZERO(&ctl_mask);
FD_SET(ctl_sockt, &ctl_mask);
set[0].fd = ctl_sockt;
set[0].events = POLLIN;
/*
* Keep sending the message until a response of
* the proper type is obtained.
*/
do {
wait.tv_sec = CTL_WAIT;
wait.tv_usec = 0;
/* resend message until a response is obtained */
do {
cc = sendto(ctl_sockt, (char *)&msg, sizeof (msg), 0,
@ -89,8 +87,7 @@ ctl_transact(target, msg, type, rp)
continue;
p_error("Error on write to talk daemon");
}
read_mask = ctl_mask;
nready = select(32, &read_mask, 0, 0, &wait);
nready = poll(set, 1, CTL_WAIT * 1000);
if (nready < 0) {
if (errno == EINTR)
continue;
@ -109,10 +106,8 @@ ctl_transact(target, msg, type, rp)
continue;
p_error("Error on read from talk daemon");
}
read_mask = ctl_mask;
/* an immediate poll */
timerclear(&wait);
nready = select(32, &read_mask, 0, 0, &wait);
nready = poll(set, 1, 0);
} while (nready > 0 && (rp->vers != TALK_VERSION ||
rp->type != type));
} while (rp->vers != TALK_VERSION || rp->type != type);

View File

@ -1,4 +1,4 @@
/* $NetBSD: io.c,v 1.5 1997/10/20 00:23:24 lukem Exp $ */
/* $NetBSD: io.c,v 1.6 2002/09/18 19:16:09 mycroft Exp $ */
/*
* Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: io.c,v 1.5 1997/10/20 00:23:24 lukem Exp $");
__RCSID("$NetBSD: io.c,v 1.6 2002/09/18 19:16:09 mycroft Exp $");
#endif /* not lint */
/*
@ -50,12 +50,13 @@ __RCSID("$NetBSD: io.c,v 1.5 1997/10/20 00:23:24 lukem Exp $");
#include "talk.h"
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/poll.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#define A_LONG_TIME 10000000
#define A_LONG_TIME 1000000
/*
* The routine to do the actual talking
@ -63,10 +64,9 @@ __RCSID("$NetBSD: io.c,v 1.5 1997/10/20 00:23:24 lukem Exp $");
void
talk()
{
fd_set read_template, read_set;
struct pollfd set[2];
int nb;
char buf[BUFSIZ];
struct timeval wait;
message("Connection established\007\007\007");
current_line = 0;
@ -75,24 +75,20 @@ talk()
* Wait on both the other process (sockt_mask) and
* standard input ( STDIN_MASK )
*/
FD_ZERO(&read_template);
FD_SET(sockt, &read_template);
FD_SET(fileno(stdin), &read_template);
set[0].fd = sockt;
set[0].events = POLLIN;
set[1].fd = fileno(stdin);
set[1].events = POLLIN;
for (;;) {
read_set = read_template;
wait.tv_sec = A_LONG_TIME;
wait.tv_usec = 0;
nb = select(32, &read_set, 0, 0, &wait);
nb = poll(set, 2, A_LONG_TIME * 1000);
if (nb <= 0) {
if (errno == EINTR) {
read_set = read_template;
if (errno == EINTR)
continue;
}
/* panic, we don't know what happened */
p_error("Unexpected error from select");
quit();
}
if (FD_ISSET(sockt, &read_set)) {
if (set[0].revents & POLLIN) {
/* There is data on sockt */
nb = read(sockt, buf, sizeof buf);
if (nb <= 0) {
@ -101,7 +97,7 @@ talk()
}
display(&his_win, buf, nb);
}
if (FD_ISSET(fileno(stdin), &read_set)) {
if (set[1].revents & POLLIN) {
/*
* We can't make the tty non_blocking, because
* curses's output routines would screw up