src/java.base/share/classes/java/net/Socket.java
branchniosocketimpl-branch
changeset 57187 056911ad3ee7
parent 57178 738431fa8fb2
child 57188 1f2101ee432d
--- a/src/java.base/share/classes/java/net/Socket.java	Fri Feb 15 18:07:17 2019 +0000
+++ b/src/java.base/share/classes/java/net/Socket.java	Sat Feb 16 19:53:43 2019 +0000
@@ -1423,9 +1423,8 @@
         try {
             getImpl().setOption(SocketOptions.IP_TOS, tc);
         } catch (SocketException se) {
-            // not supported if socket already connected
-            // Solaris returns error in such cases
-            if(!isConnected())
+            // may not be supported to change when socket is connected
+            if (!isConnected())
                 throw se;
         }
     }
@@ -1799,7 +1798,14 @@
      * @since 9
      */
     public <T> Socket setOption(SocketOption<T> name, T value) throws IOException {
-        getImpl().setOption(name, value);
+        try {
+            getImpl().setOption(name, value);
+        } catch (SocketException se) {
+            // may not be supported to change when socket is connected
+            if (name != StandardSocketOptions.IP_TOS || !isConnected()) {
+                throw se;
+            }
+        }
         return this;
     }