8217451: ExtendedSocketOptions should encapsulate support for SO_FLOW_SLA

Reviewed-by: michaelm, chegar
This commit is contained in:
Alan Bateman 2019-01-22 12:32:19 +00:00
parent 911c7ff446
commit bb1e1c7120
9 changed files with 79 additions and 66 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,21 +54,53 @@ public abstract class ExtendedSocketOptions {
/** Return the, possibly empty, set of extended socket options available. */
public final Set<SocketOption<?>> options() { return options; }
public static final Set<SocketOption<?>> options(short type) {
return getInstance().options0(type);
/**
* Returns the (possibly empty) set of extended socket options for
* stream-oriented listening sockets.
*/
public static Set<SocketOption<?>> serverSocketOptions() {
return getInstance().options0(SOCK_STREAM, true);
}
private Set<SocketOption<?>> options0(short type) {
Set<SocketOption<?>> extOptions = null;
/**
* Returns the (possibly empty) set of extended socket options for
* stream-oriented connecting sockets.
*/
public static Set<SocketOption<?>> clientSocketOptions() {
return getInstance().options0(SOCK_STREAM, false);
}
/**
* Returns the (possibly empty) set of extended socket options for
* datagram-oriented sockets.
*/
public static Set<SocketOption<?>> datagramSocketOptions() {
return getInstance().options0(SOCK_DGRAM, false);
}
private boolean isDatagramOption(SocketOption<?> option) {
return !option.name().startsWith("TCP_");
}
private boolean isStreamOption(SocketOption<?> option, boolean server) {
if (server && "SO_FLOW_SLA".equals(option.name())) {
return false;
} else {
return !option.name().startsWith("UDP_");
}
}
private Set<SocketOption<?>> options0(short type, boolean server) {
Set<SocketOption<?>> extOptions;
switch (type) {
case SOCK_DGRAM:
extOptions = options.stream()
.filter((option) -> !option.name().startsWith("TCP_"))
.filter(option -> isDatagramOption(option))
.collect(Collectors.toUnmodifiableSet());
break;
case SOCK_STREAM:
extOptions = options.stream()
.filter((option) -> !option.name().startsWith("UDP_"))
.filter(option -> isStreamOption(option, server))
.collect(Collectors.toUnmodifiableSet());
break;
default:

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import sun.net.NetHooks;
import sun.net.ext.ExtendedSocketOptions;
import static sun.net.ext.ExtendedSocketOptions.SOCK_STREAM;
/**
* Base implementation of AsynchronousServerSocketChannel.
@ -236,7 +235,7 @@ abstract class AsynchronousServerSocketChannelImpl
if (Net.isReusePortAvailable()) {
set.add(StandardSocketOptions.SO_REUSEPORT);
}
set.addAll(ExtendedSocketOptions.options(SOCK_STREAM));
set.addAll(ExtendedSocketOptions.serverSocketOptions());
return Collections.unmodifiableSet(set);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,6 @@ import java.util.concurrent.*;
import java.util.concurrent.locks.*;
import sun.net.NetHooks;
import sun.net.ext.ExtendedSocketOptions;
import static sun.net.ext.ExtendedSocketOptions.SOCK_STREAM;
/**
* Base implementation of AsynchronousSocketChannel
@ -513,7 +512,7 @@ abstract class AsynchronousSocketChannelImpl
set.add(StandardSocketOptions.SO_REUSEPORT);
}
set.add(StandardSocketOptions.TCP_NODELAY);
set.addAll(ExtendedSocketOptions.options(SOCK_STREAM));
set.addAll(ExtendedSocketOptions.clientSocketOptions());
return Collections.unmodifiableSet(set);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -57,7 +57,6 @@ import java.util.concurrent.locks.ReentrantLock;
import sun.net.ResourceManager;
import sun.net.ext.ExtendedSocketOptions;
import static sun.net.ext.ExtendedSocketOptions.SOCK_DGRAM;
/**
* An implementation of DatagramChannels.
@ -335,7 +334,7 @@ class DatagramChannelImpl
set.add(StandardSocketOptions.IP_MULTICAST_IF);
set.add(StandardSocketOptions.IP_MULTICAST_TTL);
set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
set.addAll(ExtendedSocketOptions.options(SOCK_DGRAM));
set.addAll(ExtendedSocketOptions.datagramSocketOptions());
return Collections.unmodifiableSet(set);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,11 +28,9 @@ package sun.nio.ch;
import java.io.FileDescriptor;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ProtocolFamily;
import java.net.ServerSocket;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardProtocolFamily;
import java.net.StandardSocketOptions;
import java.nio.channels.AlreadyBoundException;
import java.nio.channels.AsynchronousCloseException;
@ -50,7 +48,6 @@ import java.util.concurrent.locks.ReentrantLock;
import sun.net.NetHooks;
import sun.net.ext.ExtendedSocketOptions;
import static sun.net.ext.ExtendedSocketOptions.SOCK_STREAM;
/**
* An implementation of ServerSocketChannels
@ -193,7 +190,7 @@ class ServerSocketChannelImpl
if (Net.isReusePortAvailable()) {
set.add(StandardSocketOptions.SO_REUSEPORT);
}
set.addAll(ExtendedSocketOptions.options(SOCK_STREAM));
set.addAll(ExtendedSocketOptions.serverSocketOptions());
return Collections.unmodifiableSet(set);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,7 +55,6 @@ import java.util.concurrent.locks.ReentrantLock;
import sun.net.NetHooks;
import sun.net.ext.ExtendedSocketOptions;
import sun.net.util.SocketExceptions;
import static sun.net.ext.ExtendedSocketOptions.SOCK_STREAM;
/**
* An implementation of SocketChannels
@ -282,7 +281,7 @@ class SocketChannelImpl
// additional options required by socket adaptor
set.add(StandardSocketOptions.IP_TOS);
set.add(ExtendedSocketOption.SO_OOBINLINE);
set.addAll(ExtendedSocketOptions.options(SOCK_STREAM));
set.addAll(ExtendedSocketOptions.clientSocketOptions());
return Collections.unmodifiableSet(set);
}
}