Skip to content

Commit

Permalink
We need to use disconnectx(...) on macOS (netty#12629)
Browse files Browse the repository at this point in the history
Motivation:

We need to use disconnectx(...) on macOS as using connect(...) for disconnect is not working anymore.

Modifications:

Use disconnectx(...)

Result:

No more failure on disconnect(...)
  • Loading branch information
normanmaurer authored Jul 20, 2022
1 parent c882d80 commit f326098
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion transport-native-unix-common/src/main/c/netty_unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ static jint netty_unix_socket_finishConnect(JNIEnv* env, jclass clazz, jint fd)
}

static jint netty_unix_socket_disconnect(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6) {
#ifndef __APPLE__
struct sockaddr_storage addr;
int len;

memset(&addr, 0, sizeof(addr));

// You can disconnect connection-less sockets by using AF_UNSPEC.
// See man 2 connect.
if (ipv6 == JNI_TRUE) {
Expand All @@ -552,11 +552,16 @@ static jint netty_unix_socket_disconnect(JNIEnv* env, jclass clazz, jint fd, jbo
ipaddr->sin_family = AF_UNSPEC;
len = sizeof(struct sockaddr_in);
}
#endif // __APPLE__

int res;
int err;
do {
#ifdef __APPLE__
res = disconnectx(fd, SAE_ASSOCID_ANY, SAE_CONNID_ANY);
#else
res = connect(fd, (struct sockaddr*) &addr, len);
#endif // __APPLE__
} while (res == -1 && ((err = errno) == EINTR));

// EAFNOSUPPORT is harmless in this case.
Expand Down

0 comments on commit f326098

Please sign in to comment.