Make sure the ChannelOpen, ChannelBound and ChannelConnected events get
fired from within an IO-Worker Thread. This makes sure the Boss-Thread will not get blocked by any user action
This commit is contained in:
parent
28120aa778
commit
bbdc2032f0
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
@ -46,8 +44,5 @@ final class NioAcceptedSocketChannel extends NioSocketChannel {
|
||||
this.bossThread = bossThread;
|
||||
|
||||
setConnected();
|
||||
fireChannelOpen(this);
|
||||
fireChannelBound(this, getLocalAddress());
|
||||
fireChannelConnected(this, getRemoteAddress());
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ class NioWorker implements Runnable {
|
||||
|
||||
private final SocketReceiveBufferPool recvBufferPool = new SocketReceiveBufferPool();
|
||||
private final SocketSendBufferPool sendBufferPool = new SocketSendBufferPool();
|
||||
private final AtomicBoolean fireConnect = new AtomicBoolean(true);
|
||||
|
||||
NioWorker(int bossId, int id, Executor executor) {
|
||||
this.bossId = bossId;
|
||||
@ -96,6 +97,8 @@ class NioWorker implements Runnable {
|
||||
Selector selector;
|
||||
|
||||
synchronized (startStopLock) {
|
||||
fireConnect.set(true);
|
||||
|
||||
if (!started) {
|
||||
// Open a selector if this worker didn't start yet.
|
||||
try {
|
||||
@ -160,6 +163,7 @@ class NioWorker implements Runnable {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
SelectorUtil.select(selector);
|
||||
|
||||
// 'wakenUp.compareAndSet(false, true)' is always evaluated
|
||||
@ -790,6 +794,14 @@ class NioWorker implements Runnable {
|
||||
}
|
||||
fireChannelConnected(channel, remoteAddress);
|
||||
}
|
||||
|
||||
// Handle the channelOpen, channelBound and channelConnected in the worker thread
|
||||
if (channel instanceof NioAcceptedSocketChannel) {
|
||||
fireChannelOpen(channel);
|
||||
fireChannelBound(channel, channel.getLocalAddress());
|
||||
fireChannelConnected(channel, channel.getRemoteAddress());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.oio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
@ -60,10 +58,6 @@ class OioAcceptedSocketChannel extends OioSocketChannel {
|
||||
} catch (IOException e) {
|
||||
throw new ChannelException("Failed to obtain an OutputStream.", e);
|
||||
}
|
||||
|
||||
fireChannelOpen(this);
|
||||
fireChannelBound(this, getLocalAddress());
|
||||
fireChannelConnected(this, getRemoteAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,15 @@ class OioWorker implements Runnable {
|
||||
channel.workerThread = Thread.currentThread();
|
||||
final PushbackInputStream in = channel.getInputStream();
|
||||
|
||||
boolean fireOpen = channel instanceof OioAcceptedSocketChannel;
|
||||
|
||||
while (channel.isOpen()) {
|
||||
if (fireOpen) {
|
||||
fireOpen = false;
|
||||
fireChannelOpen(channel);
|
||||
fireChannelBound(channel, channel.getLocalAddress());
|
||||
fireChannelConnected(channel, channel.getRemoteAddress());
|
||||
}
|
||||
synchronized (channel.interestOpsLock) {
|
||||
while (!channel.isReadable()) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user