Made sure channel registration doesn't fail in Windows unexpectedly
This commit is contained in:
parent
42afa85e53
commit
2d8b3b0a4e
@ -84,11 +84,21 @@ class NioSocketChannel extends AbstractChannel
|
||||
}
|
||||
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return (InetSocketAddress) socket.socket().getLocalSocketAddress();
|
||||
try {
|
||||
return (InetSocketAddress) socket.socket().getLocalSocketAddress();
|
||||
} catch (Throwable t) {
|
||||
// Sometimes fails on a closed socket in Windows.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return (InetSocketAddress) socket.socket().getRemoteSocketAddress();
|
||||
try {
|
||||
return (InetSocketAddress) socket.socket().getRemoteSocketAddress();
|
||||
} catch (Throwable t) {
|
||||
// Sometimes fails on a closed socket in Windows.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
|
@ -25,6 +25,7 @@ package org.jboss.netty.channel.socket.nio;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.AsynchronousCloseException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
@ -628,6 +629,15 @@ class NioWorker implements Runnable {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
SocketAddress localAddress = channel.getLocalAddress();
|
||||
SocketAddress remoteAddress = channel.getRemoteAddress();
|
||||
if (localAddress == null || remoteAddress == null) {
|
||||
if (future != null) {
|
||||
future.setFailure(new ClosedChannelException());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
channel.socket.register(selector, SelectionKey.OP_READ, channel);
|
||||
if (future != null) {
|
||||
@ -641,11 +651,11 @@ class NioWorker implements Runnable {
|
||||
|
||||
if (server) {
|
||||
fireChannelOpen(channel);
|
||||
fireChannelBound(channel, channel.getLocalAddress());
|
||||
fireChannelBound(channel, localAddress);
|
||||
} else if (!((NioClientSocketChannel) channel).boundManually) {
|
||||
fireChannelBound(channel, channel.getLocalAddress());
|
||||
fireChannelBound(channel, localAddress);
|
||||
}
|
||||
fireChannelConnected(channel, channel.getRemoteAddress());
|
||||
fireChannelConnected(channel, remoteAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user