[2.2] pipe_write can block even with non-blocking fd

[2.2] pipe_write can block even with non-blocking fd

Post by Peter Beni » Sun, 08 Dec 2002 23:00:11



Please apply the following patch. This makes non-blocking writes to
pipe actually non-blocking.

A program that demonstrates the bug can be found at:
http://www.chiark.greenend.org.uk/~peterb/linux/nonblock/pipe-testnon...

--- 2.2.19/fs/pipe.c.orig       Thu Dec  6 21:20:38 2001

        else
                free = 1; /* can't do it atomically, wait for any free space */
        up(&inode->i_sem);
-       if (down_interruptible(&inode->i_atomic_write)) {
-               down(&inode->i_sem);
-               return -ERESTARTSYS;
+       if (filp->f_flags & O_NONBLOCK) {
+               if (down_trylock(&inode->i_atomic_write)) {
+                       down(&inode->i_sem);
+                       return -ERESTARTSYS;
+               }
+       }
+       else {
+               if (down_interruptible(&inode->i_atomic_write)) {
+                       down(&inode->i_sem);
+                       return -ERESTARTSYS;
+               }
        }
        while (count>0) {
                while ((PIPE_FREE(*inode) < free) || PIPE_LOCK(*inode)) {
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. Non blocking socket blocks; says 'read would block' ?

Hi all,

I have three sockets in server which I am reading in a continuous loop,
so don't want to wait on any one. I have designated them as 'non blocking'
but when run the server exits on the very first read() and says 'would
block'. (Is it the same as 'EWOULDBLOCK' mentioned in R. Steven's book ?)
I don't want that I should get any error msg and exit, in fact the
whole purpose of nonblocking is that if something is available, read it
else proceed in the loop and come back to read next time.
The client (sender) is sending msgs on all three sockets. The sockets
are conn_oriented. I am using SunOS 4.1. The small code part is below:

int emer_s, env_s, sens_s;            /* socket fds */
//----------- making sockets nonblocking ******
if ((res=fcntl(emer_s,F_SETFL,FNDELAY)) < 0)
        {
          perror("fcntl res = -1");
          exit(1);
        }
if ((res=fcntl(env_s,F_SETFL,FNDELAY)) < 0)
        {
          perror("fcntl res = -1");
          exit(1);
        }
if ((res=fcntl(sens_s,F_SETFL,FNDELAY)) < 0)
        {
          perror("fcntl res = -1");
          exit(1);
        }

for(; ;)
   {

      if ((cc=read(emer_s,(char*)&gen_struct,size)) < size)
        {
        perror("read error");
          exit(1);
        }
......... do something
      if ((cc=read(env_s,(char*)&gen_struct,size)) < size)
        {
         perror("read error");
          exit(1);
        }
        ......... do something
      if ((cc=read(sens_s,(char*)&gen_struct,size)) < size)
        {
          perror("read error");
          exit(1);
        }
        ......... do something

   }

Any help is appreciated.

hashmi

--
-----
Atiqullah Hashmi                    
UTA (Univ. of Texas at Arlington)  

2. Help: Install Solaris 8 for intel

3. Non-blocking connect()'s not working on Solaris 2.2?

4. automount hangs

5. Blocking connect() fails, non-blocking succeeds?

6. Formatting LS-120 cartridges?

7. Blocking and Non-Blocking socket

8. X Libraries ? Arrgghh!

9. how to get blocking i/o after non-blocking???

10. [2.5] Non-blocking write can block

11. Blocking & Non-Blocking

12. Non-blocking socket reads block! (Bug?)

13. Problem with blocking opens preventing non-blocking opens in AIX 5.2