--- old/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java 2019-04-18 10:58:12.000000000 +0100 +++ new/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java 2019-04-18 10:58:12.000000000 +0100 @@ -71,6 +71,12 @@ /* indicates a close is pending on the file descriptor */ protected boolean closePending = false; + /* true, if and only if, the socket is bound */ + volatile boolean bound; + + /* true, if and only if, the socket is connected */ + volatile boolean connected; + /* indicates connection reset state */ private volatile boolean connectionReset; @@ -105,6 +111,10 @@ return isReusePortAvailable; } + AbstractPlainSocketImpl(boolean server) { + super(server); + } + /** * Returns a set of SocketOptions supported by this impl and by this impl's * socket (Socket or ServerSocket) @@ -136,7 +146,7 @@ // only create the fd after we know we will be able to create the socket fd = new FileDescriptor(); try { - socketCreate(false); + socketCreate(false, server); SocketCleanable.register(fd); } catch (IOException ioe) { ResourceManager.afterUdpClose(); @@ -145,13 +155,9 @@ } } else { fd = new FileDescriptor(); - socketCreate(true); + socketCreate(true, server); SocketCleanable.register(fd); } - if (socket != null) - socket.setCreated(); - if (serverSocket != null) - serverSocket.setCreated(); } /** @@ -245,6 +251,8 @@ } else { doConnect(address, port, timeout); } + connected = true; + bound = true; // implicitly bound } public void setOption(int opt, Object val) throws SocketException { @@ -361,6 +369,7 @@ case IP_TOS: try { ret = socketGetOption(opt, null); + System.out.println("CHEGAR : ret: " + ret ); if (ret == -1) { // ipv6 tos return trafficClass; } else { @@ -368,6 +377,7 @@ } } catch (SocketException se) { // TODO - should make better effort to read TOS or TCLASS + System.out.println("CHEGAR : swallowing: " + se ); return trafficClass; // ipv6 tos } case SO_KEEPALIVE: @@ -393,7 +403,7 @@ synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException { synchronized (fdLock) { - if (!closePending && (socket == null || !socket.isBound())) { + if (!closePending && (server || !bound)) { NetHooks.beforeTcpConnect(fd, address, port); } } @@ -407,14 +417,6 @@ throw new SocketException ("Socket closed"); } } - // If we have a ref. to the Socket, then sets the flags - // created, bound & connected to true. - // This is normally done in Socket.connect() but some - // subclasses of Socket may call impl.connect() directly! - if (socket != null) { - socket.setBound(); - socket.setConnected(); - } } finally { releaseFD(); } @@ -433,15 +435,12 @@ throws IOException { synchronized (fdLock) { - if (!closePending && (socket == null || !socket.isBound())) { - NetHooks.beforeTcpBind(fd, address, lport); - } - } - socketBind(address, lport); - if (socket != null) - socket.setBound(); - if (serverSocket != null) - serverSocket.setBound(); + if (!closePending && (server || !bound)) { + NetHooks.beforeTcpBind(fd, address, lport); + } + } + socketBind(address, lport); + bound = true; } /** @@ -461,6 +460,9 @@ acquireFD(); try { socketAccept(si); + bound = true; + connected = true; + //TODO REMOVE: try removing these lines to see it something will fail (setting of bound & connected ) } finally { releaseFD(); } @@ -727,7 +729,7 @@ socketClose0(false); } - abstract void socketCreate(boolean isServer) throws IOException; + abstract void socketCreate(boolean stream, boolean isServer) throws IOException; abstract void socketConnect(InetAddress address, int port, int timeout) throws IOException; abstract void socketBind(InetAddress address, int port)