mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8053479: (dc) DatagramChannel.read() throws exception instead of discarding data when buffer too small
Reviewed-by: redestad, dfuchs
This commit is contained in:
parent
c6da6681d4
commit
6ef474a4f4
3 changed files with 185 additions and 45 deletions
|
@ -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 <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
#include "jvm.h"
|
||||
#include "jlong.h"
|
||||
#include "sun_nio_ch_DatagramDispatcher.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nio.h"
|
||||
#include "nio_util.h"
|
||||
#include <limits.h>
|
||||
#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 @@ Java_sun_nio_ch_DatagramDispatcher_read0(JNIEnv *env, jclass clazz,
|
|||
|
||||
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 @@ Java_sun_nio_ch_DatagramDispatcher_readv0(JNIEnv *env, jclass clazz,
|
|||
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 @@ Java_sun_nio_ch_DatagramDispatcher_writev0(JNIEnv *env, jclass clazz,
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue