8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS
authormichaelm
Mon, 12 Dec 2016 14:40:56 +0000
changeset 42475 c80ab3b11401
parent 42474 6b0beb616950
child 42476 feba4cd7531e
8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS Reviewed-by: chegar, clanger
jdk/src/java.base/unix/native/libnet/net_util_md.c
jdk/test/java/net/SocketOption/MinimumRcvBufferSize.java
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.c	Mon Dec 12 15:33:46 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.c	Mon Dec 12 14:40:56 2016 +0000
@@ -45,6 +45,10 @@
 #include <sys/sockio.h>
 #endif
 
+#if defined(MACOSX)
+#include <sys/sysctl.h>
+#endif
+
 #include "net_util.h"
 
 #include "java_net_SocketOptions.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/net/SocketOption/MinimumRcvBufferSize.java	Mon Dec 12 14:40:56 2016 +0000
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8170920
+ * @run main MinimumRcvBufferSize
+ */
+
+import java.nio.channels.*;
+import java.net.*;
+
+public class MinimumRcvBufferSize {
+
+    public static void main(String args[]) throws Exception {
+        boolean error = false;
+        ServerSocketChannel channel = ServerSocketChannel.open();
+        int before = channel.getOption(StandardSocketOptions.SO_RCVBUF);
+        channel.setOption(StandardSocketOptions.SO_RCVBUF, Integer.MAX_VALUE);
+        int after = channel.getOption(StandardSocketOptions.SO_RCVBUF);
+        if (before > after) {
+            System.err.println("Test failed: SO_RCVBUF");
+            error = true;
+        }
+
+        SocketChannel channel1 = SocketChannel.open();
+        before = channel1.getOption(StandardSocketOptions.SO_SNDBUF);
+        channel1.setOption(StandardSocketOptions.SO_SNDBUF, Integer.MAX_VALUE);
+        after = channel1.getOption(StandardSocketOptions.SO_SNDBUF);
+        if (before > after) {
+            System.err.println("Test failed: SO_SNDBUF");
+            error = true;
+        }
+        if (error)
+            throw new RuntimeException("Test failed");
+    }
+}