提交 f6af3f3d 编写于 作者: A alanb

6965072: Need API to create SDP sockets

Reviewed-by: michaelm
上级 d3d5f56d
...@@ -31,7 +31,7 @@ BUILDDIR = .. ...@@ -31,7 +31,7 @@ BUILDDIR = ..
PRODUCT = com PRODUCT = com
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = sun SUBDIRS = sun oracle
include $(BUILDDIR)/common/Subdirs.gmk include $(BUILDDIR)/common/Subdirs.gmk
all build clean clobber:: all build clean clobber::
......
#
# Copyright (c) 2010, 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.
#
BUILDDIR = ../..
PRODUCT = oracle
include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = net
include $(BUILDDIR)/common/Subdirs.gmk
all build clean clobber::
$(SUBDIRS-loop)
#
# Copyright (c) 2010, 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.
#
BUILDDIR = ../../..
PRODUCT = oracle
include $(BUILDDIR)/common/Defs.gmk
#
# Files to compile
#
AUTO_FILES_JAVA_DIRS = com/oracle/net
#
# Rules
#
include $(BUILDDIR)/common/Classes.gmk
...@@ -91,6 +91,8 @@ SCTPAPI_PKGS = com.sun.nio.sctp ...@@ -91,6 +91,8 @@ SCTPAPI_PKGS = com.sun.nio.sctp
TRACING_PKGS = com.sun.tracing \ TRACING_PKGS = com.sun.tracing \
com.sun.tracing.dtrace com.sun.tracing.dtrace
ORACLENET_PKGS = com.oracle.net
# non-core packages in rt.jar # non-core packages in rt.jar
NON_CORE_PKGS = $(DOMAPI_PKGS) \ NON_CORE_PKGS = $(DOMAPI_PKGS) \
$(MGMT_PKGS) \ $(MGMT_PKGS) \
...@@ -101,5 +103,6 @@ NON_CORE_PKGS = $(DOMAPI_PKGS) \ ...@@ -101,5 +103,6 @@ NON_CORE_PKGS = $(DOMAPI_PKGS) \
$(HTTPSERVER_PKGS) \ $(HTTPSERVER_PKGS) \
$(SMARTCARDIO_PKGS) \ $(SMARTCARDIO_PKGS) \
$(TRACING_PKGS) \ $(TRACING_PKGS) \
$(SCTPAPI_PKGS) $(SCTPAPI_PKGS) \
$(ORACLENET_PKGS)
...@@ -39,10 +39,6 @@ FILES_c = \ ...@@ -39,10 +39,6 @@ FILES_c = \
ResolverConfigurationImpl.c \ ResolverConfigurationImpl.c \
DefaultProxySelector.c DefaultProxySelector.c
ifeq ($(PLATFORM), solaris)
FILES_c += SdpProvider.c
endif
ifeq ($(PLATFORM), linux) ifeq ($(PLATFORM), linux)
FILES_c += linux_close.c FILES_c += linux_close.c
endif endif
......
...@@ -44,6 +44,8 @@ ifeq ($(PLATFORM), windows) ...@@ -44,6 +44,8 @@ ifeq ($(PLATFORM), windows)
endif endif
FILES_c += NTLMAuthSequence.c FILES_c += NTLMAuthSequence.c
FILES_c += NetworkInterface_winXP.c FILES_c += NetworkInterface_winXP.c
else
FILES_c += SdpSupport.c
endif endif
FILES_export = \ FILES_export = \
...@@ -84,7 +86,8 @@ endif ...@@ -84,7 +86,8 @@ endif
# #
# Find platform specific native code # Find platform specific native code
# #
vpath %.c $(PLATFORM_SRC)/native/sun/net/dns $(PLATFORM_SRC)/native/sun/net/www/protocol/http/ntlm $(PLATFORM_SRC)/native/sun/net/spi vpath %.c $(PLATFORM_SRC)/native/sun/net/dns $(PLATFORM_SRC)/native/sun/net/www/protocol/http/ntlm \
$(PLATFORM_SRC)/native/sun/net/sdp $(PLATFORM_SRC)/native/sun/net/spi
# #
# Include rules # Include rules
......
...@@ -88,9 +88,10 @@ SUNWprivate_1.1 { ...@@ -88,9 +88,10 @@ SUNWprivate_1.1 {
Java_java_net_PlainDatagramSocketImpl_setTimeToLive; Java_java_net_PlainDatagramSocketImpl_setTimeToLive;
Java_sun_net_dns_ResolverConfigurationImpl_localDomain0; Java_sun_net_dns_ResolverConfigurationImpl_localDomain0;
Java_sun_net_dns_ResolverConfigurationImpl_fallbackDomain0; Java_sun_net_dns_ResolverConfigurationImpl_fallbackDomain0;
Java_sun_net_sdp_SdpSupport_convert0;
Java_sun_net_sdp_SdpSupport_create0;
Java_sun_net_spi_DefaultProxySelector_init; Java_sun_net_spi_DefaultProxySelector_init;
Java_sun_net_spi_DefaultProxySelector_getSystemProxy; Java_sun_net_spi_DefaultProxySelector_getSystemProxy;
Java_sun_net_spi_SdpProvider_convert;
NET_AllocSockaddr; NET_AllocSockaddr;
NET_SockaddrToInetAddress; NET_SockaddrToInetAddress;
NET_SockaddrEqualsInetAddress; NET_SockaddrEqualsInetAddress;
......
...@@ -199,6 +199,7 @@ FILES_src = \ ...@@ -199,6 +199,7 @@ FILES_src = \
sun/nio/ch/PipeImpl.java \ sun/nio/ch/PipeImpl.java \
sun/nio/ch/PollArrayWrapper.java \ sun/nio/ch/PollArrayWrapper.java \
sun/nio/ch/Reflect.java \ sun/nio/ch/Reflect.java \
sun/nio/ch/Secrets.java \
sun/nio/ch/SelectionKeyImpl.java \ sun/nio/ch/SelectionKeyImpl.java \
sun/nio/ch/SelectorImpl.java \ sun/nio/ch/SelectorImpl.java \
sun/nio/ch/SelectorProviderImpl.java \ sun/nio/ch/SelectorProviderImpl.java \
......
...@@ -53,6 +53,7 @@ FILES_java = \ ...@@ -53,6 +53,7 @@ FILES_java = \
sun/net/ftp/FtpProtocolException.java \ sun/net/ftp/FtpProtocolException.java \
sun/net/ftp/impl/FtpClient.java \ sun/net/ftp/impl/FtpClient.java \
sun/net/ftp/impl/DefaultFtpClientProvider.java \ sun/net/ftp/impl/DefaultFtpClientProvider.java \
sun/net/sdp/SdpSupport.java \
sun/net/spi/DefaultProxySelector.java \ sun/net/spi/DefaultProxySelector.java \
sun/net/spi/nameservice/NameServiceDescriptor.java \ sun/net/spi/nameservice/NameServiceDescriptor.java \
sun/net/spi/nameservice/NameService.java \ sun/net/spi/nameservice/NameService.java \
...@@ -136,8 +137,6 @@ FILES_java = \ ...@@ -136,8 +137,6 @@ FILES_java = \
ifeq ($(PLATFORM), windows) ifeq ($(PLATFORM), windows)
FILES_java += sun/net/www/protocol/http/ntlm/NTLMAuthSequence.java FILES_java += sun/net/www/protocol/http/ntlm/NTLMAuthSequence.java
endif else
FILES_java += sun/net/sdp/SdpProvider.java
ifeq ($(PLATFORM), solaris)
FILES_java += sun/net/spi/SdpProvider.java
endif endif
/*
* Copyright (c) 2010, 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.
*/
package com.oracle.net;
import java.net.Socket;
import java.net.ServerSocket;
import java.net.SocketImpl;
import java.net.SocketImplFactory;
import java.net.SocketException;
import java.nio.channels.SocketChannel;
import java.nio.channels.ServerSocketChannel;
import java.io.IOException;
import java.io.FileDescriptor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.lang.reflect.Constructor;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.InvocationTargetException;
import sun.net.sdp.SdpSupport;
/**
* This class consists exclusively of static methods that Sockets or Channels to
* sockets that support the InfiniBand Sockets Direct Protocol (SDP).
*/
public final class Sdp {
private Sdp() { }
/**
* The package-privage ServerSocket(SocketImpl) constructor
*/
private static final Constructor<ServerSocket> serverSocketCtor;
static {
try {
serverSocketCtor = (Constructor<ServerSocket>)
ServerSocket.class.getDeclaredConstructor(SocketImpl.class);
setAccessible(serverSocketCtor);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
/**
* The package-private SdpSocketImpl() constructor
*/
private static final Constructor<SocketImpl> socketImplCtor;
static {
try {
Class<?> cl = Class.forName("java.net.SdpSocketImpl", true, null);
socketImplCtor = (Constructor<SocketImpl>)cl.getDeclaredConstructor();
setAccessible(socketImplCtor);
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
private static void setAccessible(final AccessibleObject o) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
o.setAccessible(true);
return null;
}
});
}
/**
* SDP enabled Socket.
*/
private static class SdpSocket extends Socket {
SdpSocket(SocketImpl impl) throws SocketException {
super(impl);
}
}
/**
* Creates a SDP enabled SocketImpl
*/
private static SocketImpl createSocketImpl() {
try {
return socketImplCtor.newInstance();
} catch (InstantiationException x) {
throw new AssertionError(x);
} catch (IllegalAccessException x) {
throw new AssertionError(x);
} catch (InvocationTargetException x) {
throw new AssertionError(x);
}
}
/**
* Creates an unconnected and unbound SDP socket. The {@code Socket} is
* associated with a {@link java.net.SocketImpl} of the system-default type.
*
* @return a new Socket
*
* @throws UnsupportedOperationException
* If SDP is not supported
* @throws IOException
* If an I/O error occurs
*/
public static Socket openSocket() throws IOException {
SocketImpl impl = createSocketImpl();
return new SdpSocket(impl);
}
/**
* Creates an unbound SDP server socket. The {@code ServerSocket} is
* associated with a {@link java.net.SocketImpl} of the system-default type.
*
* @return a new ServerSocket
*
* @throws UnsupportedOperationException
* If SDP is not supported
* @throws IOException
* If an I/O error occurs
*/
public static ServerSocket openServerSocket() throws IOException {
// create ServerSocket via package-private constructor
SocketImpl impl = createSocketImpl();
try {
return serverSocketCtor.newInstance(impl);
} catch (IllegalAccessException x) {
throw new AssertionError(x);
} catch (InstantiationException x) {
throw new AssertionError(x);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
if (cause instanceof IOException)
throw (IOException)cause;
if (cause instanceof RuntimeException)
throw (RuntimeException)cause;
throw new RuntimeException(x);
}
}
/**
* Opens a socket channel to a SDP socket.
*
* <p> The channel will be associated with the system-wide default
* {@link java.nio.channels.spi.SelectorProvider SelectorProvider}.
*
* @return a new SocketChannel
*
* @throws UnsupportedOperationException
* If SDP is not supported or not supported by the default selector
* provider
* @throws IOException
* If an I/O error occurs.
*/
public static SocketChannel openSocketChannel() throws IOException {
FileDescriptor fd = SdpSupport.createSocket();
return sun.nio.ch.Secrets.newSocketChannel(fd);
}
/**
* Opens a socket channel to a SDP socket.
*
* <p> The channel will be associated with the system-wide default
* {@link java.nio.channels.spi.SelectorProvider SelectorProvider}.
*
* @return a new ServerSocketChannel
*
* @throws UnsupportedOperationException
* If SDP is not supported or not supported by the default selector
* provider
* @throws IOException
* If an I/O error occurs
*/
public static ServerSocketChannel openServerSocketChannel()
throws IOException
{
FileDescriptor fd = SdpSupport.createSocket();
return sun.nio.ch.Secrets.newServerSocketChannel(fd);
}
}
/*
* Copyright (c) 2010, 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.
*/
package java.net;
import java.io.IOException;
import java.io.FileDescriptor;
import sun.net.sdp.SdpSupport;
/**
* SocketImpl that supports the SDP protocol
*/
class SdpSocketImpl extends PlainSocketImpl {
SdpSocketImpl() { }
@Override
protected void create(boolean stream) throws IOException {
if (!stream)
throw new UnsupportedOperationException("Must be a stream socket");
fd = SdpSupport.createSocket();
if (socket != null)
socket.setCreated();
if (serverSocket != null)
serverSocket.setCreated();
}
}
...@@ -68,6 +68,15 @@ class ServerSocket implements java.io.Closeable { ...@@ -68,6 +68,15 @@ class ServerSocket implements java.io.Closeable {
*/ */
private boolean oldImpl = false; private boolean oldImpl = false;
/**
* Package-private constructor to create a ServerSocket associated with
* the given SocketImpl.
*/
ServerSocket(SocketImpl impl) {
this.impl = impl;
impl.setServerSocket(this);
}
/** /**
* Creates an unbound server socket. * Creates an unbound server socket.
* *
......
/*
* Copyright (c) 2010, 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.
*/
package sun.net.sdp;
import java.io.IOException;
import java.io.FileDescriptor;
import java.security.AccessController;
import sun.misc.SharedSecrets;
import sun.misc.JavaIOFileDescriptorAccess;
/**
* This class defines methods for creating SDP sockets or "converting" existing
* file descriptors, referencing (unbound) TCP sockets, to SDP.
*/
public final class SdpSupport {
private static final String os = AccessController
.doPrivileged(new sun.security.action.GetPropertyAction("os.name"));
private static final boolean isSupported = (os.equals("SunOS") || (os.equals("Linux")));
private static final JavaIOFileDescriptorAccess fdAccess =
SharedSecrets.getJavaIOFileDescriptorAccess();
private SdpSupport() { }
/**
* Creates a SDP socket, returning file descriptor referencing the socket.
*/
public static FileDescriptor createSocket() throws IOException {
if (!isSupported)
throw new UnsupportedOperationException("SDP not supported on this platform");
int fdVal = create0();
FileDescriptor fd = new FileDescriptor();
fdAccess.set(fd, fdVal);
return fd;
}
/**
* Converts an existing file descriptor, that references an unbound TCP socket,
* to SDP.
*/
public static void convertSocket(FileDescriptor fd) throws IOException {
if (!isSupported)
throw new UnsupportedOperationException("SDP not supported on this platform");
int fdVal = fdAccess.get(fd);
convert0(fdVal);
}
private static native int create0() throws IOException;
private static native void convert0(int fd) throws IOException;
static {
AccessController.doPrivileged(
new sun.security.action.LoadLibraryAction("net"));
}
}
/*
* Copyright (c) 2010, 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.
*/
package sun.nio.ch;
import java.nio.channels.SocketChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.io.FileDescriptor;
import java.io.IOException;
/**
* Provides access to implementation private constructors and methods.
*/
public final class Secrets {
private Secrets() { }
private static SelectorProvider provider() {
SelectorProvider p = SelectorProvider.provider();
if (!(p instanceof SelectorProviderImpl))
throw new UnsupportedOperationException();
return p;
}
public static SocketChannel newSocketChannel(FileDescriptor fd) {
try {
return new SocketChannelImpl(provider(), fd, false);
} catch (IOException ioe) {
throw new AssertionError(ioe);
}
}
public static ServerSocketChannel newServerSocketChannel(FileDescriptor fd) {
try {
return new ServerSocketChannelImpl(provider(), fd, false);
} catch (IOException ioe) {
throw new AssertionError(ioe);
}
}
}
...@@ -80,20 +80,23 @@ class ServerSocketChannelImpl ...@@ -80,20 +80,23 @@ class ServerSocketChannelImpl
// -- End of fields protected by stateLock // -- End of fields protected by stateLock
public ServerSocketChannelImpl(SelectorProvider sp) throws IOException { ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
super(sp); super(sp);
this.fd = Net.serverSocket(true); this.fd = Net.serverSocket(true);
this.fdVal = IOUtil.fdVal(fd); this.fdVal = IOUtil.fdVal(fd);
this.state = ST_INUSE; this.state = ST_INUSE;
} }
public ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd) ServerSocketChannelImpl(SelectorProvider sp,
FileDescriptor fd,
boolean bound)
throws IOException throws IOException
{ {
super(sp); super(sp);
this.fd = fd; this.fd = fd;
this.fdVal = IOUtil.fdVal(fd); this.fdVal = IOUtil.fdVal(fd);
this.state = ST_INUSE; this.state = ST_INUSE;
if (bound)
localAddress = Net.localAddress(fd); localAddress = Net.localAddress(fd);
} }
......
...@@ -103,6 +103,19 @@ class SocketChannelImpl ...@@ -103,6 +103,19 @@ class SocketChannelImpl
this.state = ST_UNCONNECTED; this.state = ST_UNCONNECTED;
} }
SocketChannelImpl(SelectorProvider sp,
FileDescriptor fd,
boolean bound)
throws IOException
{
super(sp);
this.fd = fd;
this.fdVal = IOUtil.fdVal(fd);
this.state = ST_UNCONNECTED;
if (bound)
this.localAddress = Net.localAddress(fd);
}
// Constructor for sockets obtained from server sockets // Constructor for sockets obtained from server sockets
// //
SocketChannelImpl(SelectorProvider sp, SocketChannelImpl(SelectorProvider sp,
......
...@@ -73,28 +73,7 @@ public final class NetHooks { ...@@ -73,28 +73,7 @@ public final class NetHooks {
* be changed to use the ServiceLoader facility to allow the deployment of * be changed to use the ServiceLoader facility to allow the deployment of
* other providers. * other providers.
*/ */
private static Provider loadProvider(final String cn) { private static final Provider provider = new sun.net.sdp.SdpProvider();
return AccessController
.doPrivileged(new PrivilegedAction<Provider>() {
@Override public Provider run() {
Class<Provider> c;
try {
c = (Class<Provider>)Class.forName(cn, true, null);
} catch (ClassNotFoundException x) {
return null;
}
try {
return c.newInstance();
} catch (IllegalAccessException x) {
throw new AssertionError(x);
} catch (InstantiationException x) {
throw new AssertionError(x);
}
}});
}
private static final Provider provider = AccessController
.doPrivileged(new GetPropertyAction("os.name")).equals("SunOS") ?
loadProvider("sun.net.spi.SdpProvider") : null;
/** /**
* Invoke prior to binding a TCP socket. * Invoke prior to binding a TCP socket.
...@@ -104,7 +83,6 @@ public final class NetHooks { ...@@ -104,7 +83,6 @@ public final class NetHooks {
int port) int port)
throws IOException throws IOException
{ {
if (provider != null)
provider.implBeforeTcpBind(fdObj, address, port); provider.implBeforeTcpBind(fdObj, address, port);
} }
...@@ -116,7 +94,6 @@ public final class NetHooks { ...@@ -116,7 +94,6 @@ public final class NetHooks {
int port) int port)
throws IOException throws IOException
{ {
if (provider != null)
provider.implBeforeTcpConnect(fdObj, address, port); provider.implBeforeTcpConnect(fdObj, address, port);
} }
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* questions. * questions.
*/ */
package sun.net.spi; package sun.net.sdp;
import sun.net.NetHooks; import sun.net.NetHooks;
import java.net.InetAddress; import java.net.InetAddress;
...@@ -34,9 +34,10 @@ import java.io.File; ...@@ -34,9 +34,10 @@ import java.io.File;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.security.AccessController;
import sun.misc.SharedSecrets; import sun.net.sdp.SdpSupport;
import sun.misc.JavaIOFileDescriptorAccess; import sun.security.action.GetPropertyAction;
/** /**
* A NetHooks provider that converts sockets from the TCP to SDP protocol prior * A NetHooks provider that converts sockets from the TCP to SDP protocol prior
...@@ -44,9 +45,6 @@ import sun.misc.JavaIOFileDescriptorAccess; ...@@ -44,9 +45,6 @@ import sun.misc.JavaIOFileDescriptorAccess;
*/ */
public class SdpProvider extends NetHooks.Provider { public class SdpProvider extends NetHooks.Provider {
private static final JavaIOFileDescriptorAccess fdAccess =
SharedSecrets.getJavaIOFileDescriptorAccess();
// maximum port // maximum port
private static final int MAX_PORT = 65535; private static final int MAX_PORT = 65535;
...@@ -59,7 +57,8 @@ public class SdpProvider extends NetHooks.Provider { ...@@ -59,7 +57,8 @@ public class SdpProvider extends NetHooks.Provider {
public SdpProvider() { public SdpProvider() {
// if this property is not defined then there is nothing to do. // if this property is not defined then there is nothing to do.
String file = System.getProperty("com.sun.sdp.conf"); String file = AccessController.doPrivileged(
new GetPropertyAction("com.sun.sdp.conf"));
if (file == null) { if (file == null) {
this.enabled = false; this.enabled = false;
this.rules = null; this.rules = null;
...@@ -78,7 +77,8 @@ public class SdpProvider extends NetHooks.Provider { ...@@ -78,7 +77,8 @@ public class SdpProvider extends NetHooks.Provider {
// check if debugging is enabled // check if debugging is enabled
PrintStream out = null; PrintStream out = null;
String logfile = System.getProperty("com.sun.sdp.debug"); String logfile = AccessController.doPrivileged(
new GetPropertyAction("com.sun.sdp.debug"));
if (logfile != null) { if (logfile != null) {
out = System.out; out = System.out;
if (logfile.length() > 0) { if (logfile.length() > 0) {
...@@ -297,8 +297,7 @@ public class SdpProvider extends NetHooks.Provider { ...@@ -297,8 +297,7 @@ public class SdpProvider extends NetHooks.Provider {
boolean matched = false; boolean matched = false;
for (Rule rule: rules) { for (Rule rule: rules) {
if (rule.match(action, address, port)) { if (rule.match(action, address, port)) {
int fd = fdAccess.get(fdObj); SdpSupport.convertSocket(fdObj);
convert(fd);
matched = true; matched = true;
break; break;
} }
...@@ -333,7 +332,4 @@ public class SdpProvider extends NetHooks.Provider { ...@@ -333,7 +332,4 @@ public class SdpProvider extends NetHooks.Provider {
if (enabled) if (enabled)
convertTcpToSdpIfMatch(fdObj, Action.CONNECT, address, port); convertTcpToSdpIfMatch(fdObj, Action.CONNECT, address, port);
} }
// -- native methods --
private static native void convert(int fd) throws IOException;
} }
...@@ -96,7 +96,7 @@ class InheritedChannel { ...@@ -96,7 +96,7 @@ class InheritedChannel {
FileDescriptor fd) FileDescriptor fd)
throws IOException throws IOException
{ {
super(sp, fd); super(sp, fd, true);
} }
protected void implCloseSelectableChannel() throws IOException { protected void implCloseSelectableChannel() throws IOException {
......
...@@ -25,9 +25,16 @@ ...@@ -25,9 +25,16 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <errno.h>
#if defined(__solaris__) && !defined(PROTO_SDP) #if defined(__solaris__)
#define PROTO_SDP 257 #if !defined(PROTO_SDP)
#define PROTO_SDP 257
#endif
#elif defined(__linux__)
#if !defined(AF_INET_SDP)
#define AF_INET_SDP 27
#endif
#endif #endif
#include "jni.h" #include "jni.h"
...@@ -40,20 +47,61 @@ ...@@ -40,20 +47,61 @@
} while((_result == -1) && (errno == EINTR)); \ } while((_result == -1) && (errno == EINTR)); \
} while(0) } while(0)
JNIEXPORT void JNICALL
Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd) /**
* Creates a SDP socket.
*/
static int create(JNIEnv* env)
{ {
#ifdef PROTO_SDP int s;
#ifdef AF_INET6
#if defined(__solaris__)
#ifdef AF_INET6
int domain = ipv6_available() ? AF_INET6 : AF_INET; int domain = ipv6_available() ? AF_INET6 : AF_INET;
#else #else
int domain = AF_INET; int domain = AF_INET;
#endif
s = socket(domain, SOCK_STREAM, PROTO_SDP);
#elif defined(__linux__)
/**
* IPv6 not supported by SDP on Linux
*/
if (ipv6_available()) {
JNU_ThrowIOException(env, "IPv6 not supported");
return;
}
s = socket(AF_INET_SDP, SOCK_STREAM, 0);
#else
/* not supported on other platforms at this time */
s = -1;
errno = EPROTONOSUPPORT;
#endif #endif
int s = socket(domain, SOCK_STREAM, PROTO_SDP);
if (s < 0) { if (s < 0)
JNU_ThrowIOExceptionWithLastError(env, "socket"); JNU_ThrowIOExceptionWithLastError(env, "socket");
} else { return s;
int arg, len, res; }
/**
* Creates a SDP socket, returning file descriptor referencing the socket.
*/
JNIEXPORT jint JNICALL
Java_sun_net_sdp_SdpSupport_create0(JNIEnv *env, jclass cls)
{
return create(env);
}
/**
* Converts an existing file descriptor, that references an unbound TCP socket,
* to SDP.
*/
JNIEXPORT void JNICALL
Java_sun_net_sdp_SdpSupport_convert0(JNIEnv *env, jclass cls, int fd)
{
int s = create(env);
if (s >= 0) {
socklen_t len;
int arg, res;
struct linger linger; struct linger linger;
/* copy socket options that are relevant to SDP */ /* copy socket options that are relevant to SDP */
...@@ -72,7 +120,4 @@ Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd) ...@@ -72,7 +120,4 @@ Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd)
JNU_ThrowIOExceptionWithLastError(env, "dup2"); JNU_ThrowIOExceptionWithLastError(env, "dup2");
RESTARTABLE(close(s), res); RESTARTABLE(close(s), res);
} }
#else
JNU_ThrowInternalError(env, "should not reach here");
#endif
} }
/*
* Copyright (c) 2010, 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.
*/
import com.oracle.net.Sdp;
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.*;
/**
* Exercise com.oracle.net.Sdp with each IP address plumbed to InfiniBand
* interfaces listed in a given file.
*/
public class Sanity {
public static void main(String[] args) throws Exception {
// The file is a list of interfaces to test.
Scanner s = new Scanner(new File(args[0]));
try {
while (s.hasNextLine()) {
String link = s.nextLine();
NetworkInterface ni = NetworkInterface.getByName(link);
if (ni != null) {
Enumeration<InetAddress> addrs = ni.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
System.out.format("Testing %s: %s\n", link, addr.getHostAddress());
test(addr);
}
}
}
} finally {
s.close();
}
}
static void test(InetAddress addr) throws Exception {
// Test SocketChannel and ServerSocketChannel
ServerSocketChannel ssc = Sdp.openServerSocketChannel();
try {
ssc.socket().bind(new InetSocketAddress(addr, 0));
int port = ssc.socket().getLocalPort();
// SocketChannel.connect (implicit bind)
SocketChannel client = Sdp.openSocketChannel();
try {
client.connect(new InetSocketAddress(addr, port));
SocketChannel peer = ssc.accept();
try {
testConnection(Channels.newOutputStream(client),
Channels.newInputStream(peer));
} finally {
peer.close();
}
} finally {
client.close();
}
// SocketChannel.connect (explicit bind)
client = Sdp.openSocketChannel();
try {
client.socket().bind(new InetSocketAddress(addr, 0));
client.connect(new InetSocketAddress(addr, port));
ssc.accept().close();
} finally {
client.close();
}
} finally {
ssc.close();
}
// Test Socket and ServerSocket
ServerSocket ss = Sdp.openServerSocket();
try {
ss.bind(new InetSocketAddress(addr, 0));
int port = ss.getLocalPort();
// Socket.connect (implicit bind)
Socket s = Sdp.openSocket();
try {
s.connect(new InetSocketAddress(addr, port));
Socket peer = ss.accept();
try {
testConnection(s.getOutputStream(), peer.getInputStream());
} finally {
peer.close();
}
} finally {
s.close();
}
// Socket.connect (explicit bind)
s = Sdp.openSocket();
try {
s.bind(new InetSocketAddress(addr, 0));
s.connect(new InetSocketAddress(addr, port));
ss.accept().close();
} finally {
s.close();
}
} finally {
ss.close();
}
}
static void testConnection(OutputStream out, InputStream in)
throws IOException
{
byte[] msg = "hello".getBytes();
out.write(msg);
byte[] ba = new byte[100];
int nread = 0;
while (nread < msg.length) {
int n = in.read(ba);
if (n < 0)
throw new IOException("EOF not expected!");
nread += n;
}
}
}
#
# Copyright (c) 2010, 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 6965072
# @summary Unit test for SDP support
# @build Sanity
# @run shell sanity.sh
IB_LINKS=ib.links
OS=`uname -s`
case "$OS" in
SunOS )
/usr/sbin/dladm show-part -o LINK -p > ${IB_LINKS}
if [ $? != 0 ]; then
echo "Unable to get InfiniBand parition link information"
exit 0
fi
;;
Linux )
if [ ! -f /proc/net/sdp ]; then
echo "InfiniBand SDP module not installed"
exit 0
fi
egrep "^[ \t]+ib" /proc/net/dev|cut -d':' -f1|tr -d '\t ' > ${IB_LINKS}
;;
* )
echo "This test only runs on Solaris or Linux"
exit 0
;;
esac
if [ -z "$TESTJAVA" ]; then
JAVA=java
TESTCLASSES=.
TESTSRC=.
else
JAVA="${TESTJAVA}/bin/java"
fi
CLASSPATH=${TESTCLASSES}:${TESTSRC}
export CLASSPATH
# Run sanity test (IPv4-only for now)
$JAVA -Djava.net.preferIPv4Stack=true Sanity ${IB_LINKS}
...@@ -34,21 +34,16 @@ import java.util.Enumeration; ...@@ -34,21 +34,16 @@ import java.util.Enumeration;
public class ProbeIB { public class ProbeIB {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
Scanner s = new Scanner(new File("/etc/path_to_inst")); Scanner s = new Scanner(new File(args[0]));
try { try {
while (s.hasNextLine()) { while (s.hasNextLine()) {
String line = s.nextLine(); String link = s.nextLine();
if (line.startsWith("#")) NetworkInterface ni = NetworkInterface.getByName(link);
continue;
String[] fields = line.split("\\s+");
if (!fields[2].equals("\"ibd\""))
continue;
String name = fields[2].substring(1, fields[2].length()-1) + fields[1];
NetworkInterface ni = NetworkInterface.getByName(name);
if (ni != null) { if (ni != null) {
Enumeration<InetAddress> addrs = ni.getInetAddresses(); Enumeration<InetAddress> addrs = ni.getInetAddresses();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
System.out.println(addrs.nextElement().getHostAddress()); InetAddress addr = addrs.nextElement();
System.out.println(addr.getHostAddress());
} }
} }
} }
......
...@@ -33,14 +33,15 @@ if [ "$OS" != "SunOS" ]; then ...@@ -33,14 +33,15 @@ if [ "$OS" != "SunOS" ]; then
echo "This is a Solaris-only test" echo "This is a Solaris-only test"
exit 0 exit 0
fi fi
SDPADM=/usr/sbin/sdpadm
if [ ! -f ${SDPADM} ]; then IB_LINKS=ib.links
echo "SDP not available" IB_ADDRS=ib.addrs
exit 0
fi # Display IB partition link information
${SDPADM} status|grep Enabled # (requires Solaris 11, will fail on Solaris 10)
/usr/sbin/dladm show-part -o LINK -p > ${IB_LINKS}
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "SDP not enabled" echo "Unable to get IB parition link information"
exit 0 exit 0
fi fi
...@@ -56,13 +57,13 @@ CLASSPATH=${TESTCLASSES}:${TESTSRC} ...@@ -56,13 +57,13 @@ CLASSPATH=${TESTCLASSES}:${TESTSRC}
export CLASSPATH export CLASSPATH
# Probe for IP addresses plumbed to IB interfaces # Probe for IP addresses plumbed to IB interfaces
$JAVA -Djava.net.preferIPv4Stack=true ProbeIB > ib_addrs $JAVA -Djava.net.preferIPv4Stack=true ProbeIB ${IB_LINKS} > ${IB_ADDRS}
# Create sdp.conf # Create sdp.conf
SDPCONF=sdp.conf SDPCONF=sdp.conf
rm ${SDPCONF} rm ${SDPCONF}
touch ${SDPCONF} touch ${SDPCONF}
cat ib_addrs | while read ADDR cat ${IB_ADDRS} | while read ADDR
do do
echo "bind ${ADDR} *" > ${SDPCONF} echo "bind ${ADDR} *" > ${SDPCONF}
echo "connect ${ADDR} *" >> ${SDPCONF} echo "connect ${ADDR} *" >> ${SDPCONF}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册