8280241: (aio) AsynchronousSocketChannel init fails in IPv6 only Windows env

Reviewed-by: dfuchs, alanb
This commit is contained in:
Daniel Jeliński 2022-01-25 11:15:47 +00:00 committed by Daniel Fuchs
parent 28796cbd1d
commit 36fbec78be
2 changed files with 10 additions and 2 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, 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
@ -69,6 +69,10 @@ Java_sun_nio_ch_WindowsAsynchronousServerSocketChannelImpl_initIDs(JNIEnv* env,
DWORD dwBytes;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET && WSAGetLastError() == WSAEAFNOSUPPORT) {
/* IPv4 unavailable... try IPv6 instead */
s = socket(AF_INET6, SOCK_STREAM, 0);
}
if (s == INVALID_SOCKET) {
JNU_ThrowIOExceptionWithLastError(env, "socket failed");
return;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, 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
@ -66,6 +66,10 @@ Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_initIDs(JNIEnv* env, jclass
DWORD dwBytes;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET && WSAGetLastError() == WSAEAFNOSUPPORT) {
/* IPv4 unavailable... try IPv6 instead */
s = socket(AF_INET6, SOCK_STREAM, 0);
}
if (s == INVALID_SOCKET) {
JNU_ThrowIOExceptionWithLastError(env, "socket failed");
return;