Fix a bug in shutdownOutput() implementations where wrong ChannelFuture is notified
This commit is contained in:
parent
68e86d8667
commit
a1e8dad4ad
@ -57,7 +57,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
|
||||
assertFalse(h.ch.isOutputShutdown());
|
||||
|
||||
// Make the connection half-closed and ensure read() returns -1.
|
||||
ch.shutdownOutput();
|
||||
ch.shutdownOutput().sync();
|
||||
assertEquals(-1, s.getInputStream().read());
|
||||
|
||||
assertTrue(h.ch.isOpen());
|
||||
|
@ -110,27 +110,31 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
||||
|
||||
@Override
|
||||
public ChannelFuture shutdownOutput() {
|
||||
ChannelFuture future = newFuture();
|
||||
final ChannelFuture future = newFuture();
|
||||
EventLoop loop = eventLoop();
|
||||
if (loop.inEventLoop()) {
|
||||
try {
|
||||
javaChannel().shutdownOutput();
|
||||
outputShutdown = true;
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
}
|
||||
shutdownOutput(future);
|
||||
} else {
|
||||
loop.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
shutdownOutput();
|
||||
shutdownOutput(future);
|
||||
}
|
||||
});
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
private void shutdownOutput(ChannelFuture future) {
|
||||
try {
|
||||
javaChannel().shutdownOutput();
|
||||
outputShutdown = true;
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress, final ChannelFuture future) {
|
||||
if (localAddress != null) {
|
||||
|
@ -110,26 +110,30 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
||||
|
||||
@Override
|
||||
public ChannelFuture shutdownOutput() {
|
||||
ChannelFuture future = newFuture();
|
||||
final ChannelFuture future = newFuture();
|
||||
EventLoop loop = eventLoop();
|
||||
if (loop.inEventLoop()) {
|
||||
try {
|
||||
javaChannel().socket().shutdownOutput();
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
}
|
||||
shutdownOutput(future);
|
||||
} else {
|
||||
loop.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
shutdownOutput();
|
||||
shutdownOutput(future);
|
||||
}
|
||||
});
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
private void shutdownOutput(ChannelFuture future) {
|
||||
try {
|
||||
javaChannel().socket().shutdownOutput();
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress localAddress0() {
|
||||
return javaChannel().socket().getLocalSocketAddress();
|
||||
|
@ -115,26 +115,30 @@ public class OioSocketChannel extends AbstractOioByteChannel
|
||||
|
||||
@Override
|
||||
public ChannelFuture shutdownOutput() {
|
||||
ChannelFuture future = newFuture();
|
||||
final ChannelFuture future = newFuture();
|
||||
EventLoop loop = eventLoop();
|
||||
if (loop.inEventLoop()) {
|
||||
try {
|
||||
socket.shutdownOutput();
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
}
|
||||
shutdownOutput(future);
|
||||
} else {
|
||||
loop.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
shutdownOutput();
|
||||
shutdownOutput(future);
|
||||
}
|
||||
});
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
private void shutdownOutput(ChannelFuture future) {
|
||||
try {
|
||||
socket.shutdownOutput();
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress localAddress0() {
|
||||
return socket.getLocalSocketAddress();
|
||||
|
Loading…
Reference in New Issue
Block a user