/* * Copyright (c) 2000, 2021, 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. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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.
*/
/** * Returns true if exclusive binding is on
*/ staticboolean useExclusiveBind() { return exclusiveBind;
}
/** * Tells whether both IPV6_XXX and IP_XXX socket options should be set on * IPv6 sockets. On some kernels, both IPV6_XXX and IP_XXX socket options * need to be set so that the settings are effective for IPv4 multicast * datagrams sent using the socket.
*/ staticboolean shouldSetBothIPv4AndIPv6Options() { return shouldSetBothIPv4AndIPv6Options0();
}
/** * Tells whether IPv6 sockets can join IPv4 multicast groups
*/ staticboolean canIPv6SocketJoinIPv4Group() { return canIPv6SocketJoinIPv4Group0();
}
/** * Tells whether {@link #join6} can be used to join an IPv4 * multicast group (IPv4 group as IPv4-mapped IPv6 address)
*/ staticboolean canJoin6WithIPv4Group() { return canJoin6WithIPv4Group0();
}
/** * Tells whether IPV6_XXX socket options should be used on an IPv6 socket * that is bound to an IPv4 address.
*/ staticboolean canUseIPv6OptionsWithIPv4LocalAddress() { return canUseIPv6OptionsWithIPv4LocalAddress0();
}
staticvoid translateException(Exception x, boolean unknownHostForUnresolved) throws IOException
{ if (x instanceof IOException) throw (IOException)x; // Throw UnknownHostException from here since it cannot // be thrown as a SocketException if (unknownHostForUnresolved &&
(x instanceof UnresolvedAddressException))
{ thrownew UnknownHostException();
}
translateToSocketException(x);
}
/** * Returns the wildcard address that corresponds to the given protocol family. * * @see InetAddress#isAnyLocalAddress()
*/ static InetAddress anyLocalAddress(ProtocolFamily family) { if (family == StandardProtocolFamily.INET) { return anyLocalInet4Address;
} elseif (family == StandardProtocolFamily.INET6) { return anyLocalInet6Address;
} else { thrownew IllegalArgumentException();
}
}
/** * Returns any IPv4 address of the given network interface, or * null if the interface does not have any IPv4 addresses.
*/
@SuppressWarnings("removal") static Inet4Address anyInet4Address(final NetworkInterface interf) { return AccessController.doPrivileged(new PrivilegedAction<Inet4Address>() { public Inet4Address run() {
Enumeration<InetAddress> addrs = interf.getInetAddresses(); while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement(); if (addr instanceof Inet4Address) { return (Inet4Address)addr;
}
} returnnull;
}
});
}
/** * Returns an IPv4 address as an int.
*/ staticint inet4AsInt(InetAddress ia) { if (ia instanceof Inet4Address) { byte[] addr = ia.getAddress(); int address = addr[3] & 0xFF;
address |= ((addr[2] << 8) & 0xFF00);
address |= ((addr[1] << 16) & 0xFF0000);
address |= ((addr[0] << 24) & 0xFF000000); return address;
} thrownew AssertionError("Should not reach here");
}
// only simple values supported by this method Class<?> type = name.type(); boolean isIPv6 = (family == StandardProtocolFamily.INET6);
if (extendedOptions.isOptionSupported(name)) {
extendedOptions.setOption(fd, name, value, isIPv6); return;
}
if (type != Integer.class && type != Boolean.class) thrownew AssertionError("Should not reach here");
// special handling if (name == StandardSocketOptions.SO_RCVBUF ||
name == StandardSocketOptions.SO_SNDBUF)
{ int i = ((Integer)value).intValue(); if (i < 0) thrownew IllegalArgumentException("Invalid send/receive buffer size");
} if (name == StandardSocketOptions.SO_LINGER) { int i = ((Integer)value).intValue(); if (i < 0)
value = Integer.valueOf(-1); if (i > 65535)
value = Integer.valueOf(65535);
} if (name == StandardSocketOptions.IP_TOS) { int i = ((Integer)value).intValue(); if (i < 0 || i > 255) thrownew IllegalArgumentException("Invalid IP_TOS value");
} if (name == StandardSocketOptions.IP_MULTICAST_TTL) { int i = ((Integer)value).intValue(); if (i < 0 || i > 255) thrownew IllegalArgumentException("Invalid TTL/hop value");
}
// map option name to platform level/name
OptionKey key = SocketOptionRegistry.findOption(name, family); if (key == null) thrownew AssertionError("Option not found");
int arg; if (type == Integer.class) {
arg = ((Integer)value).intValue();
} else { boolean b = ((Boolean)value).booleanValue();
arg = (b) ? 1 : 0;
}
// only simple values supported by this method if (type != Integer.class && type != Boolean.class) thrownew AssertionError("Should not reach here");
// map option name to platform level/name
OptionKey key = SocketOptionRegistry.findOption(name, family); if (key == null) thrownew AssertionError("Option not found");
boolean mayNeedConversion = (family == UNSPEC); int value = getIntOption0(fd, mayNeedConversion, key.level(), key.name());
// Due to oddities SO_REUSEADDR on windows reuse is ignored privatestaticnativeint socket0(boolean preferIPv6, boolean stream, boolean reuse, boolean fastLoopback);
privatestaticnativeint getIntOption0(FileDescriptor fd, boolean mayNeedConversion, int level, int opt) throws IOException;
privatestaticnativevoid setIntOption0(FileDescriptor fd, boolean mayNeedConversion, int level, int opt, int arg, boolean isIPv6) throws IOException;
/** * Polls a file descriptor for events. * @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely * @return the polled events or 0 if no events are polled
*/ staticnativeint poll(FileDescriptor fd, int events, long timeout) throws IOException;
/** * Performs a non-blocking poll of a file descriptor. * @return the polled events or 0 if no events are polled
*/ staticint pollNow(FileDescriptor fd, int events) throws IOException { return poll(fd, events, 0);
}
/** * Polls a connecting socket to test if the connection has been established. * * @apiNote This method is public to allow it be used by code in jdk.sctp. * * @param timeout the timeout to wait; 0 to not wait, -1 to wait indefinitely * @return true if connected
*/ publicstaticnativeboolean pollConnect(FileDescriptor fd, long timeout) throws IOException;
/** * Performs a non-blocking poll of a connecting socket to test if the * connection has been established. * * @return true if connected
*/ staticboolean pollConnectNow(FileDescriptor fd) throws IOException { return pollConnect(fd, 0);
}
/** * Return the number of bytes in the socket input buffer.
*/ staticnativeint available(FileDescriptor fd) throws IOException;
/** * Send one byte of urgent data (MSG_OOB) on the socket.
*/ staticnativeint sendOOB(FileDescriptor fd, byte data) throws IOException;
/** * Read and discard urgent data (MSG_OOB) on the socket.
*/ staticnativeboolean discardOOB(FileDescriptor fd) throws IOException;
// -- Multicast support --
/** * Join IPv4 multicast group
*/ staticint join4(FileDescriptor fd, int group, int interf, int source) throws IOException
{ return joinOrDrop4(true, fd, group, interf, source);
}
/** * Drop membership of IPv4 multicast group
*/ staticvoid drop4(FileDescriptor fd, int group, int interf, int source) throws IOException
{
joinOrDrop4(false, fd, group, interf, source);
}
privatestaticnativeint joinOrDrop4(boolean join, FileDescriptor fd, int group, int interf, int source) throws IOException;
/** * Block IPv4 source
*/ staticint block4(FileDescriptor fd, int group, int interf, int source) throws IOException
{ return blockOrUnblock4(true, fd, group, interf, source);
}
/** * Unblock IPv6 source
*/ staticvoid unblock4(FileDescriptor fd, int group, int interf, int source) throws IOException
{
blockOrUnblock4(false, fd, group, interf, source);
}
privatestaticnativeint blockOrUnblock4(boolean block, FileDescriptor fd, int group, int interf, int source) throws IOException;
/** * Event masks for the various poll system calls. * They will be set platform dependent in the static initializer below.
*/ publicstaticfinalshort POLLIN; publicstaticfinalshort POLLOUT; publicstaticfinalshort POLLERR; publicstaticfinalshort POLLHUP; publicstaticfinalshort POLLNVAL; publicstaticfinalshort POLLCONN;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.