Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 26094 invoked from network); 22 Mar 2007 15:32:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Mar 2007 15:32:56 -0000 Received: (qmail 1774 invoked by uid 500); 22 Mar 2007 15:33:01 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 1751 invoked by uid 500); 22 Mar 2007 15:33:01 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 1724 invoked by uid 99); 22 Mar 2007 15:33:01 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2007 08:33:01 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2007 08:32:52 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id D23B7714071 for ; Thu, 22 Mar 2007 08:32:32 -0700 (PDT) Message-ID: <19978921.1174577552857.JavaMail.jira@brutus> Date: Thu, 22 Mar 2007 08:32:32 -0700 (PDT) From: "Sergey Dmitriev (JIRA)" To: commits@harmony.apache.org Subject: [jira] Updated: (HARMONY-3475) java.nio.SocketChannel's OutputStream cannot write a single byte In-Reply-To: <2919649.1174577432393.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HARMONY-3475?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Sergey Dmitriev updated HARMONY-3475: ------------------------------------- Description: java.nio.SocketChannelImpl$SocketChannelOutputStream.write(int) does not actually write a byte. public void write(int oneByte) throws IOException { if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } ByteBuffer buffer = ByteBuffer.allocate(1); buffer.put((byte) (oneByte & 0xFF)); channel.write(buffer); } As you can see the buffer created via allocate & put hence the buffer has no remaining data as expected (remaining() == 0). So there is actually nothing to write. As one of bug fix variants we can make a replace: - buffer.put((byte) (oneByte & 0xFF)); ---- + buffer.put(0, (byte) (oneByte & 0xFF)); Here is a simple demo with respect to this: --- server.java --- import java.net.*; import java.nio.*; import java.nio.channels.*; public class server { public static void main(String args[]) throws Exception { int port = 9999; InetSocketAddress addr = new InetSocketAddress(port); ServerSocketChannel sch = ServerSocketChannel.open(); sch.socket().bind(addr); System.out.println("listening on " + port); SocketChannel ch = sch.accept(); System.out.println("accepted"); try { while (true) { ByteBuffer buf = ByteBuffer.allocate(100); int res = ch.read(buf); if (res == -1) { System.out.println("received eof"); break; } System.out.println("received " + res + " byte(s)"); } } finally { ch.close(); } } } --- client.java --- import java.net.*; import java.io.*; import java.nio.channels.*; public class client { public static void main(String args[]) throws Exception { int port = 9999; InetSocketAddress addr = new InetSocketAddress("localhost", port); SocketChannel ch = SocketChannel.open(addr); Socket socket = ch.socket(); OutputStream os = socket.getOutputStream(); os.write(1); System.out.println("sent 1 byte to " +port); ch.close(); System.out.println("sent eof to " +port); } } --- console1 --- ] ~ ~/jdk150/bin/java server listening on 9999 accepted received eof --- console2 --- ] ~ ~/harmony/bin/java client sent 1 byte to 9999 sent eof to 9999 As you can see from the server's log 1 byte is not received. You can run SUN JDK on client side and compare the outputs. PS As for the summary "cannot write a single byte" - of course this stream CAN write. :) was: java.nio.SocketChannelImpl$SocketChannelOutputStream.write(int) does not actually write a byte. public void write(int oneByte) throws IOException { if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } ByteBuffer buffer = ByteBuffer.allocate(1); buffer.put((byte) (oneByte & 0xFF)); channel.write(buffer); } As you can see the buffer created via allocate & put hence the buffer has no remaining data as expected (remaining() == 0). So there is actually nothing to write. As one of bug fix variants we can make a replace: - buffer.put((byte) (oneByte & 0xFF)); ---- + buffer.put(0, (byte) (oneByte & 0xFF)); Here is a simple demo with respect to this: --- server.java --- import java.net.*; import java.nio.*; import java.nio.channels.*; public class server { public static void main(String args[]) throws Exception { int port = 9999; InetSocketAddress addr = new InetSocketAddress(port); ServerSocketChannel sch = ServerSocketChannel.open(); sch.socket().bind(addr); System.out.println("listening on " + port); SocketChannel ch = sch.accept(); System.out.println("accepted"); try { while (true) { ByteBuffer buf = ByteBuffer.allocate(100); int res = ch.read(buf); if (res == -1) { System.out.println("received eof"); break; } System.out.println("received " + res + " byte(s)"); } } finally { ch.close(); } } } --- client.java --- import java.net.*; import java.io.*; import java.nio.channels.*; public class client { public static void main(String args[]) throws Exception { int port = 9999; InetSocketAddress addr = new InetSocketAddress("localhost", port); SocketChannel ch = SocketChannel.open(addr); Socket socket = ch.socket(); OutputStream os = socket.getOutputStream(); os.write(1); System.out.println("sent 1 byte to " +port); ch.close(); System.out.println("sent eof to " +port); } } --- console1 --- ] ~ ~/jdk150/bin/java server listening on 9999 accepted received eof --- console2 --- ] ~ ~/harmony/bin/java client sent 1 byte to 9999 sent eof to 9999 As you can see from the server's log 1 byte is not received. You can run SUN JDK on client side and compare the outputs. PS As for the summary "cannot write a sibgle byte" - of course this stream CAN write. :) Summary: java.nio.SocketChannel's OutputStream cannot write a single byte (was: java.nio.SocketChannel's OutputStream cannot write a sibgle byte) > java.nio.SocketChannel's OutputStream cannot write a single byte > ---------------------------------------------------------------- > > Key: HARMONY-3475 > URL: https://issues.apache.org/jira/browse/HARMONY-3475 > Project: Harmony > Issue Type: Bug > Components: Classlib > Reporter: Sergey Dmitriev > > java.nio.SocketChannelImpl$SocketChannelOutputStream.write(int) does not actually write a byte. > public void write(int oneByte) throws IOException { > if (!channel.isBlocking()) { > throw new IllegalBlockingModeException(); > } > ByteBuffer buffer = ByteBuffer.allocate(1); > buffer.put((byte) (oneByte & 0xFF)); > channel.write(buffer); > } > As you can see the buffer created via allocate & put hence the buffer has no remaining data as expected (remaining() == 0). So there is actually nothing to write. > As one of bug fix variants we can make a replace: > - buffer.put((byte) (oneByte & 0xFF)); > ---- > + buffer.put(0, (byte) (oneByte & 0xFF)); > Here is a simple demo with respect to this: > --- server.java --- > import java.net.*; > import java.nio.*; > import java.nio.channels.*; > public class server { > public static void main(String args[]) throws Exception { > int port = 9999; > InetSocketAddress addr = new InetSocketAddress(port); > ServerSocketChannel sch = ServerSocketChannel.open(); > sch.socket().bind(addr); > System.out.println("listening on " + port); > SocketChannel ch = sch.accept(); > System.out.println("accepted"); > try { > while (true) { > ByteBuffer buf = ByteBuffer.allocate(100); > int res = ch.read(buf); > if (res == -1) { > System.out.println("received eof"); > break; > } > System.out.println("received " + res + " byte(s)"); > } > } finally { > ch.close(); > } > } > } > --- client.java --- > import java.net.*; > import java.io.*; > import java.nio.channels.*; > public class client { > public static void main(String args[]) throws Exception { > int port = 9999; > InetSocketAddress addr = new InetSocketAddress("localhost", port); > SocketChannel ch = SocketChannel.open(addr); > Socket socket = ch.socket(); > OutputStream os = socket.getOutputStream(); > os.write(1); > System.out.println("sent 1 byte to " +port); > ch.close(); > System.out.println("sent eof to " +port); > } > } > --- console1 --- > ] ~ ~/jdk150/bin/java server > listening on 9999 > accepted > received eof > --- console2 --- > ] ~ ~/harmony/bin/java client > sent 1 byte to 9999 > sent eof to 9999 > As you can see from the server's log 1 byte is not received. You can run SUN JDK on client side and compare the outputs. > PS As for the summary "cannot write a single byte" - of course this stream CAN write. :) -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.