harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Zhang" <zhanghuang...@gmail.com>
Subject RI's bug of Socket.getOutputStream().write(byte[]) ?
Date Fri, 23 Jun 2006 06:47:01 GMT
Hi everybody,

It seems RI Socket.getOutputStream().write(byte[])  doesn't send all data
sometimes. Consider following test, which often blocks on RI:

    public void test_SocketChannel_BlockWriteRead() throws IOException {
        final int CAPACITY_NORMAL = 200;
        InetSocketAddress localAddr1 = new InetSocketAddress("127.0.0.1
",1234);
        ServerSocket server = new ServerSocket(1234);

        SocketChannel channel = SocketChannel.open();
        channel.connect(localAddr1);
        Socket serverSocket = server.accept();

        OutputStream out = serverSocket.getOutputStream();
        byte[] sendBuf = new byte[CAPACITY_NORMAL * 2];
        for (int i = 0; i < CAPACITY_NORMAL * 2; i++) {
            sendBuf[i] = (byte) i;
        }
        // send CAPACITY_NORMAL * 2 bytes data
        out.write(sendBuf);
        out.flush();

        ByteBuffer buf1 = ByteBuffer.allocate(CAPACITY_NORMAL);
        ByteBuffer buf2 = ByteBuffer.allocate(CAPACITY_NORMAL);
        ByteBuffer[] buf ={buf1, buf2};

        // should receive CAPACITY_NORMAL * 2 bytes data
        // RI often hangs here, with CAPACITY_NORMAL bytes data received.
        long count = 0;
        do{
            count += channel.read(buf);
        }while(count < CAPACITY_NORMAL*2);
        assertEquals(CAPACITY_NORMAL * 2, count);
    }

I think it's a bug of RI. Am I missing something? Please correct me if I'm
wrong. There're also some similar tests in NIO module with FIXME mark.

If it's a bug of RI, I'll raise a JIRA to tidy up those "FIXME" in NIO.

Thanks!

Best regards,

-- 
Andrew Zhang
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message