Skip to content
Permalink
Browse files
8285515: (dc) DatagramChannel.disconnect fails with "Invalid argument…
…" on macOS 12.4

Backport-of: 269eae61894b6bd0a7512045a369b53df747f6e5
  • Loading branch information
lu-pinto authored and Rob McKenna committed Jun 3, 2022
1 parent c08f40e commit 7af433da4d05bad055b1c8426ab65c9799c923a7
Showing 2 changed files with 19 additions and 11 deletions.
@@ -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;
#endif

rv = connect(fd, &sa.sa, len);
#endif

#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)
@@ -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

1 comment on commit 7af433d

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 7af433d Jun 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.