2 problem about udp

lyl luyanliang01 at 163.com
Thu Jun 3 11:00:14 EDT 2010


Hi Trustin Lee,

I meet 2 problems about netty udp:

1) About OIO udp. Thread can be blocked for seconds after creating dozens of
channels. But NIO doesn't have this problem. The test code is as below:

ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(new
OioDatagramChannelFactory(Executors.newCachedThreadPool()));
		
  // After creating some channels, the thread is paused for some seconds,
very strange...
  for (int i = 0; i < 500; i++) {
			
  DatagramChannel channel = (DatagramChannel)bootstrap.bind(new
InetSocketAddress(0));
			
  channel.connect(new InetSocketAddress("10.72.4.94", 5000));
			
  System.out.println(i);
  }
		


2) Also about udp, but is NIO mode. I tried to send empty data with udp,
which lead to OIO work thread dead loop. The test code is as below:

ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(new
NioDatagramChannelFactory(Executors
				.newCachedThreadPool()));
  DatagramChannel channel = (DatagramChannel) bootstrap.bind(new
InetSocketAddress(0));

  byte[] bytes = new byte[0];

  ChannelBuffer channelBuffer = ChannelBuffers.wrappedBuffer(bytes);
  
  channel.write(channelBuffer, new InetSocketAddress("192.168.0.190",
8000)).awaitUninterruptibly();

  // The program can not execute to here...

  System.out.println("ok");



  After simple debug, I found the dead loop lies here: 
  
  NioDatagramWork(line:533)
  ...
      for (int i = writeSpinCount; i > 0; i --) {
             localWrittenBytes = buf.transferTo(ch);
             if (localWrittenBytes != 0) {
                  writtenBytes += localWrittenBytes;
                  break;
             }
      }
 ...
 Because the data length is 0, so the "localWrittenBytes != 0" would never
meet. Is the problem here?


Above is the problem I meet, any reply is appreciated. 

Best regards!

Lu Yanliang

-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/2-problem-about-udp-tp5135490p5135490.html
Sent from the Netty User Group mailing list archive at Nabble.com.



More information about the netty-users mailing list