[program deleted]Quote:>Is it possible (correct?) for write() on a descriptor marked for
>non-blockion I/O to block anyway? I've been having a problem
>in which any time I have more than a few open named pipes,
>write() seems to block even though the fd is set using O_NDELAY,
>and the buffer is not full.
>Sun's man page seems to suggest that write() should return -1
>with EWOULDBLOCK or EAGAIN instead of blocking. What is it I
>did wrong in the program below:
> --------------------------------
>#include <sys/types.h>
>#include <fcntl.h>
>#include <errno.h>
>main()
>{
> int i,j,k,l,err;
> char buf[100];
> for (i=0;i<50;i++) {
> sprintf(buf,"fifo%d",i);
> j = mkfifo(buf,0777); if (j<0) {perror("mkfifo");}
> k = open(buf,O_RDONLY|O_NDELAY); if (k<0) perror("open(RDONLY)");
> l = open(buf,O_WRONLY|O_NDELAY); if (l<0) perror("open(WRONLY)");
> if (fcntl(l,F_SETFL,fcntl(l,F_GETFL,0)|O_NDELAY)<0) perror("fcntl");
> err = write(l,buf,1); if (err<0) perror("write");
> err = read( k,buf,1); if (err<0) perror("read");
>/* close(l); (see below) */
> close(k);
> printf("cool %d\n",i);
> }
> sleep(30);
>}
> --------------------------------
>Yes, I know that the close() statement is "incorrectly" commented
>out. The idea is to simulate a number of different processes which
>all have a named pipe open for reading. This was the simplest
>program I could think of that reproduces the problem.
>In case it matters, This is on a Sun sparc 2
> % showrev -a
> *************** showrev version 1.15 *****************
> * Hostname: "grizzly"
> * Hostid: "7230209f"
> * Kernel Arch: "sun4m"
> * Application Arch: "sun4"
> * Kernel Revision:
> 4.1.3 (GENERIC) #3: Mon Jul 27 16:44:16 PDT 1992
> * Release: 4.1.3
>The problem doesn't seem to occur on a system running Solaris, so
>it might be an OS rather than a programming question.
Just a wild pointer, but it did happen to me. Maybe you need to use the
O_NONBLOCK rather than the O_NDELAY. I found systems where both are
defined, have different values and the doco is confused which one to use
when. Good luck.
> Ron Mayer
Regards