1 /*
2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
374 protected PlatformSocketOptions() {}
375
376 @SuppressWarnings("unchecked")
377 private static PlatformSocketOptions newInstance(String cn) {
378 Class<PlatformSocketOptions> c;
379 try {
380 c = (Class<PlatformSocketOptions>)Class.forName(cn);
381 return c.getConstructor(new Class<?>[] { }).newInstance();
382 } catch (ReflectiveOperationException x) {
383 throw new AssertionError(x);
384 }
385 }
386
387 private static PlatformSocketOptions create() {
388 String osname = AccessController.doPrivileged(
389 new PrivilegedAction<String>() {
390 public String run() {
391 return System.getProperty("os.name");
392 }
393 });
394 if ("SunOS".equals(osname)) {
395 return newInstance("jdk.net.SolarisSocketOptions");
396 } else if ("Linux".equals(osname)) {
397 return newInstance("jdk.net.LinuxSocketOptions");
398 } else if (osname.startsWith("Mac")) {
399 return newInstance("jdk.net.MacOSXSocketOptions");
400 } else {
401 return new PlatformSocketOptions();
402 }
403 }
404
405 private static final PlatformSocketOptions instance = create();
406
407 static PlatformSocketOptions get() {
408 return instance;
409 }
410
411 int setFlowOption(int fd, int priority, long bandwidth)
412 throws SocketException
413 {
414 throw new UnsupportedOperationException("unsupported socket option");
415 }
416
|
1 /*
2 * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
374 protected PlatformSocketOptions() {}
375
376 @SuppressWarnings("unchecked")
377 private static PlatformSocketOptions newInstance(String cn) {
378 Class<PlatformSocketOptions> c;
379 try {
380 c = (Class<PlatformSocketOptions>)Class.forName(cn);
381 return c.getConstructor(new Class<?>[] { }).newInstance();
382 } catch (ReflectiveOperationException x) {
383 throw new AssertionError(x);
384 }
385 }
386
387 private static PlatformSocketOptions create() {
388 String osname = AccessController.doPrivileged(
389 new PrivilegedAction<String>() {
390 public String run() {
391 return System.getProperty("os.name");
392 }
393 });
394 if ("Linux".equals(osname)) {
395 return newInstance("jdk.net.LinuxSocketOptions");
396 } else if (osname.startsWith("Mac")) {
397 return newInstance("jdk.net.MacOSXSocketOptions");
398 } else {
399 return new PlatformSocketOptions();
400 }
401 }
402
403 private static final PlatformSocketOptions instance = create();
404
405 static PlatformSocketOptions get() {
406 return instance;
407 }
408
409 int setFlowOption(int fd, int priority, long bandwidth)
410 throws SocketException
411 {
412 throw new UnsupportedOperationException("unsupported socket option");
413 }
414
|