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