src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java
branchniosocketimpl-branch
changeset 57274 07b6be5d9150
parent 53445 c96f9aa1f3d8
child 57278 bf925a3ee68a
equal deleted inserted replaced
57270:3519688a4e4d 57274:07b6be5d9150
   463                     if (isConnected())
   463                     if (isConnected())
   464                         return true;
   464                         return true;
   465                     if (state != ChannelState.PENDING)
   465                     if (state != ChannelState.PENDING)
   466                         throw new NoConnectionPendingException();
   466                         throw new NoConnectionPendingException();
   467                 }
   467                 }
   468                 int n = 0;
   468                 boolean connected = false;
   469                 try {
   469                 try {
   470                     try {
   470                     try {
   471                         begin();
   471                         begin();
   472                         synchronized (blockingLock()) {
   472                         synchronized (blockingLock()) {
   473                             synchronized (stateLock) {
   473                             synchronized (stateLock) {
   475                                     return false;
   475                                     return false;
   476                                 }
   476                                 }
   477                                 receiverThread = NativeThread.current();
   477                                 receiverThread = NativeThread.current();
   478                             }
   478                             }
   479                             if (!isBlocking()) {
   479                             if (!isBlocking()) {
   480                                 for (;;) {
   480                                 connected = Net.pollConnect(fd, 0);
   481                                     n = Net.pollConnect(fd, 0);
       
   482                                     if (  (n == IOStatus.INTERRUPTED)
       
   483                                           && isOpen())
       
   484                                         continue;
       
   485                                     break;
       
   486                                 }
       
   487                             } else {
   481                             } else {
   488                                 for (;;) {
   482                                 do {
   489                                     n = Net.pollConnect(fd, -1);
   483                                     connected = Net.pollConnect(fd, -1);
   490                                     if (n == 0) {
   484                                 } while (!connected && isOpen());
   491                                         // Loop in case of
       
   492                                         // spurious notifications
       
   493                                         continue;
       
   494                                     }
       
   495                                     if (  (n == IOStatus.INTERRUPTED)
       
   496                                           && isOpen())
       
   497                                         continue;
       
   498                                     break;
       
   499                                 }
       
   500                             }
   485                             }
   501                         }
   486                         }
   502                     } finally {
   487                     } finally {
   503                         synchronized (stateLock) {
   488                         synchronized (stateLock) {
   504                             receiverThread = 0;
   489                             receiverThread = 0;
   505                             if (state == ChannelState.KILLPENDING) {
   490                             if (state == ChannelState.KILLPENDING) {
   506                                 kill();
   491                                 kill();
   507                                 /* poll()/getsockopt() does not report
   492                                 connected = false;
   508                                  * error (throws exception, with n = 0)
       
   509                                  * on Linux platform after dup2 and
       
   510                                  * signal-wakeup. Force n to 0 so the
       
   511                                  * end() can throw appropriate exception */
       
   512                                 n = 0;
       
   513                             }
   493                             }
   514                         }
   494                         }
   515                         end((n > 0) || (n == IOStatus.UNAVAILABLE));
   495                         end(connected);
   516                         assert IOStatus.check(n);
       
   517                     }
   496                     }
   518                 } catch (IOException x) {
   497                 } catch (IOException x) {
   519                     /* If an exception was thrown, close the channel after
   498                     /* If an exception was thrown, close the channel after
   520                      * invoking end() so as to avoid bogus
   499                      * invoking end() so as to avoid bogus
   521                      * AsynchronousCloseExceptions */
   500                      * AsynchronousCloseExceptions */
   522                     close();
   501                     close();
   523                     throw x;
   502                     throw x;
   524                 }
   503                 }
   525 
   504 
   526                 if (n > 0) {
   505                 if (connected) {
   527                     synchronized (stateLock) {
   506                     synchronized (stateLock) {
   528                         state = ChannelState.CONNECTED;
   507                         state = ChannelState.CONNECTED;
   529                         if (!isBound()) {
   508                         if (!isBound()) {
   530                             InetSocketAddress boundIsa =
   509                             InetSocketAddress boundIsa =
   531                                     Net.localAddress(fd);
   510                                     Net.localAddress(fd);