< prev index next >

src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java

Print this page

        

*** 69,78 **** --- 69,84 ---- protected final Object fdLock = new Object(); /* 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; /* whether this Socket is a stream (TCP) socket or not (UDP) */
*** 103,112 **** --- 109,122 ---- checkedReusePort = true; } 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) * * @return a Set of SocketOptions
*** 134,159 **** if (!stream) { ResourceManager.beforeUdpCreate(); // only create the fd after we know we will be able to create the socket fd = new FileDescriptor(); try { ! socketCreate(false); SocketCleanable.register(fd); } catch (IOException ioe) { ResourceManager.afterUdpClose(); fd = null; throw ioe; } } else { fd = new FileDescriptor(); ! socketCreate(true); SocketCleanable.register(fd); } - if (socket != null) - socket.setCreated(); - if (serverSocket != null) - serverSocket.setCreated(); } /** * Creates a socket and connects it to the specified port on * the specified host. --- 144,165 ---- if (!stream) { ResourceManager.beforeUdpCreate(); // only create the fd after we know we will be able to create the socket fd = new FileDescriptor(); try { ! socketCreate(false, server); SocketCleanable.register(fd); } catch (IOException ioe) { ResourceManager.afterUdpClose(); fd = null; throw ioe; } } else { fd = new FileDescriptor(); ! socketCreate(true, server); SocketCleanable.register(fd); } } /** * Creates a socket and connects it to the specified port on * the specified host.
*** 243,252 **** --- 249,260 ---- if (address.isAnyLocalAddress()) { doConnect(InetAddress.getLocalHost(), port, timeout); } else { doConnect(address, port, timeout); } + connected = true; + bound = true; // implicitly bound } public void setOption(int opt, Object val) throws SocketException { if (isClosedOrPending()) { throw new SocketException("Socket Closed");
*** 359,375 **** --- 367,385 ---- ret = socketGetOption(opt, null); return ret; case IP_TOS: try { ret = socketGetOption(opt, null); + System.out.println("CHEGAR : ret: " + ret ); if (ret == -1) { // ipv6 tos return trafficClass; } else { return ret; } } 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: ret = socketGetOption(opt, null); return Boolean.valueOf(ret != -1);
*** 391,401 **** * throws an IOException indicating what went wrong. */ synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException { synchronized (fdLock) { ! if (!closePending && (socket == null || !socket.isBound())) { NetHooks.beforeTcpConnect(fd, address, port); } } try { acquireFD(); --- 401,411 ---- * throws an IOException indicating what went wrong. */ synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException { synchronized (fdLock) { ! if (!closePending && (server || !bound)) { NetHooks.beforeTcpConnect(fd, address, port); } } try { acquireFD();
*** 405,422 **** synchronized (fdLock) { if (closePending) { 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(); } } catch (IOException e) { close(); --- 415,424 ----
*** 431,449 **** */ protected synchronized void bind(InetAddress address, int lport) 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(); } /** * Listens, for a specified amount of time, for connections. * @param count the amount of time to listen for connections --- 433,448 ---- */ protected synchronized void bind(InetAddress address, int lport) throws IOException { synchronized (fdLock) { ! if (!closePending && (server || !bound)) { NetHooks.beforeTcpBind(fd, address, lport); } } socketBind(address, lport); ! bound = true; } /** * Listens, for a specified amount of time, for connections. * @param count the amount of time to listen for connections
*** 459,468 **** --- 458,470 ---- protected void accept(SocketImpl si) throws IOException { si.fd = new FileDescriptor(); 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(); } SocketCleanable.register(si.fd); }
*** 725,735 **** protected void socketClose() throws IOException { SocketCleanable.unregister(fd); socketClose0(false); } ! abstract void socketCreate(boolean isServer) throws IOException; abstract void socketConnect(InetAddress address, int port, int timeout) throws IOException; abstract void socketBind(InetAddress address, int port) throws IOException; abstract void socketListen(int count) --- 727,737 ---- protected void socketClose() throws IOException { SocketCleanable.unregister(fd); socketClose0(false); } ! 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) throws IOException; abstract void socketListen(int count)
< prev index next >