< prev index next >

src/java.base/unix/classes/java/net/PlainDatagramSocketImpl.java

Print this page




  24  */
  25 package java.net;
  26 
  27 import java.io.IOException;
  28 import java.util.Set;
  29 import java.util.HashSet;
  30 import sun.net.ext.ExtendedSocketOptions;
  31 
  32 /*
  33  * On Unix systems we simply delegate to native methods.
  34  *
  35  * @author Chris Hegarty
  36  */
  37 
  38 class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
  39 {
  40     static {
  41         init();
  42     }
  43 
  44     static final ExtendedSocketOptions extendedOptions =
  45             ExtendedSocketOptions.getInstance();
  46 
  47     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
  48         if (isClosed()) {
  49             throw new SocketException("Socket closed");
  50         }
  51         if (supportedOptions().contains(name)) {
  52             if (extendedOptions.isOptionSupported(name)) {
  53                 extendedOptions.setOption(fd, name, value);
  54             } else {
  55                 super.setOption(name, value);
  56             }
  57         } else {
  58             throw new UnsupportedOperationException("unsupported option");
  59         }
  60     }
  61 
  62     @SuppressWarnings("unchecked")
  63     protected <T> T getOption(SocketOption<T> name) throws IOException {
  64         if (isClosed()) {
  65             throw new SocketException("Socket closed");
  66         }
  67         if (supportedOptions().contains(name)) {
  68             if (extendedOptions.isOptionSupported(name)) {
  69                 return (T) extendedOptions.getOption(fd, name);
  70             } else {
  71                 return super.getOption(name);
  72             }
  73         } else {
  74             throw new UnsupportedOperationException("unsupported option");
  75         }
  76     }
  77 
  78     protected Set<SocketOption<?>> supportedOptions() {
  79         HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions());
  80         options.addAll(ExtendedSocketOptions.datagramSocketOptions());
  81         return options;
  82     }
  83 
  84     protected void socketSetOption(int opt, Object val) throws SocketException {
  85         if (opt == SocketOptions.SO_REUSEPORT &&
  86             !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {
  87             throw new UnsupportedOperationException("unsupported option");
  88         }
  89         try {
  90             socketSetOption0(opt, val);
  91         } catch (SocketException se) {
  92             if (!connected)
  93                 throw se;
  94         }
  95     }
  96 
  97     protected synchronized native void bind0(int lport, InetAddress laddr)
  98         throws SocketException;
  99 
 100     protected native void send(DatagramPacket p) throws IOException;
 101 
 102     protected synchronized native int peek(InetAddress i) throws IOException;
 103 




  24  */
  25 package java.net;
  26 
  27 import java.io.IOException;
  28 import java.util.Set;
  29 import java.util.HashSet;
  30 import sun.net.ext.ExtendedSocketOptions;
  31 
  32 /*
  33  * On Unix systems we simply delegate to native methods.
  34  *
  35  * @author Chris Hegarty
  36  */
  37 
  38 class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
  39 {
  40     static {
  41         init();
  42     }
  43 








































  44     protected void socketSetOption(int opt, Object val) throws SocketException {
  45         if (opt == SocketOptions.SO_REUSEPORT &&
  46             !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {
  47             throw new UnsupportedOperationException("unsupported option");
  48         }
  49         try {
  50             socketSetOption0(opt, val);
  51         } catch (SocketException se) {
  52             if (!connected)
  53                 throw se;
  54         }
  55     }
  56 
  57     protected synchronized native void bind0(int lport, InetAddress laddr)
  58         throws SocketException;
  59 
  60     protected native void send(DatagramPacket p) throws IOException;
  61 
  62     protected synchronized native int peek(InetAddress i) throws IOException;
  63 


< prev index next >