From 87a6a68059f27b3118d56f76f0d98621f4a618be Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 12 Sep 2013 09:27:43 +0200 Subject: [PATCH] [#1830] Add testcase for write to not bound DatagramChannel impls and revert change in OIO as it breaks things as the udnerlying socket lazy binds --- .../transport/socket/DatagramUnicastTest.java | 33 +++++++++++++++++++ .../socket/oio/OioDatagramChannel.java | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java index fab3d6e211..4aea9cf37a 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java @@ -62,4 +62,37 @@ public class DatagramUnicastTest extends AbstractDatagramTest { sc.close().sync(); cc.close().sync(); } + + @Test + public void testSimpleSendWithoutBind() throws Throwable { + //run(); + } + + public void testSimpleSendWithoutBind(Bootstrap sb, Bootstrap cb) throws Throwable { + final CountDownLatch latch = new CountDownLatch(1); + + sb.handler(new SimpleChannelInboundHandler() { + @Override + public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { + assertEquals(1, msg.content().readInt()); + latch.countDown(); + } + }); + + cb.handler(new SimpleChannelInboundHandler() { + @Override + public void channelRead0(ChannelHandlerContext ctx, Object msgs) throws Exception { + // Nothing will be sent. + } + }); + + Channel sc = sb.bind().sync().channel(); + Channel cc = cb.register().sync().channel(); + + cc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), addr)).sync(); + assertTrue(latch.await(10, TimeUnit.SECONDS)); + + sc.close().sync(); + cc.close().sync(); + } } diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java index 8d3aa1693d..1c9d3ec3bc 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java @@ -125,7 +125,7 @@ public class OioDatagramChannel extends AbstractOioMessageChannel @Override public boolean isActive() { - return isOpen(); + return isOpen() && socket.isBound(); } @Override