From owner-p4-projects@FreeBSD.ORG Tue Jun 16 12:16:52 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BBA1E1065694; Tue, 16 Jun 2009 12:16:51 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 708891065688 for ; Tue, 16 Jun 2009 12:16:51 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5D56F8FC30 for ; Tue, 16 Jun 2009 12:16:51 +0000 (UTC) (envelope-from zhaoshuai@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5GCGpek042956 for ; Tue, 16 Jun 2009 12:16:51 GMT (envelope-from zhaoshuai@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5GCGpsV042954 for perforce@freebsd.org; Tue, 16 Jun 2009 12:16:51 GMT (envelope-from zhaoshuai@FreeBSD.org) Date: Tue, 16 Jun 2009 12:16:51 GMT Message-Id: <200906161216.n5GCGpsV042954@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zhaoshuai@FreeBSD.org using -f From: Zhao Shuai To: Perforce Change Reviews Cc: Subject: PERFORCE change 164493 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jun 2009 12:16:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=164493 Change 164493 by zhaoshuai@zhaoshuai on 2009/06/16 12:16:44 wrongly use #elif, replace it by #else Affected files ... .. //depot/projects/soc2009/fifo/fifo_test/functionality/kqueue.c#2 edit .. //depot/projects/soc2009/fifo/fifo_test/functionality/poll.c#2 edit .. //depot/projects/soc2009/fifo/fifo_test/functionality/select.c#5 edit Differences ... ==== //depot/projects/soc2009/fifo/fifo_test/functionality/kqueue.c#2 (text+ko) ==== @@ -11,34 +11,58 @@ #include #include "test.h" +#define TEST_READ 0 + int main() { int fd, kq, ret, n; - struct kevent rkev; - char rbuf[BUF_SIZE]; + struct kevent rkev, wkev; + char rbuf[BUF_SIZE], wbuf[BUF_SIZE]; kq = kqueue(); if (kq < 0) { perror("kqueue error"); return (1); } +#if TEST_READ fd = open(FIFO_PATH, O_RDONLY); +#else + fd = open(FIFO_PATH, O_WRONLY); +#endif if (fd < 0) { perror("open error"); return (2); } - +#if TEST_READ EV_SET(&rkev, fd, EVFILT_READ, EV_ADD, 0, 0, NULL); kevent(kq, &rkev, 1, NULL, 0, NULL); +#else + EV_SET(&wkev, fd, EVFILT_WRITE, EV_ADD, 0, 0, NULL); + kevent(kq, &wkev, 1, NULL, 0, NULL); +#endif + while (1) { + printf("wait on kevent...\n"); +#if TEST_READ ret = kevent(kq, NULL, 0, &rkev, 1, NULL); +#else + ret = kevent(kq, NULL, 0, &wkev, 1, NULL); +#endif + printf("kevent returned %d, fd = %d...\n", ret, rkev.ident); if (ret > 0 && rkev.ident == fd) { +#if TEST_READ n = read(fd, rbuf, BUF_SIZE); if (n == 0) break; printf("%s", rbuf); memset(rbuf, 0, n); +#else + n = read(0, wbuf, BUF_SIZE); + if (n == 0) + break; + write(fd, wbuf, n); +#endif } else if (ret < 0) { perror("kevent error"); break; ==== //depot/projects/soc2009/fifo/fifo_test/functionality/poll.c#2 (text+ko) ==== @@ -12,7 +12,7 @@ #include #include "test.h" -#define TEST_READ 1 +#define TEST_READ 0 int main() { @@ -23,7 +23,7 @@ #if TEST_READ fd = open(FIFO_PATH, O_RDONLY | O_NONBLOCK); #else - fd = open(FIFO_PATH, O_WRONLY | O_NONBLOCK); + fd = open(FIFO_PATH, O_WRONLY /* | O_NONBLOCK */); #endif if (fd < 0) { @@ -40,6 +40,7 @@ while (1) { ret = poll(&pfd, 1, INFTIM); if (ret > 0) { + printf("poll returned %d, revents = %d\n", ret, (int)pfd.revents); #if TEST_READ if (pfd.revents & POLLRDNORM) { n = read(fd, rbuf, BUF_SIZE); @@ -58,7 +59,7 @@ return (0); else { /* poll error */ perror("poll error"); - return (2); + return (ret); } } return (0); ==== //depot/projects/soc2009/fifo/fifo_test/functionality/select.c#5 (text+ko) ==== @@ -16,7 +16,7 @@ #include "test.h" /* set this value to 0 when testing write */ -#define TEST_READ 1 +#define TEST_READ 0 int main() { @@ -28,8 +28,8 @@ FD_ZERO(&wset); #if TEST_READ fd = open(FIFO_PATH, O_RDONLY | O_NONBLOCK); -#elif - fd = open(FIFO_PATH, O_WRONLY | O_NONBLOCK); +#else + fd = open(FIFO_PATH, O_WRONLY /* | O_NONBLOCK */); #endif if (fd < 0) { perror("open error"); @@ -40,7 +40,7 @@ FD_SET(fd, &wset); #if TEST_READ ret = select(fd+1, &rset, NULL, NULL, NULL); -#elif +#else ret = select(fd+1, NULL, &wset, NULL, NULL); #endif if (ret > 0) { @@ -52,7 +52,7 @@ printf("%s", buf); memset(buf, 0, n); } -#elif +#else if (FD_ISSET(fd, &wset)) { n = read(0, buf, BUF_SIZE); if (n <= 0)