# HG changeset patch # User igerasim # Date 1520367882 28800 # Tue Mar 06 12:24:42 2018 -0800 # Node ID 71dfb717041b73796c665c889c63d2a90d4c1402 # Parent a5b237cfccef5cecaa13d3caa5dfd54a3f987cef imported patch 8198358-Change-DualStackPlainSocketImpl-to-align-its-organization-with-TwoStacksPlainSocketImp-00-reorder diff --git a/src/java.base/windows/classes/java/net/DualStackPlainSocketImpl.java b/src/java.base/windows/classes/java/net/DualStackPlainSocketImpl.java --- a/src/java.base/windows/classes/java/net/DualStackPlainSocketImpl.java +++ b/src/java.base/windows/classes/java/net/DualStackPlainSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2018, 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 @@ -49,6 +49,10 @@ // emulates SO_REUSEADDR when exclusiveBind is true private boolean isReuseAddress; + static { + initIDs(); + } + public DualStackPlainSocketImpl(boolean exclBind) { exclusiveBind = exclBind; } @@ -58,45 +62,7 @@ exclusiveBind = exclBind; } - void socketCreate(boolean stream) throws IOException { - if (fd == null) - throw new SocketException("Socket closed"); - - int newfd = socket0(stream, false /*v6 Only*/); - - fdAccess.set(fd, newfd); - } - - void socketConnect(InetAddress address, int port, int timeout) - throws IOException { - int nativefd = checkAndReturnNativeFD(); - - if (address == null) - throw new NullPointerException("inet address argument is null."); - - int connectResult; - if (timeout <= 0) { - connectResult = connect0(nativefd, address, port); - } else { - configureBlocking(nativefd, false); - try { - connectResult = connect0(nativefd, address, port); - if (connectResult == WOULDBLOCK) { - waitForConnect(nativefd, timeout); - } - } finally { - configureBlocking(nativefd, true); - } - } - /* - * We need to set the local port field. If bind was called - * previous to the connect (by the client) then localport field - * will already be set. - */ - if (localport == 0) - localport = localPort0(nativefd); - } - + @Override void socketBind(InetAddress address, int port) throws IOException { int nativefd = checkAndReturnNativeFD(); @@ -113,67 +79,8 @@ this.address = address; } - void socketListen(int backlog) throws IOException { - int nativefd = checkAndReturnNativeFD(); - - listen0(nativefd, backlog); - } - - void socketAccept(SocketImpl s) throws IOException { - int nativefd = checkAndReturnNativeFD(); - - if (s == null) - throw new NullPointerException("socket is null"); - - int newfd = -1; - InetSocketAddress[] isaa = new InetSocketAddress[1]; - if (timeout <= 0) { - newfd = accept0(nativefd, isaa); - } else { - configureBlocking(nativefd, false); - try { - waitForNewConnection(nativefd, timeout); - newfd = accept0(nativefd, isaa); - if (newfd != -1) { - configureBlocking(newfd, true); - } - } finally { - configureBlocking(nativefd, true); - } - } - /* Update (SocketImpl)s' fd */ - fdAccess.set(s.fd, newfd); - /* Update socketImpls remote port, address and localport */ - InetSocketAddress isa = isaa[0]; - s.port = isa.getPort(); - s.address = isa.getAddress(); - s.localport = localport; - } - - int socketAvailable() throws IOException { - int nativefd = checkAndReturnNativeFD(); - return available0(nativefd); - } - - void socketClose0(boolean useDeferredClose/*unused*/) throws IOException { - if (fd == null) - throw new SocketException("Socket closed"); - - if (!fd.valid()) - return; - - final int nativefd = fdAccess.get(fd); - fdAccess.set(fd, -1); - close0(nativefd); - } - - void socketShutdown(int howto) throws IOException { - int nativefd = checkAndReturnNativeFD(); - shutdown0(nativefd, howto); - } - - // Intentional fallthrough after SO_REUSEADDR - @SuppressWarnings("fallthrough") + @Override + @SuppressWarnings("fallthrough") // Intentional fallthrough after SO_REUSEADDR void socketSetOption(int opt, boolean on, Object value) throws SocketException { int nativefd = checkAndReturnNativeFD(); @@ -220,6 +127,131 @@ setIntOption(nativefd, opt, optionValue); } + static native void initIDs(); + + void socketCreate(boolean stream) throws IOException { + if (fd == null) + throw new SocketException("Socket closed"); + + int newfd = socket0(stream, false /*v6 Only*/); + + fdAccess.set(fd, newfd); + } + static native int socket0(boolean stream, boolean v6Only) throws IOException; + + void socketConnect(InetAddress address, int port, int timeout) + throws IOException { + int nativefd = checkAndReturnNativeFD(); + + if (address == null) + throw new NullPointerException("inet address argument is null."); + + int connectResult; + if (timeout <= 0) { + connectResult = connect0(nativefd, address, port); + } else { + configureBlocking(nativefd, false); + try { + connectResult = connect0(nativefd, address, port); + if (connectResult == WOULDBLOCK) { + waitForConnect(nativefd, timeout); + } + } finally { + configureBlocking(nativefd, true); + } + } + /* + * We need to set the local port field. If bind was called + * previous to the connect (by the client) then localport field + * will already be set. + */ + if (localport == 0) + localport = localPort0(nativefd); + } + static native int connect0(int fd, InetAddress remote, int remotePort) + throws IOException; + static native void waitForConnect(int fd, int timeout) throws IOException; + static native void configureBlocking(int fd, boolean blocking) throws IOException; + static native int localPort0(int fd) throws IOException; + + + static native void bind0(int fd, InetAddress localAddress, int localport, + boolean exclBind) + throws IOException; + + + void socketListen(int backlog) throws IOException { + int nativefd = checkAndReturnNativeFD(); + + listen0(nativefd, backlog); + } + static native void listen0(int fd, int backlog) throws IOException; + + void socketAccept(SocketImpl s) throws IOException { + int nativefd = checkAndReturnNativeFD(); + + if (s == null) + throw new NullPointerException("socket is null"); + + int newfd = -1; + InetSocketAddress[] isaa = new InetSocketAddress[1]; + if (timeout <= 0) { + newfd = accept0(nativefd, isaa); + } else { + configureBlocking(nativefd, false); + try { + waitForNewConnection(nativefd, timeout); + newfd = accept0(nativefd, isaa); + if (newfd != -1) { + configureBlocking(newfd, true); + } + } finally { + configureBlocking(nativefd, true); + } + } + /* Update (SocketImpl)s' fd */ + fdAccess.set(s.fd, newfd); + /* Update socketImpls remote port, address and localport */ + InetSocketAddress isa = isaa[0]; + s.port = isa.getPort(); + s.address = isa.getAddress(); + s.localport = localport; + } + static native int accept0(int fd, InetSocketAddress[] isaa) throws IOException; + static native void waitForNewConnection(int fd, int timeout) throws IOException; + + + int socketAvailable() throws IOException { + int nativefd = checkAndReturnNativeFD(); + return available0(nativefd); + } + static native int available0(int fd) throws IOException; + + + void socketClose0(boolean useDeferredClose/*unused*/) throws IOException { + if (fd == null) + throw new SocketException("Socket closed"); + + if (!fd.valid()) + return; + + final int nativefd = fdAccess.get(fd); + fdAccess.set(fd, -1); + close0(nativefd); + } + static native void close0(int fd) throws IOException; + + + void socketShutdown(int howto) throws IOException { + int nativefd = checkAndReturnNativeFD(); + shutdown0(nativefd, howto); + } + static native void shutdown0(int fd, int howto) throws IOException; + + + static native void setIntOption(int fd, int cmd, int optionValue) throws SocketException; + + int socketGetOption(int opt, Object iaContainerObj) throws SocketException { int nativefd = checkAndReturnNativeFD(); @@ -248,11 +280,16 @@ } return value; } + static native int getIntOption(int fd, int cmd) throws SocketException; + static native void localAddress(int fd, InetAddressContainer in) throws SocketException; + void socketSendUrgentData(int data) throws IOException { int nativefd = checkAndReturnNativeFD(); sendOOB(nativefd, data); } + static native void sendOOB(int fd, int data) throws IOException; + private int checkAndReturnNativeFD() throws SocketException { if (fd == null || !fd.valid()) @@ -262,47 +299,4 @@ } static final int WOULDBLOCK = -2; // Nothing available (non-blocking) - - static { - initIDs(); - } - - /* Native methods */ - - static native void initIDs(); - - static native int socket0(boolean stream, boolean v6Only) throws IOException; - - static native void bind0(int fd, InetAddress localAddress, int localport, - boolean exclBind) - throws IOException; - - static native int connect0(int fd, InetAddress remote, int remotePort) - throws IOException; - - static native void waitForConnect(int fd, int timeout) throws IOException; - - static native int localPort0(int fd) throws IOException; - - static native void localAddress(int fd, InetAddressContainer in) throws SocketException; - - static native void listen0(int fd, int backlog) throws IOException; - - static native int accept0(int fd, InetSocketAddress[] isaa) throws IOException; - - static native void waitForNewConnection(int fd, int timeout) throws IOException; - - static native int available0(int fd) throws IOException; - - static native void close0(int fd) throws IOException; - - static native void shutdown0(int fd, int howto) throws IOException; - - static native void setIntOption(int fd, int cmd, int optionValue) throws SocketException; - - static native int getIntOption(int fd, int cmd) throws SocketException; - - static native void sendOOB(int fd, int data) throws IOException; - - static native void configureBlocking(int fd, boolean blocking) throws IOException; }