--- old/src/java.base/unix/native/libnio/ch/DatagramDispatcher.c 2020-01-15 12:45:30.000000000 +0000 +++ new/src/java.base/unix/native/libnio/ch/DatagramDispatcher.c 2020-01-15 12:45:29.000000000 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -23,32 +23,30 @@ * questions. */ -/* - */ - -#include "jni.h" -#include "jni_util.h" -#include "jvm.h" -#include "jlong.h" -#include "sun_nio_ch_DatagramDispatcher.h" #include #include #include #include +#include +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" +#include "nio.h" #include "nio_util.h" -#include +#include "sun_nio_ch_DatagramDispatcher.h" JNIEXPORT jint JNICALL Java_sun_nio_ch_DatagramDispatcher_read0(JNIEnv *env, jclass clazz, - jobject fdo, jlong address, jint len) + jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); void *buf = (void *)jlong_to_ptr(address); int result = recv(fd, buf, len, 0); if (result < 0 && errno == ECONNREFUSED) { JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); - return -2; + return IOS_THROWN; } return convertReturnVal(env, result, JNI_TRUE); } @@ -56,7 +54,7 @@ JNIEXPORT jlong JNICALL Java_sun_nio_ch_DatagramDispatcher_readv0(JNIEnv *env, jclass clazz, - jobject fdo, jlong address, jint len) + jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); ssize_t result = 0; @@ -74,28 +72,28 @@ result = recvmsg(fd, &m, 0); if (result < 0 && errno == ECONNREFUSED) { JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); - return -2; + return IOS_THROWN; } return convertLongReturnVal(env, (jlong)result, JNI_TRUE); } JNIEXPORT jint JNICALL Java_sun_nio_ch_DatagramDispatcher_write0(JNIEnv *env, jclass clazz, - jobject fdo, jlong address, jint len) + jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); void *buf = (void *)jlong_to_ptr(address); int result = send(fd, buf, len, 0); if (result < 0 && errno == ECONNREFUSED) { JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); - return -2; + return IOS_THROWN; } return convertReturnVal(env, result, JNI_FALSE); } JNIEXPORT jlong JNICALL Java_sun_nio_ch_DatagramDispatcher_writev0(JNIEnv *env, jclass clazz, - jobject fdo, jlong address, jint len) + jobject fdo, jlong address, jint len) { jint fd = fdval(env, fdo); struct iovec *iov = (struct iovec *)jlong_to_ptr(address); @@ -113,7 +111,7 @@ result = sendmsg(fd, &m, 0); if (result < 0 && errno == ECONNREFUSED) { JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); - return -2; + return IOS_THROWN; } return convertLongReturnVal(env, (jlong)result, JNI_FALSE); } --- old/src/java.base/windows/native/libnio/ch/DatagramDispatcher.c 2020-01-15 12:45:33.000000000 +0000 +++ new/src/java.base/windows/native/libnio/ch/DatagramDispatcher.c 2020-01-15 12:45:32.000000000 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -23,21 +23,19 @@ * questions. */ -/* - */ - #include #include #include + #include "jni.h" #include "jni_util.h" #include "jvm.h" #include "jlong.h" -#include "sun_nio_ch_DatagramDispatcher.h" - #include "nio.h" #include "nio_util.h" +#include "sun_nio_ch_DatagramDispatcher.h" + /************************************************************** * DatagramDispatcher.c @@ -45,7 +43,7 @@ JNIEXPORT jint JNICALL Java_sun_nio_ch_DatagramDispatcher_read0(JNIEnv *env, jclass clazz, jobject fdo, - jlong address, jint len) + jlong address, jint len) { /* set up */ int i = 0; @@ -69,16 +67,18 @@ if (i == SOCKET_ERROR) { int theErr = (jint)WSAGetLastError(); - if (theErr == WSAEWOULDBLOCK) { - return IOS_UNAVAILABLE; - } - if (theErr == WSAECONNRESET) { - purgeOutstandingICMP(env, clazz, fd); - JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); + if (theErr != WSAEMSGSIZE) { + if (theErr == WSAEWOULDBLOCK) { + return IOS_UNAVAILABLE; + } + if (theErr == WSAECONNRESET) { + purgeOutstandingICMP(env, clazz, fd); + JNU_ThrowByName(env, JNU_JAVANETPKG "PortUnreachableException", 0); + return IOS_THROWN; + } + JNU_ThrowIOExceptionWithLastError(env, "WSARecv failed"); return IOS_THROWN; } - JNU_ThrowIOExceptionWithLastError(env, "Write failed"); - return IOS_THROWN; } return convertReturnVal(env, (jint)read, JNI_TRUE); @@ -104,7 +104,7 @@ for(i=0; i buffer.put((byte)i)); + buffer.flip(); + + int n = dc.send(buffer, target); + assertTrue(n == size); + buffer.flip(); + return buffer; + } + + static void assertTrue(boolean e) { + if (!e) throw new RuntimeException(); + } +}