Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/talk select() -> poll()
details: https://anonhg.NetBSD.org/src/rev/8dbc13ce81f2
branches: trunk
changeset: 536561:8dbc13ce81f2
user: mycroft <mycroft%NetBSD.org@localhost>
date: Wed Sep 18 19:16:09 2002 +0000
description:
select() -> poll()
diffstat:
usr.bin/talk/ctl_transact.c | 21 ++++++++-------------
usr.bin/talk/io.c | 30 +++++++++++++-----------------
2 files changed, 21 insertions(+), 30 deletions(-)
diffs (159 lines):
diff -r b0fb468d754d -r 8dbc13ce81f2 usr.bin/talk/ctl_transact.c
--- a/usr.bin/talk/ctl_transact.c Wed Sep 18 19:14:58 2002 +0000
+++ b/usr.bin/talk/ctl_transact.c Wed Sep 18 19:16:09 2002 +0000
@@ -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 @@
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 @@
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 @@
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);
diff -r b0fb468d754d -r 8dbc13ce81f2 usr.bin/talk/io.c
--- a/usr.bin/talk/io.c Wed Sep 18 19:14:58 2002 +0000
+++ b/usr.bin/talk/io.c Wed Sep 18 19:16:09 2002 +0000
@@ -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 @@
#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 @@
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 @@
* 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 @@
}
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
Home |
Main Index |
Thread Index |
Old Index