src/java.base/unix/native/libnio/ch/SocketDispatcher.c
changeset 54554 c171aa9e5d3e
parent 47216 71c04702a3d5
parent 54246 f04e3492fd88
child 57339 40fdbdd92617
--- a/src/java.base/unix/native/libnio/ch/SocketDispatcher.c	Tue Jan 22 14:14:52 2019 -0800
+++ b/src/java.base/unix/native/libnio/ch/SocketDispatcher.c	Tue Mar 26 10:55:17 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 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,12 +23,43 @@
  * questions.
  */
 
-#include "jni.h"
-#include "jni_util.h"
-#include "jvm.h"
-#include "jlong.h"
+ #include <sys/types.h>
+ #include <sys/uio.h>
+ #include <unistd.h>
+
+ #include "jni.h"
+ #include "jni_util.h"
+ #include "jlong.h"
+ #include "nio.h"
+ #include "nio_util.h"
+ #include "sun_nio_ch_SocketDispatcher.h"
 
-/* this is a fake c file to make the build happy since there is no
-   real SocketDispatcher.c file on Solaris but there is on windows. */
+ JNIEXPORT jint JNICALL
+ Java_sun_nio_ch_SocketDispatcher_read0(JNIEnv *env, jclass clazz,
+                                        jobject fdo, jlong address, jint len)
+ {
+     jint fd = fdval(env, fdo);
+     void *buf = (void *)jlong_to_ptr(address);
+     jint n = read(fd, buf, len);
+     if ((n == -1) && (errno == ECONNRESET || errno == EPIPE)) {
+         JNU_ThrowByName(env, "sun/net/ConnectionResetException", "Connection reset");
+         return IOS_THROWN;
+     } else {
+         return convertReturnVal(env, n, JNI_TRUE);
+     }
+ }
 
-static jfieldID fd_fdID;        /* for jint 'fd' in java.io.FileDescriptor */
+ JNIEXPORT jlong JNICALL
+ Java_sun_nio_ch_SocketDispatcher_readv0(JNIEnv *env, jclass clazz,
+                                         jobject fdo, jlong address, jint len)
+ {
+     jint fd = fdval(env, fdo);
+     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
+     jlong n = readv(fd, iov, len);
+     if ((n == -1) && (errno == ECONNRESET || errno == EPIPE)) {
+         JNU_ThrowByName(env, "sun/net/ConnectionResetException", "Connection reset");
+         return IOS_THROWN;
+     } else {
+         return convertLongReturnVal(env, n, JNI_TRUE);
+     }
+ }