Date: Tue, 16 Jun 2009 12:16:51 GMT From: Zhao Shuai <zhaoshuai@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 164493 for review Message-ID: <200906161216.n5GCGpsV042954@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/event.h> #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 <poll.h> #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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906161216.n5GCGpsV042954>