use of java.net.SocketOption in project OpenSearch by opensearch-project.
the class NetUtils method getExtendedSocketOptionOrNull.
@SuppressWarnings("unchecked")
private static <T> SocketOption<T> getExtendedSocketOptionOrNull(String fieldName) {
try {
final Class<?> extendedSocketOptionsClass = Class.forName("jdk.net.ExtendedSocketOptions");
final Field field = extendedSocketOptionsClass.getField(fieldName);
return (SocketOption<T>) field.get(null);
} catch (Exception t) {
// ignore
return null;
}
}
use of java.net.SocketOption in project servicetalk by apple.
the class TcpFastOpenTest method newClient.
private static BlockingHttpClient newClient(final ServerContext serverContext, final Collection<HttpProtocol> protocols, final boolean secure, @SuppressWarnings("rawtypes") final Map<SocketOption, Object> clientOptions) {
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> builder = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(toConfigs(protocols));
if (secure) {
builder.sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).sniHostname(serverPemHostname()).build());
}
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : clientOptions.entrySet()) {
@SuppressWarnings("unchecked") SocketOption<Object> option = entry.getKey();
builder.socketOption(option, entry.getValue());
}
return builder.buildBlocking();
}
use of java.net.SocketOption in project servicetalk by apple.
the class TcpFastOpenTest method requestSucceedsEvenIfTcpFastOpenNotEnabledOrSupported.
@ParameterizedTest(name = "{displayName} [{index}] protocols={0}, secure={1}, serverListenOptions={2}, clientOptions={3}")
@MethodSource("sslProviders")
void requestSucceedsEvenIfTcpFastOpenNotEnabledOrSupported(final Collection<HttpProtocol> protocols, final boolean secure, @SuppressWarnings("rawtypes") final Map<SocketOption, Object> serverListenOptions, @SuppressWarnings("rawtypes") final Map<SocketOption, Object> clientOptions) throws Exception {
assumeTcpFastOpen(clientOptions);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0)).protocols(toConfigs(protocols));
if (secure) {
serverBuilder.sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).build());
}
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : serverListenOptions.entrySet()) {
@SuppressWarnings("unchecked") SocketOption<Object> option = entry.getKey();
serverBuilder.listenSocketOption(option, entry.getValue());
}
try (ServerContext serverContext = serverBuilder.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = newClient(serverContext, protocols, secure, clientOptions)) {
assertEquals(HttpResponseStatus.OK, client.request(client.get("/")).status());
}
}
use of java.net.SocketOption in project j2objc by google.
the class AsynchronousSocketChannelTest method test_supportedOptions.
public void test_supportedOptions() throws Throwable {
AsynchronousSocketChannel assc = AsynchronousSocketChannel.open();
Set<SocketOption<?>> supportedOptions = assc.supportedOptions();
assertEquals(5, supportedOptions.size());
assertTrue(supportedOptions.contains(StandardSocketOptions.SO_REUSEADDR));
assertTrue(supportedOptions.contains(StandardSocketOptions.SO_RCVBUF));
assertTrue(supportedOptions.contains(StandardSocketOptions.SO_SNDBUF));
assertTrue(supportedOptions.contains(StandardSocketOptions.SO_KEEPALIVE));
assertTrue(supportedOptions.contains(StandardSocketOptions.TCP_NODELAY));
// supportedOptions should work after close according to spec
assc.close();
supportedOptions = assc.supportedOptions();
assertEquals(5, supportedOptions.size());
}
use of java.net.SocketOption in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_supportedOptions.
public void test_supportedOptions() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
Set<SocketOption<?>> supportedOptions = assc.supportedOptions();
assertEquals(2, supportedOptions.size());
assertTrue(supportedOptions.contains(StandardSocketOptions.SO_REUSEADDR));
assertTrue(supportedOptions.contains(StandardSocketOptions.SO_RCVBUF));
// supportedOptions should work after close according to spec
assc.close();
supportedOptions = assc.supportedOptions();
assertEquals(2, supportedOptions.size());
}
Aggregations