[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: native FileChannelImpl cleanups and simple force imple
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI: native FileChannelImpl cleanups and simple force implementation |
Date: |
Mon, 11 Jul 2005 19:16:01 +0200 |
Hi,
This adds a simple force() implementation to FileChannelImpl and fixes a
couple of subtle issues with some other native methods. We would
read/write the wrong amount of bytes when a read() or write() was
interrupted and in one case we would forget to return when an error
condition was encountered. The force implementation just does a fsync
(ignoring the difference between file and meta data) since that was the
only thing we had a TARGET_NATIVE macro for.
2005-07-10 Mark Wielaard <address@hidden>
* gnu/java/nio/channels/FileChannelImpl.java (force): New native
method.
(force(boolean)): Call new native force method.
* native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
(Java_gnu_java_nio_channels_FileChannelImpl_read__):
Test for result != TARGET_NATIVE_OK as stop condition.
(Java_gnu_java_nio_channels_FileChannelImpl_read___3BII):
Check overflow and underflow. Only increase bytes_read when
we didn't get an error.
(Java_gnu_java_nio_channels_FileChannelImpl_write__I):
Return when we encounter an error.
(Java_gnu_java_nio_channels_FileChannelImpl_write___3BII):
Only increase bytes_written when we didn't get an error.
(Java_gnu_java_nio_channels_FileChannelImpl_force): New function.
* include/gnu_java_nio_channels_FileChannelImpl.h: Regenerated.
Committed,
Mark
? include/Makefile.mark
? include/java_io_ObjectInputStream.h
Index: native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c,v
retrieving revision 1.17
diff -u -r1.17 gnu_java_nio_channels_FileChannelImpl.c
--- native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 10 Jul 2005
20:11:33 -0000 1.17
+++ native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 11 Jul 2005
15:11:09 -0000
@@ -543,7 +543,7 @@
return (-1);
}
}
- while (bytes_read != 1);
+ while (result != TARGET_NATIVE_OK);
return ((jint) (data & 0xFF));
}
@@ -571,6 +571,12 @@
if (length == 0)
return 0;
+ if (offset < 0)
+ {
+ JCL_ThrowException (env, IO_EXCEPTION, "negative offset");
+ return -1;
+ }
+
bufptr = (*env)->GetByteArrayElements (env, buffer, 0);
if (!bufptr)
{
@@ -578,6 +584,13 @@
return (-1);
}
+ if (length + offset > (*env)->GetArrayLength (env, buffer))
+ {
+ JCL_ThrowException (env, IO_EXCEPTION,
+ "length + offset > buffer.length");
+ return -1;
+ }
+
bytes_read = 0;
do
{
@@ -600,7 +613,8 @@
(*env)->ReleaseByteArrayElements (env, buffer, bufptr, 0);
return -1;
}
- bytes_read += n;
+ if (result == TARGET_NATIVE_OK)
+ bytes_read += n;
}
while (bytes_read < 1);
@@ -634,12 +648,29 @@
{
JCL_ThrowException (env, IO_EXCEPTION,
TARGET_NATIVE_LAST_ERROR_STRING ());
+ return;
}
}
while (result != TARGET_NATIVE_OK);
}
/*
+ * Copies all parts of a file to disk.
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_nio_channels_FileChannelImpl_force (JNIEnv * env,
+ jobject obj)
+{
+ int native_fd;
+ int result;
+ native_fd = get_native_fd (env, obj);
+ TARGET_NATIVE_FILE_FSYNC (native_fd, result);
+ if (result != TARGET_NATIVE_OK)
+ JCL_ThrowException (env, IO_EXCEPTION,
+ TARGET_NATIVE_LAST_ERROR_STRING ());
+}
+
+/*
* Writes a byte buffer to the specified file descriptor
* Return status code, exception on error
*/
@@ -683,7 +714,8 @@
(*env)->ReleaseByteArrayElements (env, buffer, bufptr, 0);
return;
}
- bytes_written += n;
+ if (result == TARGET_NATIVE_OK)
+ bytes_written += n;
}
(*env)->ReleaseByteArrayElements (env, buffer, bufptr, 0);
Index: include/gnu_java_nio_channels_FileChannelImpl.h
===================================================================
RCS file:
/cvsroot/classpath/classpath/include/gnu_java_nio_channels_FileChannelImpl.h,v
retrieving revision 1.4
diff -u -r1.4 gnu_java_nio_channels_FileChannelImpl.h
--- include/gnu_java_nio_channels_FileChannelImpl.h 21 Feb 2005 17:42:37
-0000 1.4
+++ include/gnu_java_nio_channels_FileChannelImpl.h 11 Jul 2005 15:11:09
-0000
@@ -24,6 +24,7 @@
JNIEXPORT void JNICALL Java_gnu_java_nio_channels_FileChannelImpl_write___3BII
(JNIEnv *env, jobject, jbyteArray, jint, jint);
JNIEXPORT void JNICALL Java_gnu_java_nio_channels_FileChannelImpl_write__I
(JNIEnv *env, jobject, jint);
JNIEXPORT jobject JNICALL Java_gnu_java_nio_channels_FileChannelImpl_mapImpl
(JNIEnv *env, jobject, jchar, jlong, jint);
+JNIEXPORT void JNICALL Java_gnu_java_nio_channels_FileChannelImpl_force
(JNIEnv *env, jobject);
JNIEXPORT jboolean JNICALL Java_gnu_java_nio_channels_FileChannelImpl_lock
(JNIEnv *env, jobject, jlong, jlong, jboolean, jboolean);
#undef gnu_java_nio_channels_FileChannelImpl_READ
#define gnu_java_nio_channels_FileChannelImpl_READ 1L
Index: gnu/java/nio/channels/FileChannelImpl.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/gnu/java/nio/channels/FileChannelImpl.java,v
retrieving revision 1.14
diff -u -r1.14 FileChannelImpl.java
--- gnu/java/nio/channels/FileChannelImpl.java 2 Jul 2005 20:32:13 -0000
1.14
+++ gnu/java/nio/channels/FileChannelImpl.java 11 Jul 2005 15:11:09 -0000
@@ -302,7 +302,11 @@
{
if (!isOpen ())
throw new ClosedChannelException ();
+
+ force ();
}
+
+ private native void force ();
// like transferTo, but with a count of less than 2Gbytes
private int smallTransferTo (long position, int count,
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: native FileChannelImpl cleanups and simple force implementation,
Mark Wielaard <=