diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java index fab9c72212..1bc1f1e051 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioWorker.java @@ -887,7 +887,7 @@ abstract class AbstractNioWorker implements Worker { } } - private void cleanUpWriteBuffer(AbstractNioChannel channel) { + protected void cleanUpWriteBuffer(AbstractNioChannel channel) { Exception cause = null; boolean fireExceptionCaught = false; diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramWorker.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramWorker.java index 5eb8c458fc..1806cc749e 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramWorker.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramWorker.java @@ -159,5 +159,35 @@ public class NioDatagramWorker extends AbstractNioWorker { } } + @Override + public void writeFromUserCode(final AbstractNioChannel channel) { + /* + * Note that we are not checking if the channel is connected. Connected + * has a different meaning in UDP and means that the channels socket is + * configured to only send and receive from a given remote peer. + */ + if (!channel.isBound()) { + cleanUpWriteBuffer(channel); + return; + } + + if (scheduleWriteIfNecessary(channel)) { + return; + } + + // From here, we are sure Thread.currentThread() == workerThread. + + if (channel.writeSuspended) { + return; + } + + if (channel.inWriteNowLoop) { + return; + } + + write0(channel); + } + + }