8203369: Check for both EAGAIN and EWOULDBLOCK error codes
authorigerasim
Fri, 25 May 2018 12:44:34 -0700
changeset 50275 69204b98dc3d
parent 50274 33a890c972c3
child 50276 6a5a8ed5e475
child 56612 902afa0f37f9
8203369: Check for both EAGAIN and EWOULDBLOCK error codes Reviewed-by: alanb
src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java
src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template
src/java.base/unix/native/libnet/PlainSocketImpl.c
src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c
src/java.base/unix/native/libnio/ch/IOUtil.c
src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c
src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c
--- a/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java	Fri May 25 11:59:01 2018 -0700
+++ b/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java	Fri May 25 12:44:34 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -319,7 +319,7 @@
                     try {
                         bytesRead = read(ifd, address, BUFFER_SIZE);
                     } catch (UnixException x) {
-                        if (x.errno() != EAGAIN)
+                        if (x.errno() != EAGAIN && x.errno() != EWOULDBLOCK)
                             throw x;
                         bytesRead = 0;
                     }
@@ -367,7 +367,7 @@
                             if (shutdown)
                                 break;
                         } catch (UnixException x) {
-                            if (x.errno() != UnixConstants.EAGAIN)
+                            if (x.errno() != EAGAIN && x.errno() != EWOULDBLOCK)
                                 throw x;
                         }
                     }
--- a/src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template	Fri May 25 11:59:01 2018 -0700
+++ b/src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template	Fri May 25 12:44:34 2018 -0700
@@ -1,6 +1,5 @@
 /*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
- *
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +21,6 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
- *
  */
 
 @@END_COPYRIGHT@@
@@ -111,6 +109,7 @@
     static final int PREFIX_ENOTEMPTY = ENOTEMPTY;
     static final int PREFIX_ENOSPC = ENOSPC;
     static final int PREFIX_EAGAIN = EAGAIN;
+    static final int PREFIX_EWOULDBLOCK = EWOULDBLOCK;
     static final int PREFIX_ENOSYS = ENOSYS;
     static final int PREFIX_ELOOP = ELOOP;
     static final int PREFIX_EROFS = EROFS;
--- a/src/java.base/unix/native/libnet/PlainSocketImpl.c	Fri May 25 11:59:01 2018 -0700
+++ b/src/java.base/unix/native/libnet/PlainSocketImpl.c	Fri May 25 12:44:34 2018 -0700
@@ -630,8 +630,8 @@
      * before accept() was called.
      *
      * If accept timeout in place and timeout is adjusted with
-     * each ECONNABORTED or EWOULDBLOCK to ensure that semantics
-     * of timeout are preserved.
+     * each ECONNABORTED or EWOULDBLOCK or EAGAIN to ensure that
+     * semantics of timeout are preserved.
      */
     for (;;) {
         int ret;
@@ -673,12 +673,12 @@
             break;
         }
 
-        /* non (ECONNABORTED or EWOULDBLOCK) error */
-        if (!(errno == ECONNABORTED || errno == EWOULDBLOCK)) {
+        /* non (ECONNABORTED or EWOULDBLOCK or EAGAIN) error */
+        if (!(errno == ECONNABORTED || errno == EWOULDBLOCK || errno == EAGAIN)) {
             break;
         }
 
-        /* ECONNABORTED or EWOULDBLOCK error so adjust timeout if there is one. */
+        /* ECONNABORTED or EWOULDBLOCK or EAGAIN error so adjust timeout if there is one. */
         if (nanoTimeout >= NET_NSEC_PER_MSEC) {
             currNanoTime = JVM_NanoTime(env, 0);
             nanoTimeout -= (currNanoTime - prevNanoTime);
--- a/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c	Fri May 25 11:59:01 2018 -0700
+++ b/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c	Fri May 25 12:44:34 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -142,7 +142,7 @@
         retry = JNI_FALSE;
         n = recvfrom(fd, buf, len, 0, &sa.sa, &sa_len);
         if (n < 0) {
-            if (errno == EWOULDBLOCK) {
+            if (errno == EAGAIN || errno == EWOULDBLOCK) {
                 return IOS_UNAVAILABLE;
             }
             if (errno == EINTR) {
@@ -217,7 +217,7 @@
 
     n = sendto(fd, buf, len, 0, &sa.sa, sa_len);
     if (n < 0) {
-        if (errno == EAGAIN) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK) {
             return IOS_UNAVAILABLE;
         }
         if (errno == EINTR) {
--- a/src/java.base/unix/native/libnio/ch/IOUtil.c	Fri May 25 11:59:01 2018 -0700
+++ b/src/java.base/unix/native/libnio/ch/IOUtil.c	Fri May 25 12:44:34 2018 -0700
@@ -120,7 +120,7 @@
     for (;;) {
         int n = read(fd, buf, sizeof(buf));
         tn += n;
-        if ((n < 0) && (errno != EAGAIN))
+        if ((n < 0) && (errno != EAGAIN && errno != EWOULDBLOCK))
             JNU_ThrowIOExceptionWithLastError(env, "Drain");
         if (n == (int)sizeof(buf))
             continue;
@@ -136,7 +136,7 @@
 
     res = read(fd, buf, 1);
     if (res < 0) {
-        if (errno == EAGAIN) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK) {
             res = 0;
         } else if (errno == EINTR) {
             return IOS_INTERRUPTED;
@@ -187,7 +187,7 @@
             return 0;
         }
     }
-    else if (errno == EAGAIN)
+    else if (errno == EAGAIN || errno == EWOULDBLOCK)
         return IOS_UNAVAILABLE;
     else if (errno == EINTR)
         return IOS_INTERRUPTED;
@@ -212,7 +212,7 @@
             return 0;
         }
     }
-    else if (errno == EAGAIN)
+    else if (errno == EAGAIN || errno == EWOULDBLOCK)
         return IOS_UNAVAILABLE;
     else if (errno == EINTR)
         return IOS_INTERRUPTED;
--- a/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c	Fri May 25 11:59:01 2018 -0700
+++ b/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c	Fri May 25 12:44:34 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -103,7 +103,7 @@
     }
 
     if (newfd < 0) {
-        if (errno == EAGAIN)
+        if (errno == EAGAIN || errno == EWOULDBLOCK)
             return IOS_UNAVAILABLE;
         if (errno == EINTR)
             return IOS_INTERRUPTED;
--- a/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c	Fri May 25 11:59:01 2018 -0700
+++ b/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c	Fri May 25 12:44:34 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -439,7 +439,7 @@
 
     do {
         if ((rv = recvmsg(fd, msg, flags)) < 0) {
-            if (errno == EWOULDBLOCK) {
+            if (errno == EAGAIN || errno == EWOULDBLOCK) {
                 return IOS_UNAVAILABLE;
             } else if (errno == EINTR) {
                 return IOS_INTERRUPTED;
@@ -582,7 +582,7 @@
     setControlData(msg, cdata);
 
     if ((rv = sendmsg(fd, msg, 0)) < 0) {
-        if (errno == EWOULDBLOCK) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK) {
             return IOS_UNAVAILABLE;
         } else if (errno == EINTR) {
             return IOS_INTERRUPTED;