lkml.org 
[lkml]   [2000]   [Mar]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjecttesters needed: fifo & POLLHUP & POLLERR
I've written a test program, and Tigran ran it on a few Unices [AIX,
FreeBSD, Unixware, UnixSV].

It seems that noone except Linux uses POLLHUP and POLLERR for fifos.
Could someone run the attached test program on a SunOS or Solaris
computer?

The Linux POLLHUP code is unreliable [open(read), open(write),
close(write) without writing a single byte, poll()--> no POLLHUP], so I
would like to remove connect_poll().

And since connect_read() is superfluous as well, we can remove the
complete connecting_fifo_fops array.

TIA,
Manfred/*
* fifo.c: fifo & poll compatibility tester
*
* Copyright (C) 1999,2000 by Manfred Spraul.
*
* Redistribution of this file is permitted under the terms of the GNU
* Public License (GPL)
* $Header: /pub/cvs/ms/fifotest/fifo.c,v 1.2 2000/03/07 17:10:11 manfreds Exp $
*
*/

#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/utsname.h>

int pollflags = 0;

void show_poll(char* str, int fd)
{
struct pollfd pfd[1];
int err;
pfd[0].fd = fd;
pfd[0].events = pollflags;
pfd[0].revents = 0;
err = poll(pfd,1,0);
printf("%s: ret %d, errno %d, flags %xh.\n",
str,
err, errno, pfd[0].revents);
}

int main(int argc, char** argv)
{
char fifoname[128];
char dummy[1];
int fd_r, fd_w;


printf("fifotest");
{
struct utsname un;
uname(&un);
printf(" OS: sysname %s\n release %s\n version %s\n machine %s\n\n",
un.sysname,
un.release,
un.version,
un.machine);
}
printf(" supported poll flags:\n");
#ifdef POLLIN
printf(" POLLIN: %xh\n",POLLIN);
pollflags |= POLLIN;
#endif
#ifdef POLLRDNORM
printf(" POLLRDNORM: %xh\n",POLLRDNORM);
pollflags |= POLLRDNORM;
#endif
#ifdef POLLRDBAND
printf(" POLLRDBAND: %xh\n",POLLRDBAND);
pollflags |= POLLRDBAND;
#endif
#ifdef POLLPRI
printf(" POLLPRI: %xh\n",POLLPRI);
pollflags |= POLLPRI;
#endif
#ifdef POLLOUT
printf(" POLLOUT: %xh\n",POLLOUT);
pollflags |= POLLOUT;
#endif
#ifdef POLLWRNORM
printf(" POLLWRNORM: %xh\n",POLLWRNORM);
pollflags |= POLLWRNORM;
#endif
#ifdef POLLWRBAND
printf(" POLLWRBAND: %xh\n",POLLWRBAND);
pollflags |= POLLWRBAND;
#endif
#ifdef POLLERR
printf(" POLLERR: %xh\n",POLLERR);
#endif
#ifdef POLLHUP
printf(" POLLHUP: %xh\n",POLLHUP);
#endif
#ifdef POLLNVAL
printf(" POLLNVAL: %xh\n",POLLNVAL);
#endif
printf(" --> pollflags %xh.\n",pollflags);

sprintf(fifoname,"/tmp/fifoname.%d",getpid());
if(mkfifo(fifoname,0666)) {
printf("mkfifo(%s) failed, errno %d.\n",fifoname, errno);
exit(1);
}
fd_r = open(fifoname, O_RDONLY|O_NONBLOCK);
if(fd_r == -1) {
printf("open(O_RDONLY) failed, errno %d.\n",errno);
exit(1);
}
show_poll("fifo, single reader, no writer, fd_r", fd_r);
fd_w = open(fifoname, O_WRONLY|O_NONBLOCK);
if(fd_w == -1) {
printf("open(O_WRONLY) failed, errno %d.\n",errno);
exit(1);
}
show_poll("fifo, reader, writer, empty, fd_r", fd_r);
show_poll("fifo, reader, writer, empty, fd_w", fd_w);
printf("close(WR)\n");
close(fd_w);
show_poll("fifo, reader, writer gone, empty, fd_r", fd_r);

printf("open(WR)\n");
fd_w = open(fifoname, O_WRONLY|O_NONBLOCK);
if(fd_w == -1) {
printf("open(O_WRONLY) failed, errno %d.\n",errno);
exit(1);
}
show_poll("fifo, reader, writer reappeared, empty, fd_r", fd_r);
show_poll("fifo, reader, writer reappeared, empty, fd_w", fd_w);
printf("write()\n");
if(write(fd_w, fifoname,1) != 1) {
printf("write() failed: errno %d.\n",errno);
exit(1);
}
show_poll("fifo, reader, writer, 1 byte, fd_r", fd_r);
show_poll("fifo, reader, writer, 1 byte, fd_w", fd_w);

close(fd_w);
show_poll("fifo, reader, writer gone, 1 byte, fd_r", fd_r);
printf("read()\n");
if(read(fd_r, dummy, 1) != 1) {
printf(" couldn't read one byte: errno %d.\n",errno);
}
show_poll("fifo, reader, writer gone, empty, fd_r", fd_r);
printf("open(WR)\n");
fd_w = open(fifoname, O_WRONLY|O_NONBLOCK);
if(fd_w == -1) {
printf("open(O_WRONLY) failed, errno %d.\n",errno);
exit(1);
}
show_poll("fifo, reader, writer reappeared, empty, fd_r", fd_r);
printf("close(RD)\n");
close(fd_r);
show_poll("fifo, no reader, writer, empty, fd_w", fd_w);
close(fd_w);
unlink(fifoname);
return 0;
}
\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.041 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site