jdk/src/solaris/classes/sun/nio/ch/SctpMultiChannelImpl.java
changeset 4669 11d1dbd3598d
parent 3320 a7c037dd2e14
child 4677 1b6ce3fbc01b
equal deleted inserted replaced
4668:53e1c92056fc 4669:11d1dbd3598d
    36 import java.util.Set;
    36 import java.util.Set;
    37 import java.util.HashSet;
    37 import java.util.HashSet;
    38 import java.util.HashMap;
    38 import java.util.HashMap;
    39 import java.nio.ByteBuffer;
    39 import java.nio.ByteBuffer;
    40 import java.nio.channels.SelectionKey;
    40 import java.nio.channels.SelectionKey;
    41 import java.nio.channels.AlreadyBoundException;
       
    42 import java.nio.channels.ClosedChannelException;
    41 import java.nio.channels.ClosedChannelException;
    43 import java.nio.channels.NotYetBoundException;
    42 import java.nio.channels.NotYetBoundException;
    44 import java.nio.channels.spi.SelectorProvider;
    43 import java.nio.channels.spi.SelectorProvider;
    45 import com.sun.nio.sctp.AbstractNotificationHandler;
    44 import com.sun.nio.sctp.AbstractNotificationHandler;
    46 import com.sun.nio.sctp.Association;
    45 import com.sun.nio.sctp.Association;
    61  * An implementation of SctpMultiChannel
    60  * An implementation of SctpMultiChannel
    62  */
    61  */
    63 public class SctpMultiChannelImpl extends SctpMultiChannel
    62 public class SctpMultiChannelImpl extends SctpMultiChannel
    64     implements SelChImpl
    63     implements SelChImpl
    65 {
    64 {
    66     /* Used to make native close and preClose calls */
       
    67     private static NativeDispatcher nd;
       
    68 
       
    69     private final FileDescriptor fd;
    65     private final FileDescriptor fd;
    70 
    66 
    71     private final int fdVal;
    67     private final int fdVal;
    72 
    68 
    73     /* IDs of native threads doing send and receives, for signalling */
    69     /* IDs of native threads doing send and receives, for signalling */
   138         synchronized (receiveLock) {
   134         synchronized (receiveLock) {
   139             synchronized (sendLock) {
   135             synchronized (sendLock) {
   140                 synchronized (stateLock) {
   136                 synchronized (stateLock) {
   141                     ensureOpen();
   137                     ensureOpen();
   142                     if (isBound())
   138                     if (isBound())
   143                         throw new AlreadyBoundException();
   139                         SctpNet.throwAlreadyBoundException();
   144                     InetSocketAddress isa = (local == null) ?
   140                     InetSocketAddress isa = (local == null) ?
   145                         new InetSocketAddress(0) : Net.checkAddress(local);
   141                         new InetSocketAddress(0) : Net.checkAddress(local);
   146 
   142 
   147                     SecurityManager sm = System.getSecurityManager();
   143                     SecurityManager sm = System.getSecurityManager();
   148                     if (sm != null)
   144                     if (sm != null)
   153                     port = boundIsa.getPort();
   149                     port = boundIsa.getPort();
   154                     localAddresses.add(isa);
   150                     localAddresses.add(isa);
   155                     if (isa.getAddress().isAnyLocalAddress())
   151                     if (isa.getAddress().isAnyLocalAddress())
   156                         wildcard = true;
   152                         wildcard = true;
   157 
   153 
   158                     Net.listen(fd, backlog < 1 ? 50 : backlog);
   154                     SctpNet.listen(fdVal, backlog < 1 ? 50 : backlog);
   159                 }
   155                 }
   160             }
   156             }
   161         }
   157         }
   162         return this;
   158         return this;
   163     }
   159     }
   194                         throw new IllegalArgumentException(
   190                         throw new IllegalArgumentException(
   195                                 "Cannot add or remove the wildcard address");
   191                                 "Cannot add or remove the wildcard address");
   196                     if (add) {
   192                     if (add) {
   197                         for (InetSocketAddress addr : localAddresses) {
   193                         for (InetSocketAddress addr : localAddresses) {
   198                             if (addr.getAddress().equals(address)) {
   194                             if (addr.getAddress().equals(address)) {
   199                                 throw new AlreadyBoundException();
   195                                 SctpNet.throwAlreadyBoundException();
   200                             }
   196                             }
   201                         }
   197                         }
   202                     } else { /*removing */
   198                     } else { /*removing */
   203                         /* Verify that there is more than one address
   199                         /* Verify that there is more than one address
   204                          * and that address is already bound */
   200                          * and that address is already bound */
   282     }
   278     }
   283 
   279 
   284     @Override
   280     @Override
   285     public void implCloseSelectableChannel() throws IOException {
   281     public void implCloseSelectableChannel() throws IOException {
   286         synchronized (stateLock) {
   282         synchronized (stateLock) {
   287             nd.preClose(fd);
   283             SctpNet.preClose(fdVal);
   288 
   284 
   289             if (receiverThread != 0)
   285             if (receiverThread != 0)
   290                 NativeThread.signal(receiverThread);
   286                 NativeThread.signal(receiverThread);
   291 
   287 
   292             if (senderThread != 0)
   288             if (senderThread != 0)
   373             }
   369             }
   374             assert !isOpen() && !isRegistered();
   370             assert !isOpen() && !isRegistered();
   375 
   371 
   376             /* Postpone the kill if there is a thread sending or receiving. */
   372             /* Postpone the kill if there is a thread sending or receiving. */
   377             if (receiverThread == 0 && senderThread == 0) {
   373             if (receiverThread == 0 && senderThread == 0) {
   378                 nd.close(fd);
   374                 SctpNet.close(fdVal);
   379                 state = ChannelState.KILLED;
   375                 state = ChannelState.KILLED;
   380             } else {
   376             } else {
   381                 state = ChannelState.KILLPENDING;
   377                 state = ChannelState.KILLPENDING;
   382             }
   378             }
   383         }
   379         }
   979 
   975 
   980     static {
   976     static {
   981         Util.load();   /* loads nio & net native libraries */
   977         Util.load();   /* loads nio & net native libraries */
   982         java.security.AccessController.doPrivileged(
   978         java.security.AccessController.doPrivileged(
   983                 new sun.security.action.LoadLibraryAction("sctp"));
   979                 new sun.security.action.LoadLibraryAction("sctp"));
   984         nd = new SctpSocketDispatcher();
       
   985     }
   980     }
   986 }
   981 }