< prev index next >

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

Print this page
*** 113,12 ***
      private static final int ST_CLOSING = 3;
      private static final int ST_CLOSED = 4;
      private volatile int state;  // need stateLock to change
  
      // IDs of native threads doing reads and writes, for signalling
!     private long readerThread;
!     private long writerThread;
  
      // Binding
      private SocketAddress localAddress;
      private SocketAddress remoteAddress;
  
--- 113,12 ---
      private static final int ST_CLOSING = 3;
      private static final int ST_CLOSED = 4;
      private volatile int state;  // need stateLock to change
  
      // IDs of native threads doing reads and writes, for signalling
!     private NativeThread readerThread;
!     private NativeThread writerThread;
  
      // Binding
      private SocketAddress localAddress;
      private SocketAddress remoteAddress;
  

*** 383,11 ***
      private void endRead(boolean blocking, boolean completed)
          throws AsynchronousCloseException
      {
          if (blocking) {
              synchronized (stateLock) {
!                 readerThread = 0;
                  if (state == ST_CLOSING) {
                      tryFinishClose();
                  }
              }
              // remove hook for Thread.interrupt
--- 383,11 ---
      private void endRead(boolean blocking, boolean completed)
          throws AsynchronousCloseException
      {
          if (blocking) {
              synchronized (stateLock) {
!                 readerThread = null;
                  if (state == ST_CLOSING) {
                      tryFinishClose();
                  }
              }
              // remove hook for Thread.interrupt

*** 537,11 ***
      private void endWrite(boolean blocking, boolean completed)
          throws AsynchronousCloseException
      {
          if (blocking) {
              synchronized (stateLock) {
!                 writerThread = 0;
                  if (state == ST_CLOSING) {
                      tryFinishClose();
                  }
              }
              // remove hook for Thread.interrupt
--- 537,11 ---
      private void endWrite(boolean blocking, boolean completed)
          throws AsynchronousCloseException
      {
          if (blocking) {
              synchronized (stateLock) {
!                 writerThread = null;
                  if (state == ST_CLOSING) {
                      tryFinishClose();
                  }
              }
              // remove hook for Thread.interrupt

*** 688,11 ***
       * Marks the end of a transfer to this channel.
       * @throws AsynchronousCloseException if not completed and the channel is closed
       */
      void afterTransferTo(boolean completed) throws AsynchronousCloseException {
          synchronized (stateLock) {
!             writerThread = 0;
              if (state == ST_CLOSING) {
                  tryFinishClose();
              }
          }
          writeLock.unlock();
--- 688,11 ---
       * Marks the end of a transfer to this channel.
       * @throws AsynchronousCloseException if not completed and the channel is closed
       */
      void afterTransferTo(boolean completed) throws AsynchronousCloseException {
          synchronized (stateLock) {
!             writerThread = null;
              if (state == ST_CLOSING) {
                  tryFinishClose();
              }
          }
          writeLock.unlock();

*** 1073,11 ***
       * Closes the socket if there are no I/O operations in progress (or no I/O
       * operations tracked), and the channel is not registered with a Selector.
       */
      private boolean tryClose() throws IOException {
          assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
!         if ((readerThread == 0) && (writerThread == 0) && !isRegistered()) {
              state = ST_CLOSED;
              nd.close(fd);
              return true;
          } else {
              return false;
--- 1073,11 ---
       * Closes the socket if there are no I/O operations in progress (or no I/O
       * operations tracked), and the channel is not registered with a Selector.
       */
      private boolean tryClose() throws IOException {
          assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
!         if ((readerThread == null) && (writerThread == null) && !isRegistered()) {
              state = ST_CLOSED;
              nd.close(fd);
              return true;
          } else {
              return false;

*** 1216,15 ***
              ensureOpen();
              if (!isConnected())
                  throw new NotYetConnectedException();
              if (!isInputClosed) {
                  Net.shutdown(fd, Net.SHUT_RD);
!                 long reader = readerThread;
!                 if (NativeThread.isVirtualThread(reader)) {
-                     Poller.stopPoll(fdVal, Net.POLLIN);
-                 } else if (NativeThread.isNativeThread(reader)) {
-                     NativeThread.signal(reader);
                  }
                  isInputClosed = true;
              }
              return this;
          }
--- 1216,12 ---
              ensureOpen();
              if (!isConnected())
                  throw new NotYetConnectedException();
              if (!isInputClosed) {
                  Net.shutdown(fd, Net.SHUT_RD);
!                 if (NativeThread.isVirtualThread(readerThread)) {
!                     Poller.stopPoll(readerThread.thread());
                  }
                  isInputClosed = true;
              }
              return this;
          }

*** 1236,15 ***
              ensureOpen();
              if (!isConnected())
                  throw new NotYetConnectedException();
              if (!isOutputClosed) {
                  Net.shutdown(fd, Net.SHUT_WR);
!                 long writer = writerThread;
!                 if (NativeThread.isVirtualThread(writer)) {
-                     Poller.stopPoll(fdVal, Net.POLLOUT);
-                 } else if (NativeThread.isNativeThread(writer)) {
-                     NativeThread.signal(writer);
                  }
                  isOutputClosed = true;
              }
              return this;
          }
--- 1233,12 ---
              ensureOpen();
              if (!isConnected())
                  throw new NotYetConnectedException();
              if (!isOutputClosed) {
                  Net.shutdown(fd, Net.SHUT_WR);
!                 if (NativeThread.isVirtualThread(writerThread)) {
!                     Poller.stopPoll(writerThread.thread());
                  }
                  isOutputClosed = true;
              }
              return this;
          }
< prev index next >