Skip to content

Commit 76b69eb

Browse files
committed
8285515: (dc) DatagramChannel.disconnect fails with "Invalid argument" on macOS 12.4
Backport-of: 269eae61894b6bd0a7512045a369b53df747f6e5
1 parent 00cf424 commit 76b69eb

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,28 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jclass clazz,
5050
jint fd = fdval(env, fdo);
5151
int rv;
5252

53+
#if defined(__APPLE__)
54+
// On macOS systems we use disconnectx
55+
rv = disconnectx(fd, SAE_ASSOCID_ANY, SAE_CONNID_ANY);
56+
#else
5357
SOCKETADDRESS sa;
58+
memset(&sa, 0, sizeof(sa));
59+
#if defined(_ALLBSD_SOURCE)
60+
sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET;
61+
#else
62+
sa.sa.sa_family = AF_UNSPEC;
63+
#endif
5464
socklen_t len = isIPv6 ? sizeof(struct sockaddr_in6) :
5565
sizeof(struct sockaddr_in);
56-
57-
memset(&sa, 0, sizeof(sa));
58-
#if defined(_ALLBSD_SOURCE)
59-
sa.sa.sa_family = isIPv6 ? AF_INET6 : AF_INET;
60-
#else
61-
sa.sa.sa_family = AF_UNSPEC;
62-
#endif
63-
6466
rv = connect(fd, &sa.sa, len);
67+
#endif
6568

66-
#if defined(_ALLBSD_SOURCE)
69+
#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
70+
// On _ALLBSD_SOURCE except __APPLE__ we consider EADDRNOTAVAIL
71+
// error to be OK and ignore it. __APPLE__ systems are excluded
72+
// in this check since for __APPLE__ systems, unlike other BSD systems,
73+
// we issue a "disconnectx" call (a few lines above),
74+
// which isn't expected to return this error code.
6775
if (rv < 0 && errno == EADDRNOTAVAIL)
6876
rv = errno = 0;
6977
#elif defined(_AIX)

test/jdk/java/nio/channels/DatagramChannel/Disconnect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/* @test
25-
* @bug 7132924
25+
* @bug 7132924 8285515
2626
* @library /test/lib
2727
* @key intermittent
2828
* @summary Test DatagramChannel.disconnect when DatagramChannel is connected to an IPv4 socket

0 commit comments

Comments
 (0)