723 724 private static Set<SocketOption<?>> options; 725 private static boolean optionsSet = false; 726 727 @Override 728 public Set<SocketOption<?>> supportedOptions() { 729 synchronized (MulticastSocket.class) { 730 if (optionsSet) { 731 return options; 732 } 733 try { 734 DatagramSocketImpl impl = getImpl(); 735 options = Collections.unmodifiableSet(impl.supportedOptions()); 736 } catch (SocketException ex) { 737 options = Collections.emptySet(); 738 } 739 optionsSet = true; 740 return options; 741 } 742 } 743 } | 723 724 private static Set<SocketOption<?>> options; 725 private static boolean optionsSet = false; 726 727 @Override 728 public Set<SocketOption<?>> supportedOptions() { 729 synchronized (MulticastSocket.class) { 730 if (optionsSet) { 731 return options; 732 } 733 try { 734 DatagramSocketImpl impl = getImpl(); 735 options = Collections.unmodifiableSet(impl.supportedOptions()); 736 } catch (SocketException ex) { 737 options = Collections.emptySet(); 738 } 739 optionsSet = true; 740 return options; 741 } 742 } 743 744 @Override 745 public synchronized boolean getReuseAddress() throws SocketException { 746 try { 747 return super.getReuseAddress() || getOption(StandardSocketOptions.SO_REUSEPORT); 748 } catch (IOException ex) { 749 SocketException se = new SocketException(ex.getMessage()); 750 se.addSuppressed(ex); 751 throw se; 752 } 753 } 754 755 @Override 756 public synchronized void setReuseAddress(boolean on) throws SocketException { 757 super.setReuseAddress(on); 758 if (supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) { 759 try { 760 setOption(StandardSocketOptions.SO_REUSEPORT, on); 761 } catch (IOException ex) { 762 SocketException se = new SocketException(ex.getMessage()); 763 se.addSuppressed(ex); 764 throw se; 765 } 766 } 767 } 768 } |