< prev index next >

src/jdk.net/share/classes/jdk/net/ExtendedSocketOptions.java

Print this page




 189     static {
 190         // Registers the extended socket options with the base module.
 191         sun.net.ext.ExtendedSocketOptions.register(
 192                 new sun.net.ext.ExtendedSocketOptions(extendedOptions) {
 193 
 194             @Override
 195             public void setOption(FileDescriptor fd,
 196                                   SocketOption<?> option,
 197                                   Object value)
 198                 throws SocketException
 199             {
 200                 SecurityManager sm = System.getSecurityManager();
 201                 if (sm != null)
 202                     sm.checkPermission(new NetworkPermission("setOption." + option.name()));
 203 
 204                 if (fd == null || !fd.valid())
 205                     throw new SocketException("socket closed");
 206 
 207                 if (option == SO_FLOW_SLA) {
 208                     assert flowSupported;
 209                     SocketFlow flow = checkValueType(value, option.type());
 210                     setFlowOption(fd, flow);
 211                 } else if (option == TCP_QUICKACK) {
 212                     setQuickAckOption(fd, (boolean) value);
 213                 } else if (option == TCP_KEEPCOUNT) {
 214                     setTcpkeepAliveProbes(fd, (Integer) value);
 215                 } else if (option == TCP_KEEPIDLE) {
 216                     setTcpKeepAliveTime(fd, (Integer) value);
 217                 } else if (option == TCP_KEEPINTERVAL) {
 218                     setTcpKeepAliveIntvl(fd, (Integer) value);
 219                 } else {
 220                     throw new InternalError("Unexpected option " + option);
 221                 }
 222             }
 223 
 224             @Override
 225             public Object getOption(FileDescriptor fd,
 226                                     SocketOption<?> option)
 227                 throws SocketException
 228             {
 229                 SecurityManager sm = System.getSecurityManager();


 237                     assert flowSupported;
 238                     SocketFlow flow = SocketFlow.create();
 239                     getFlowOption(fd, flow);
 240                     return flow;
 241                 } else if (option == TCP_QUICKACK) {
 242                     return getQuickAckOption(fd);
 243                 } else if (option == TCP_KEEPCOUNT) {
 244                     return getTcpkeepAliveProbes(fd);
 245                 } else if (option == TCP_KEEPIDLE) {
 246                     return getTcpKeepAliveTime(fd);
 247                 } else if (option == TCP_KEEPINTERVAL) {
 248                     return getTcpKeepAliveIntvl(fd);
 249                 } else {
 250                     throw new InternalError("Unexpected option " + option);
 251                 }
 252             }
 253         });
 254     }
 255 
 256     @SuppressWarnings("unchecked")
 257     private static <T> T checkValueType(Object value, Class<?> type) {
 258         if (!type.isAssignableFrom(value.getClass())) {
 259             String s = "Found: " + value.getClass() + ", Expected: " + type;
 260             throw new IllegalArgumentException(s);
 261         }
 262         return (T) value;
 263     }
 264 
 265     private static final JavaIOFileDescriptorAccess fdAccess =
 266             SharedSecrets.getJavaIOFileDescriptorAccess();
 267 
 268     private static void setFlowOption(FileDescriptor fd, SocketFlow f)
 269         throws SocketException
 270     {
 271         int status = platformSocketOptions.setFlowOption(fdAccess.get(fd),
 272                                                          f.priority(),
 273                                                          f.bandwidth());
 274         f.status(status);  // augment the given flow with the status
 275     }
 276 
 277     private static void getFlowOption(FileDescriptor fd, SocketFlow f)
 278             throws SocketException {
 279         int status = platformSocketOptions.getFlowOption(fdAccess.get(fd), f);
 280         f.status(status);  // augment the given flow with the status
 281     }
 282 




 189     static {
 190         // Registers the extended socket options with the base module.
 191         sun.net.ext.ExtendedSocketOptions.register(
 192                 new sun.net.ext.ExtendedSocketOptions(extendedOptions) {
 193 
 194             @Override
 195             public void setOption(FileDescriptor fd,
 196                                   SocketOption<?> option,
 197                                   Object value)
 198                 throws SocketException
 199             {
 200                 SecurityManager sm = System.getSecurityManager();
 201                 if (sm != null)
 202                     sm.checkPermission(new NetworkPermission("setOption." + option.name()));
 203 
 204                 if (fd == null || !fd.valid())
 205                     throw new SocketException("socket closed");
 206 
 207                 if (option == SO_FLOW_SLA) {
 208                     assert flowSupported;
 209                     SocketFlow flow = checkValueType(value, SocketFlow.class);
 210                     setFlowOption(fd, flow);
 211                 } else if (option == TCP_QUICKACK) {
 212                     setQuickAckOption(fd, (boolean) value);
 213                 } else if (option == TCP_KEEPCOUNT) {
 214                     setTcpkeepAliveProbes(fd, (Integer) value);
 215                 } else if (option == TCP_KEEPIDLE) {
 216                     setTcpKeepAliveTime(fd, (Integer) value);
 217                 } else if (option == TCP_KEEPINTERVAL) {
 218                     setTcpKeepAliveIntvl(fd, (Integer) value);
 219                 } else {
 220                     throw new InternalError("Unexpected option " + option);
 221                 }
 222             }
 223 
 224             @Override
 225             public Object getOption(FileDescriptor fd,
 226                                     SocketOption<?> option)
 227                 throws SocketException
 228             {
 229                 SecurityManager sm = System.getSecurityManager();


 237                     assert flowSupported;
 238                     SocketFlow flow = SocketFlow.create();
 239                     getFlowOption(fd, flow);
 240                     return flow;
 241                 } else if (option == TCP_QUICKACK) {
 242                     return getQuickAckOption(fd);
 243                 } else if (option == TCP_KEEPCOUNT) {
 244                     return getTcpkeepAliveProbes(fd);
 245                 } else if (option == TCP_KEEPIDLE) {
 246                     return getTcpKeepAliveTime(fd);
 247                 } else if (option == TCP_KEEPINTERVAL) {
 248                     return getTcpKeepAliveIntvl(fd);
 249                 } else {
 250                     throw new InternalError("Unexpected option " + option);
 251                 }
 252             }
 253         });
 254     }
 255 
 256     @SuppressWarnings("unchecked")
 257     private static <T, U extends T> U checkValueType(Object value, Class<T> type) {
 258         if (!type.isAssignableFrom(value.getClass())) {
 259             String s = "Found: " + value.getClass() + ", Expected: " + type;
 260             throw new IllegalArgumentException(s);
 261         }
 262         return (U) value;
 263     }
 264 
 265     private static final JavaIOFileDescriptorAccess fdAccess =
 266             SharedSecrets.getJavaIOFileDescriptorAccess();
 267 
 268     private static void setFlowOption(FileDescriptor fd, SocketFlow f)
 269         throws SocketException
 270     {
 271         int status = platformSocketOptions.setFlowOption(fdAccess.get(fd),
 272                                                          f.priority(),
 273                                                          f.bandwidth());
 274         f.status(status);  // augment the given flow with the status
 275     }
 276 
 277     private static void getFlowOption(FileDescriptor fd, SocketFlow f)
 278             throws SocketException {
 279         int status = platformSocketOptions.getFlowOption(fdAccess.get(fd), f);
 280         f.status(status);  // augment the given flow with the status
 281     }
 282 


< prev index next >