From owner-svn-src-all@freebsd.org Thu Feb 25 19:06:45 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C0CA5AB4C6D; Thu, 25 Feb 2016 19:06:45 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9A25F1E08; Thu, 25 Feb 2016 19:06:45 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u1PJ6iNn049359; Thu, 25 Feb 2016 19:06:44 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u1PJ6iCK049357; Thu, 25 Feb 2016 19:06:44 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201602251906.u1PJ6iCK049357@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Thu, 25 Feb 2016 19:06:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r296054 - head/usr.bin/talk X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2016 19:06:46 -0000 Author: pfg Date: Thu Feb 25 19:06:44 2016 New Revision: 296054 URL: https://svnweb.freebsd.org/changeset/base/296054 Log: talk(1): Replace select(2) with poll(2) Hinted by: OpenBSD and NetBSD Modified: head/usr.bin/talk/ctl_transact.c head/usr.bin/talk/io.c Modified: head/usr.bin/talk/ctl_transact.c ============================================================================== --- head/usr.bin/talk/ctl_transact.c Thu Feb 25 18:49:48 2016 (r296053) +++ head/usr.bin/talk/ctl_transact.c Thu Feb 25 19:06:44 2016 (r296054) @@ -38,6 +38,7 @@ static const char sccsid[] = "@(#)ctl_tr #include #include +#include #include "talk.h" #include "talk_ctl.h" @@ -52,23 +53,20 @@ static const char sccsid[] = "@(#)ctl_tr void ctl_transact(struct in_addr target, CTL_MSG lmsg, int type, CTL_RESPONSE *rp) { - fd_set read_mask, ctl_mask; + struct pollfd pfd[1]; int nready = 0, cc; - struct timeval wait; lmsg.type = type; daemon_addr.sin_addr = target; daemon_addr.sin_port = daemon_port; - FD_ZERO(&ctl_mask); - FD_SET(ctl_sockt, &ctl_mask); + pfd[0].fd = ctl_sockt; + pfd[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 *)&lmsg, sizeof (lmsg), 0, @@ -79,8 +77,7 @@ ctl_transact(struct in_addr target, CTL_ continue; p_error("Error on write to talk daemon"); } - read_mask = ctl_mask; - nready = select(32, &read_mask, 0, 0, &wait); + nready = poll(pfd, 1, CTL_WAIT * 1000); if (nready < 0) { if (errno == EINTR) continue; @@ -99,10 +96,7 @@ ctl_transact(struct in_addr target, CTL_ 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(pfd, 1, 0); } while (nready > 0 && (rp->vers != TALK_VERSION || rp->type != type)); } while (rp->vers != TALK_VERSION || rp->type != type); Modified: head/usr.bin/talk/io.c ============================================================================== --- head/usr.bin/talk/io.c Thu Feb 25 18:49:48 2016 (r296053) +++ head/usr.bin/talk/io.c Thu Feb 25 19:06:44 2016 (r296054) @@ -46,6 +46,7 @@ static const char sccsid[] = "@(#)io.c 8 #include #include #include +#include #include #include #include @@ -67,8 +68,8 @@ void talk(void) { struct hostent *hp, *hp2; + struct pollfd fds[2]; int nb; - fd_set read_set; wchar_t buf[BUFSIZ]; char **addr, *his_machine_name; FILE *sockfp; @@ -107,10 +108,11 @@ talk(void) * Wait on both the other process (sockt) and standard input. */ for (;;) { - FD_ZERO(&read_set); - FD_SET(sockt, &read_set); - FD_SET(fileno(stdin), &read_set); - nb = select(32, &read_set, 0, 0, NULL); + fds[0].fd = fileno(stdin); + fds[0].events = POLLIN; + fds[1].fd = sockt; + fds[1].events = POLLIN; + nb = poll(fds, 2, INFTIM); if (gotwinch) { resize_display(); gotwinch = 0; @@ -119,10 +121,10 @@ talk(void) if (errno == EINTR) continue; /* Panic, we don't know what happened. */ - p_error("Unexpected error from select"); + p_error("Unexpected error from poll"); quit(); } - if (FD_ISSET(sockt, &read_set)) { + if (fds[1].revents & POLLIN) { wint_t w; /* There is data on sockt. */ @@ -133,7 +135,7 @@ talk(void) } display(&his_win, &w); } - if (FD_ISSET(fileno(stdin), &read_set)) { + if (fds[0].revents & POLLIN) { wint_t w; if ((w = getwchar()) != WEOF) {