Path: blob/master/src/java.base/unix/native/libnio/ch/SocketDispatcher.c
41133 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <sys/types.h>26#include <sys/uio.h>27#include <unistd.h>2829#include "jni.h"30#include "jni_util.h"31#include "jlong.h"32#include "nio.h"33#include "nio_util.h"34#include "sun_nio_ch_SocketDispatcher.h"3536JNIEXPORT jint JNICALL37Java_sun_nio_ch_SocketDispatcher_read0(JNIEnv *env, jclass clazz,38jobject fdo, jlong address, jint len)39{40jint fd = fdval(env, fdo);41void *buf = (void *)jlong_to_ptr(address);42jint n = read(fd, buf, len);43if ((n == -1) && (errno == ECONNRESET || errno == EPIPE)) {44JNU_ThrowByName(env, "sun/net/ConnectionResetException", "Connection reset");45return IOS_THROWN;46} else {47return convertReturnVal(env, n, JNI_TRUE);48}49}5051JNIEXPORT jlong JNICALL52Java_sun_nio_ch_SocketDispatcher_readv0(JNIEnv *env, jclass clazz,53jobject fdo, jlong address, jint len)54{55jint fd = fdval(env, fdo);56struct iovec *iov = (struct iovec *)jlong_to_ptr(address);57jlong n = readv(fd, iov, len);58if ((n == -1) && (errno == ECONNRESET || errno == EPIPE)) {59JNU_ThrowByName(env, "sun/net/ConnectionResetException", "Connection reset");60return IOS_THROWN;61} else {62return convertLongReturnVal(env, n, JNI_TRUE);63}64}656667