harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: RI's bug of Socket.getOutputStream().write(byte[]) ?
Date Fri, 23 Jun 2006 08:31:04 GMT
Andrew,

There is no guarantee that the out.flush() will actually send the bytes
(it will just ensure that they get from Java to the OS).  Indeed, there
is no guaranteed way to force the TCP stack to send the bytes; but you
can try by reducing the socket send buffer size (SO_SNDBUF) and setting
no delay on (TCP_NODELAY).  The best bet is to close the output stream
socket when you have finished writing, and read until you get a -1 on
the client.

Regards,
Tim

Andrew Zhang wrote:
> 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,
> 

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message