using the sendfile system call on Darwin
Michael Allman
msa at allman.ms
Fri Mar 5 18:03:19 PST 2010
I've determined the cause of the Transfers.java test failure. The current
implementation of transferTo ignores the count argument.
I've attached my sendfile patch. It's very simple. It should resolve
this issue while adding sendfile support for Darwin. Hopefully this will
pave the way for other *bsd hackers to plug in their own sendfile
implementations where possible.
Cheers,
Michael
On Mon, 1 Mar 2010, Michael Allman wrote:
> Hello All,
>
> Can someone please run the jtreg test target below ("make jdk_nio2" in
> jdk/test) on a recent build of OpenJDK 7 and let me know if you get the
> errors I'm getting? I'd like to know before I start digging, and this is
> a blocker for my sendfile patch.
>
> I will gladly field any questions on running the tests.
>
> Thanks.
>
> Michael
>
> On Mon, 22 Feb 2010, Michael Allman wrote:
>
>> On Sun, 21 Feb 2010, Greg Lewis wrote:
>>
>>> G'day Michael,
>>>
>>> On Fri, Feb 19, 2010 at 01:07:35PM -0800, Michael Allman wrote:
>>>> Ok, I have a patch. How do I submit it?
>>>
>>> Sending it to the list for review (either directly or by putting up a URL
>>> people can see it at) is a good first step :).
>>
>> Before I send it, I have run into a pertinent issue.
>>
>> I am testing the jdk using the jdk/test/Makefile target jdk_nio2. Using
>> the virgin BSD port (i.e. without my patch), I get a whole boatload of
>> failures that look like
>>
>> FAILURE: FileChannel, offset 1, length 7
>> Transfers$Failure: Incorrect transfer length: 65533 (expected 7)
>> at Transfers.testTo(Transfers.java:436)
>> at Transfers.main(Transfers.java:527)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:613)
>> at
>> com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:94)
>> at java.lang.Thread.run(Thread.java:717)
>>
>> Can someone else try running this test and report back their results?
>>
>> I ran it on Mac OS X v. 10.6.2.
>>
>> Cheers,
>>
>> Michael
>>
>
-------------- next part --------------
diff -r be136cb85b3b src/solaris/native/sun/nio/ch/FileChannelImpl.c
--- a/src/solaris/native/sun/nio/ch/FileChannelImpl.c Fri Mar 05 17:07:24 2010 -0800
+++ b/src/solaris/native/sun/nio/ch/FileChannelImpl.c Fri Mar 05 17:54:41 2010 -0800
@@ -256,54 +256,22 @@
#endif
#ifdef _ALLBSD_SOURCE
- /*
- * XXXBSD: make sure that we're returning what java class may understand
- *
- * XXXBSD: I'd prefer to have it implemented with sendfile(), but since
- * FreeBSD's sendfile() is only supposed to be used in file->socket
- * schema we need to provide some kind of fall-back operation, if
- * sendfile() failed with ENOTSOCK error only.
- */
- void *buf;
- off_t offset = (off_t)position;
- int r, w = 0;
+#ifdef __APPLE__
+ int result = sendfile(srcFD, dstFD, position, &count, NULL, 0);
- buf = malloc(4096);
- if (buf == NULL) {
- JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
- return IOS_THROWN;
- }
+ if (result == 0 || errno == EAGAIN)
+ return count;
- while ((r = pread(srcFD, buf, 4096, offset)) > 0) {
- w = write(dstFD, buf, r);
- if (w == -1)
- break;
- offset += w;
- }
- free(buf);
+ if (errno == EINTR)
+ return IOS_INTERRUPTED;
- /*
- * Similar to solaris if we've transferred any data return
- * the number of bytes and ignore any error
- */
- if (offset - (off_t)position > 0)
- return (offset - (off_t)position);
+ if (errno == ENOTSOCK)
+ return IOS_UNSUPPORTED_CASE;
- /*
- * Deal with NBIO EAGAIN & EINTR the same as solaris.
- */
- if (r == -1 || w == -1) {
- switch (errno) {
- case EAGAIN:
- return IOS_UNAVAILABLE;
- case EINTR:
- return IOS_INTERRUPTED;
- default:
- JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
- return IOS_THROWN;
- }
- }
+ JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
+ return IOS_THROWN;
+#endif
- return (0);
+ return IOS_UNSUPPORTED;
#endif
}
More information about the bsd-port-dev
mailing list