< prev index next >

src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java

Print this page
*** 106,12 ***
  
      // set to true when the socket is in non-blocking mode
      private volatile boolean nonBlocking;
  
      // used by connect/read/write/accept, protected by stateLock
!     private long readerThread;
!     private long writerThread;
  
      // used when SO_REUSEADDR is emulated, protected by stateLock
      private boolean isReuseAddress;
  
      // read or accept timeout in millis
--- 106,12 ---
  
      // set to true when the socket is in non-blocking mode
      private volatile boolean nonBlocking;
  
      // used by connect/read/write/accept, protected by stateLock
!     private NativeThread readerThread;
!     private NativeThread writerThread;
  
      // used when SO_REUSEADDR is emulated, protected by stateLock
      private boolean isReuseAddress;
  
      // read or accept timeout in millis

*** 232,11 ***
       * Marks the end of a read operation that may have blocked.
       * @throws SocketException is the socket is closed
       */
      private void endRead(boolean completed) throws SocketException {
          synchronized (stateLock) {
!             readerThread = 0;
              int state = this.state;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (!completed && state >= ST_CLOSING)
                  throw new SocketException("Socket closed");
--- 232,11 ---
       * Marks the end of a read operation that may have blocked.
       * @throws SocketException is the socket is closed
       */
      private void endRead(boolean completed) throws SocketException {
          synchronized (stateLock) {
!             readerThread = null;
              int state = this.state;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (!completed && state >= ST_CLOSING)
                  throw new SocketException("Socket closed");

*** 377,11 ***
       * Marks the end of a write operation that may have blocked.
       * @throws SocketException is the socket is closed
       */
      private void endWrite(boolean completed) throws SocketException {
          synchronized (stateLock) {
!             writerThread = 0;
              int state = this.state;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (!completed && state >= ST_CLOSING)
                  throw new SocketException("Socket closed");
--- 377,11 ---
       * Marks the end of a write operation that may have blocked.
       * @throws SocketException is the socket is closed
       */
      private void endWrite(boolean completed) throws SocketException {
          synchronized (stateLock) {
!             writerThread = null;
              int state = this.state;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (!completed && state >= ST_CLOSING)
                  throw new SocketException("Socket closed");

*** 519,11 ***
       * Marks the end of a connect operation that may have blocked.
       * @throws SocketException is the socket is closed
       */
      private void endConnect(FileDescriptor fd, boolean completed) throws IOException {
          synchronized (stateLock) {
!             readerThread = 0;
              int state = this.state;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (completed && state == ST_CONNECTING) {
                  this.state = ST_CONNECTED;
--- 519,11 ---
       * Marks the end of a connect operation that may have blocked.
       * @throws SocketException is the socket is closed
       */
      private void endConnect(FileDescriptor fd, boolean completed) throws IOException {
          synchronized (stateLock) {
!             readerThread = null;
              int state = this.state;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (completed && state == ST_CONNECTING) {
                  this.state = ST_CONNECTED;

*** 676,11 ***
       * @throws SocketException is the socket is closed
       */
      private void endAccept(boolean completed) throws SocketException {
          synchronized (stateLock) {
              int state = this.state;
!             readerThread = 0;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (!completed && state >= ST_CLOSING)
                  throw new SocketException("Socket closed");
          }
--- 676,11 ---
       * @throws SocketException is the socket is closed
       */
      private void endAccept(boolean completed) throws SocketException {
          synchronized (stateLock) {
              int state = this.state;
!             readerThread = null;
              if (state == ST_CLOSING)
                  tryFinishClose();
              if (!completed && state >= ST_CLOSING)
                  throw new SocketException("Socket closed");
          }

*** 842,11 ***
      /**
       * Closes the socket if there are no I/O operations in progress.
       */
      private boolean tryClose() throws IOException {
          assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
!         if (readerThread == 0 && writerThread == 0) {
              try {
                  cleaner.clean();
              } catch (UncheckedIOException ioe) {
                  throw ioe.getCause();
              } finally {
--- 842,11 ---
      /**
       * Closes the socket if there are no I/O operations in progress.
       */
      private boolean tryClose() throws IOException {
          assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
!         if (readerThread == null && writerThread == null) {
              try {
                  cleaner.clean();
              } catch (UncheckedIOException ioe) {
                  throw ioe.getCause();
              } finally {

*** 1142,11 ***
          synchronized (stateLock) {
              ensureOpenAndConnected();
              if (!isInputClosed) {
                  Net.shutdown(fd, Net.SHUT_RD);
                  if (NativeThread.isVirtualThread(readerThread)) {
!                     Poller.stopPoll(fdVal(fd), Net.POLLIN);
                  }
                  isInputClosed = true;
              }
          }
      }
--- 1142,11 ---
          synchronized (stateLock) {
              ensureOpenAndConnected();
              if (!isInputClosed) {
                  Net.shutdown(fd, Net.SHUT_RD);
                  if (NativeThread.isVirtualThread(readerThread)) {
!                     Poller.stopPoll(readerThread.thread());
                  }
                  isInputClosed = true;
              }
          }
      }

*** 1156,11 ***
          synchronized (stateLock) {
              ensureOpenAndConnected();
              if (!isOutputClosed) {
                  Net.shutdown(fd, Net.SHUT_WR);
                  if (NativeThread.isVirtualThread(writerThread)) {
!                     Poller.stopPoll(fdVal(fd), Net.POLLOUT);
                  }
                  isOutputClosed = true;
              }
          }
      }
--- 1156,11 ---
          synchronized (stateLock) {
              ensureOpenAndConnected();
              if (!isOutputClosed) {
                  Net.shutdown(fd, Net.SHUT_WR);
                  if (NativeThread.isVirtualThread(writerThread)) {
!                     Poller.stopPoll(writerThread.thread());
                  }
                  isOutputClosed = true;
              }
          }
      }
< prev index next >