Date: Sun, 23 Mar 2003 23:53:43 +0900 (JST) From: OISHI Masakuni <yamasa@ec.catv.ne.jp> To: freebsd-java@FreeBSD.org Subject: FileChannel#transferTo() is broken. Message-ID: <20030323.235343.74757311.yamasa@ec.catv.ne.jp>
next in thread | raw e-mail | index | archive | help
----Next_Part(Sun_Mar_23_23:53:43_2003_697)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi. I found that FileCannel#transferTo() method in JDK1.4.1 patchset 3 is broken. sample code: public static void main(String[] args) throws Exception { FileChannel src = new FileInputStream("foo").getChannel(); SocketChannel dst = SocketChannel.open(new InetSocketAddress( "192.168.0.1", 3000)); src.transferTo(0, src.size(), dst); } solution: Apply the attached patch. -- OISHI Masakuni ----Next_Part(Sun_Mar_23_23:53:43_2003_697)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-FileChannelImpl.java" --- ../../j2se/src/share/classes/sun/nio/ch/FileChannelImpl.java.orig Fri Sep 6 16:23:07 2002 +++ ../../j2se/src/share/classes/sun/nio/ch/FileChannelImpl.java Fri Mar 21 23:29:47 2003 @@ -377,10 +377,8 @@ return IOStatus.UNSUPPORTED; FileDescriptor targetFD = null; - if (target instanceof FileChannelImpl) - targetFD = ((FileChannelImpl)target).fd; - else if (target instanceof SelChImpl) - targetFD = ((SelChImpl)target).getFD(); + if (target instanceof SocketChannelImpl) + targetFD = ((SocketChannelImpl)target).getFD(); if (targetFD == null) return IOStatus.UNSUPPORTED; ----Next_Part(Sun_Mar_23_23:53:43_2003_697)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-FileChannelImpl.c" --- ../../j2se/src/solaris/native/sun/nio/ch/FileChannelImpl.c.orig Sat Mar 15 14:15:15 2003 +++ ../../j2se/src/solaris/native/sun/nio/ch/FileChannelImpl.c Sat Mar 22 00:33:28 2003 @@ -190,15 +190,18 @@ } return n; #elif defined(__FreeBSD__) - /* - * XXXBSD: make sure that we're returning what java class may understand - */ off_t offset = (off_t)position; - int n = sendfile(dstFD, srcFD, offset, (size_t)count, NULL, NULL, 0); - if (n < 0) { + size_t nbytes = (size_t)count; + off_t sbytes; + int n; + if (nbytes == 0) { + return 0; + } + n = sendfile(srcFD, dstFD, offset, nbytes, NULL, &sbytes, 0); + if ((n < 0) && (errno != EAGAIN)) { JNU_ThrowIOExceptionWithLastError(env, "Transfer failed"); } - return n; + return sbytes; #else return IOS_UNSUPPORTED; #endif ----Next_Part(Sun_Mar_23_23:53:43_2003_697)---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030323.235343.74757311.yamasa>