Skip to content

Commit c7c080a

Browse files
Ben Taylorshipilev
authored andcommitted
8285515: (dc) DatagramChannel.disconnect fails with "Invalid argument" on macOS 12.4
Reviewed-by: phh, shade Backport-of: 269eae61894b6bd0a7512045a369b53df747f6e5
1 parent 3e69b49 commit c7c080a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
8989

9090
#ifdef __solaris__
9191
rv = connect(fd, 0, 0);
92-
#endif
93-
94-
#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
92+
#elif defined(__APPLE__)
93+
// On macOS systems we use disconnectx
94+
rv = disconnectx(fd, SAE_ASSOCID_ANY, SAE_CONNID_ANY);
95+
#elif defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
9596
{
9697
int len;
9798
SOCKADDR sa;
@@ -120,8 +121,16 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
120121
}
121122

122123
rv = connect(fd, (struct sockaddr *)&sa, len);
124+
}
123125

124-
#if defined(_ALLBSD_SOURCE)
126+
#endif
127+
128+
#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
129+
// On _ALLBSD_SOURCE except __APPLE__ we consider EADDRNOTAVAIL
130+
// error to be OK and ignore it. __APPLE__ systems are excluded
131+
// in this check since for __APPLE__ systems, unlike other BSD systems,
132+
// we issue a "disconnectx" call (a few lines above),
133+
// which isn't expected to return this error code.
125134
if (rv < 0 && errno == EADDRNOTAVAIL)
126135
rv = errno = 0;
127136
#endif
@@ -133,8 +142,6 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
133142
if (rv < 0 && errno == EAFNOSUPPORT)
134143
rv = errno = 0;
135144
#endif
136-
}
137-
#endif
138145

139146
if (rv < 0)
140147
handleSocketError(env, errno);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 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,8 @@
2222
*/
2323

2424
/* @test
25-
* @bug 7132924
25+
* @bug 7132924 8285515
26+
* @key intermittent
2627
* @summary Test DatagramChannel.disconnect when DatagramChannel is connected to an IPv4 socket
2728
* @run main Disconnect
2829
* @run main/othervm -Djava.net.preferIPv4Stack=true Disconnect

0 commit comments

Comments
 (0)