8285515: (dc) DatagramChannel.disconnect fails with "Invalid argument" on macOS 12.4 beta2

Reviewed-by: dfuchs, alanb
This commit is contained in:
Jaikiran Pai 2022-04-29 09:15:56 +00:00
parent c4f7a850c6
commit 269eae6189
2 changed files with 19 additions and 11 deletions

View File

@ -50,20 +50,28 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jclass clazz,
jint fd = fdval(env, fdo);
int rv;
#if defined(__APPLE__)
// On macOS systems we use disconnectx
rv = disconnectx(fd, SAE_ASSOCID_ANY, SAE_CONNID_ANY);
#else
SOCKETADDRESS sa;
memset(&sa, 0, sizeof(sa));
#if defined(_ALLBSD_SOURCE)
sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET;
#else
sa.sa.sa_family = AF_UNSPEC;
#endif
socklen_t len = isIPv6 ? sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in);
memset(&sa, 0, sizeof(sa));
#if defined(_ALLBSD_SOURCE)
sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET;
#else
sa.sa.sa_family = AF_UNSPEC;
rv = connect(fd, &sa.sa, len);
#endif
rv = connect(fd, &sa.sa, len);
#if defined(_ALLBSD_SOURCE)
#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
// On _ALLBSD_SOURCE except __APPLE__ we consider EADDRNOTAVAIL
// error to be OK and ignore it. __APPLE__ systems are excluded
// in this check since for __APPLE__ systems, unlike other BSD systems,
// we issue a "disconnectx" call (a few lines above),
// which isn't expected to return this error code.
if (rv < 0 && errno == EADDRNOTAVAIL)
rv = errno = 0;
#elif defined(_AIX)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -22,7 +22,7 @@
*/
/* @test
* @bug 7132924
* @bug 7132924 8285515
* @library /test/lib
* @key intermittent
* @summary Test DatagramChannel.disconnect when DatagramChannel is connected to an IPv4 socket