< prev index next >

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

Print this page




  41 
  42 class PlainSocketImpl extends AbstractPlainSocketImpl
  43 {
  44     static {
  45         initProto();
  46     }
  47 
  48     /**
  49      * Constructs an empty instance.
  50      */
  51     PlainSocketImpl() { }
  52 
  53     /**
  54      * Constructs an instance with the given file descriptor.
  55      */
  56     PlainSocketImpl(FileDescriptor fd) {
  57         this.fd = fd;
  58     }
  59 
  60     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
  61         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {

  62             super.setOption(name, value);
  63         } else {
  64             if (isClosedOrPending()) {
  65                 throw new SocketException("Socket closed");
  66             }

  67             checkSetOptionPermission(name);
  68             checkValueType(value, SocketFlow.class);
  69             setFlowOption(getFileDescriptor(), (SocketFlow)value);



  70         }
  71     }
  72 
  73     @SuppressWarnings("unchecked")
  74     protected <T> T getOption(SocketOption<T> name) throws IOException {
  75         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {

  76             return super.getOption(name);
  77         }
  78         if (isClosedOrPending()) {
  79             throw new SocketException("Socket closed");
  80         }

  81         checkGetOptionPermission(name);
  82         SocketFlow flow = SocketFlow.create();
  83         getFlowOption(getFileDescriptor(), flow);
  84         return (T)flow;
  85     }


  86 
  87     protected Set<SocketOption<?>> supportedOptions() {
  88         HashSet<SocketOption<?>> options = new HashSet<>(
  89             super.supportedOptions());
  90 
  91         if (getSocket() != null && flowSupported()) {
  92             options.add(ExtendedSocketOptions.SO_FLOW_SLA);



  93         }
  94         return options;
  95     }
  96 
  97     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
  98         try {
  99             socketSetOption0(opt, b, val);
 100         } catch (SocketException se) {
 101             if (socket == null || !socket.isConnected())
 102                 throw se;
 103         }
 104     }
 105 
 106     native void socketCreate(boolean isServer) throws IOException;
 107 
 108     native void socketConnect(InetAddress address, int port, int timeout)
 109         throws IOException;
 110 
 111     native void socketBind(InetAddress address, int port)
 112         throws IOException;


  41 
  42 class PlainSocketImpl extends AbstractPlainSocketImpl
  43 {
  44     static {
  45         initProto();
  46     }
  47 
  48     /**
  49      * Constructs an empty instance.
  50      */
  51     PlainSocketImpl() { }
  52 
  53     /**
  54      * Constructs an instance with the given file descriptor.
  55      */
  56     PlainSocketImpl(FileDescriptor fd) {
  57         this.fd = fd;
  58     }
  59 
  60     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
  61         if (!(name.equals(ExtendedSocketOptions.SO_FLOW_SLA)
  62               || (name.equals(ExtendedSocketOptions.SO_REUSEPORT)))) {
  63             super.setOption(name, value);
  64         } else {
  65             if (isClosedOrPending()) {
  66                 throw new SocketException("Socket closed");
  67             }
  68             if (name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
  69                 checkSetOptionPermission(name);
  70                 checkValueType(value, SocketFlow.class);
  71                 setFlowOption(getFileDescriptor(), (SocketFlow)value);
  72             } else {
  73                 setReusePortOption(getFileDescriptor(), ((Boolean)value).booleanValue());
  74             }
  75         }
  76     }
  77 
  78     @SuppressWarnings("unchecked")
  79     protected <T> T getOption(SocketOption<T> name) throws IOException {
  80         if (!(name.equals(ExtendedSocketOptions.SO_FLOW_SLA)
  81               || (name.equals(ExtendedSocketOptions.SO_REUSEPORT)))) {
  82             return super.getOption(name);
  83         }
  84         if (isClosedOrPending()) {
  85             throw new SocketException("Socket closed");
  86         }
  87         if (name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
  88             checkGetOptionPermission(name);
  89             SocketFlow flow = SocketFlow.create();
  90             getFlowOption(getFileDescriptor(), flow);
  91             return (T)flow;
  92         }
  93         return (T)getReusePortOption(getFileDescriptor());
  94     }
  95 
  96     protected Set<SocketOption<?>> supportedOptions() {
  97         HashSet<SocketOption<?>> options = new HashSet<>(
  98             super.supportedOptions());
  99 
 100         if (getSocket() != null && flowSupported()) {
 101             options.add(ExtendedSocketOptions.SO_FLOW_SLA);
 102         }
 103         if (getSocket() != null && reuseportSupported()) {
 104             options.add(ExtendedSocketOptions.SO_REUSEPORT);
 105         }
 106         return options;
 107     }
 108 
 109     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
 110         try {
 111             socketSetOption0(opt, b, val);
 112         } catch (SocketException se) {
 113             if (socket == null || !socket.isConnected())
 114                 throw se;
 115         }
 116     }
 117 
 118     native void socketCreate(boolean isServer) throws IOException;
 119 
 120     native void socketConnect(InetAddress address, int port, int timeout)
 121         throws IOException;
 122 
 123     native void socketBind(InetAddress address, int port)
 124         throws IOException;
< prev index next >