src/share/classes/sun/nio/ch/DatagramChannelImpl.java

Print this page




 694                     ensureOpenAndUnconnected();
 695                     InetSocketAddress isa = Net.checkAddress(sa);
 696                     SecurityManager sm = System.getSecurityManager();
 697                     if (sm != null)
 698                         sm.checkConnect(isa.getAddress().getHostAddress(),
 699                                         isa.getPort());
 700                     int n = Net.connect(family,
 701                                         fd,
 702                                         isa.getAddress(),
 703                                         isa.getPort());
 704                     if (n <= 0)
 705                         throw new Error();      // Can't happen
 706 
 707                     // Connection succeeded; disallow further invocation
 708                     state = ST_CONNECTED;
 709                     remoteAddress = sa;
 710                     sender = isa;
 711                     cachedSenderInetAddress = isa.getAddress();
 712                     cachedSenderPort = isa.getPort();
 713 
 714                     // Socket was not bound before connecting,
 715                     if (localAddress == null) {
 716                         localAddress = Net.localAddress(fd);
 717                     }
 718                 }
 719             }
 720         }
 721         return this;
 722     }
 723 
 724     public DatagramChannel disconnect() throws IOException {
 725         synchronized(readLock) {
 726             synchronized(writeLock) {
 727                 synchronized (stateLock) {
 728                     if (!isConnected() || !isOpen())
 729                         return this;
 730                     InetSocketAddress isa = (InetSocketAddress)remoteAddress;
 731                     SecurityManager sm = System.getSecurityManager();
 732                     if (sm != null)
 733                         sm.checkConnect(isa.getAddress().getHostAddress(),
 734                                         isa.getPort());
 735                     disconnect0(fd);
 736                     remoteAddress = null;
 737                     state = ST_UNCONNECTED;



 738                 }
 739             }
 740         }
 741         return this;
 742     }
 743 
 744     /**
 745      * Joins channel's socket to the given group/interface and
 746      * optional source address.
 747      */
 748     private MembershipKey innerJoin(InetAddress group,
 749                                     NetworkInterface interf,
 750                                     InetAddress source)
 751         throws IOException
 752     {
 753         if (!group.isMulticastAddress())
 754             throw new IllegalArgumentException("Group not a multicast address");
 755 
 756         // check multicast address is compatible with this socket
 757         if (!(group instanceof Inet4Address)) {




 694                     ensureOpenAndUnconnected();
 695                     InetSocketAddress isa = Net.checkAddress(sa);
 696                     SecurityManager sm = System.getSecurityManager();
 697                     if (sm != null)
 698                         sm.checkConnect(isa.getAddress().getHostAddress(),
 699                                         isa.getPort());
 700                     int n = Net.connect(family,
 701                                         fd,
 702                                         isa.getAddress(),
 703                                         isa.getPort());
 704                     if (n <= 0)
 705                         throw new Error();      // Can't happen
 706 
 707                     // Connection succeeded; disallow further invocation
 708                     state = ST_CONNECTED;
 709                     remoteAddress = sa;
 710                     sender = isa;
 711                     cachedSenderInetAddress = isa.getAddress();
 712                     cachedSenderPort = isa.getPort();
 713 
 714                     // set or refresh local address

 715                     localAddress = Net.localAddress(fd);
 716                 }
 717             }
 718         }

 719         return this;
 720     }
 721 
 722     public DatagramChannel disconnect() throws IOException {
 723         synchronized(readLock) {
 724             synchronized(writeLock) {
 725                 synchronized (stateLock) {
 726                     if (!isConnected() || !isOpen())
 727                         return this;
 728                     InetSocketAddress isa = (InetSocketAddress)remoteAddress;
 729                     SecurityManager sm = System.getSecurityManager();
 730                     if (sm != null)
 731                         sm.checkConnect(isa.getAddress().getHostAddress(),
 732                                         isa.getPort());
 733                     disconnect0(fd);
 734                     remoteAddress = null;
 735                     state = ST_UNCONNECTED;
 736 
 737                     // refresh local address
 738                     localAddress = Net.localAddress(fd);
 739                 }
 740             }
 741         }
 742         return this;
 743     }
 744 
 745     /**
 746      * Joins channel's socket to the given group/interface and
 747      * optional source address.
 748      */
 749     private MembershipKey innerJoin(InetAddress group,
 750                                     NetworkInterface interf,
 751                                     InetAddress source)
 752         throws IOException
 753     {
 754         if (!group.isMulticastAddress())
 755             throw new IllegalArgumentException("Group not a multicast address");
 756 
 757         // check multicast address is compatible with this socket
 758         if (!(group instanceof Inet4Address)) {