goiri commented on a change in pull request #1825: HDFS-15151 Use TransmitFile 
for file to socket data transfer
URL: https://github.com/apache/hadoop/pull/1825#discussion_r373806641
 
 

 ##########
 File path: 
hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/nativeio/NativeIO.c
 ##########
 @@ -1341,6 +1350,68 @@ 
Java_org_apache_hadoop_io_nativeio_NativeIO_00024Windows_extendWorkingSetSize(
 #endif
 }
 
+jint
+fdval(JNIEnv *env, jobject fdo)
+{
+    return (*env)->GetIntField(env, fdo, fd_fdID);
+}
+
+jlong
+handleval(JNIEnv *env, jobject fdo)
+{
+    return (*env)->GetLongField(env, fdo, handle_fdID);
+}
+
+JNIEXPORT jlong JNICALL
+Java_org_apache_hadoop_io_nativeio_NativeIO_00024Windows_transmitFile(
+  JNIEnv *env, jobject jObject, jobject srcFD, jlong position, jlong count,
+  jobject dstFD)
+{
+#ifdef UNIX
+  THROW(env, "java/io/IOException",
+    "The function transmitFile is not supported on Unix");
+#endif
+
+#ifdef WINDOWS
+    jclass clazz;
+
+    HANDLE src;
+    HANDLE dst;
+    LARGE_INTEGER srcPosition;
+    DWORD numberOfBytesToWrite;
+    BOOL result;
+
+    clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
+    fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
+    handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");
+
+    src = (HANDLE)(handleval(env, srcFD));
+    dst = (SOCKET)(fdval(env, dstFD));
+
+    numberOfBytesToWrite = (DWORD)count;
+
+    srcPosition.QuadPart = position;
+    result = SetFilePointerEx(src, srcPosition, &srcPosition, FILE_BEGIN);
+    if (result == 0) {
+        throw_ioe(env, WSAGetLastError());
+    }
+
+    result = TransmitFile(
+        dst,
+        src,
+        numberOfBytesToWrite,
+        0,
+        NULL,
+        NULL,
+        TF_USE_KERNEL_APC
+    );
+    if (!result) {
+        throw_ioe(env, WSAGetLastError());
+    }
+    return numberOfBytesToWrite;
+#endif
 
 Review comment:
   Anyway to rewrite this so we don't get:
   NativeIO.c:1413:1: warning: control reaches end of non-void function 
[-Wreturn-type]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to