Problem with SelectionKey OP_CONNECT

Bryce McKinlay mckinlay@redhat.com
Mon Sep 27 14:44:00 GMT 2004


Stanley Brown wrote:
> Hello,
>> I have noticed a difference between gcj and Sun's implementation of 
> NIO socket channels. GCJ is not setting the readyOps when a socket is 
> connectable. I wrote an example program to illustrate the problem:

Hi Stanley,
Could you post a bug report with this test case at gcc.gnu.org/bugzilla? 
Also, please post a context diff (-c or -u) with the bug report, as the 
patch you posted is difficult to read.
Thanks
Bryce
> -------------------------
> import java.net.InetSocketAddress;
> import java.nio.channels.*;
> import java.util.Iterator;
>> public class TestConnect
> {
> public TestConnect()
> {
> try
> {
> Selector selector = Selector.open();
> SocketChannel channel = SocketChannel.open();
> channel.configureBlocking(false);
> channel.connect(new InetSocketAddress("gcc.gnu.org", 80));
> channel.register(selector, SelectionKey.OP_CONNECT);
> while (true)
> {
> selector.select();
> Iterator it = selector.selectedKeys().iterator();
> while (it.hasNext())
> {
> SelectionKey selKey = (SelectionKey)it.next();
> if (selKey.isConnectable())
> {
> System.out.println("Connection ready");
> System.exit(0);
> }
> }
> }
> }
> catch (Exception ex)
> {
> ex.printStackTrace();
> }
> }
> public static void main(String[] args)
> {
> new TestConnect();
> }
> }



More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /