changeset 16249:5a6a97703855

8170920: SO_RCVBUF and SO_SNDBUF options problem for network channels on MacOS Reviewed-by: chegar, clanger
author michaelm
date Mon, 12 Dec 2016 14:40:56 +0000
parents 03d7bdec12fe
children 5a846396a24c
files src/java.base/unix/native/libnet/net_util_md.c test/java/net/SocketOption/MinimumRcvBufferSize.java
diffstat 2 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/unix/native/libnet/net_util_md.c	Mon Dec 12 15:33:46 2016 +0100
+++ b/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/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");
+    }
+}