Fix a bug in shutdownOutput() implementations where wrong ChannelFuture is notified

This commit is contained in:
Trustin Lee 2012-08-30 16:38:08 +09:00
parent 68e86d8667
commit a1e8dad4ad
4 changed files with 38 additions and 26 deletions

View File

@ -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());

View File

@ -110,9 +110,22 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
@Override
public ChannelFuture shutdownOutput() {
ChannelFuture future = newFuture();
final ChannelFuture future = newFuture();
EventLoop loop = eventLoop();
if (loop.inEventLoop()) {
shutdownOutput(future);
} else {
loop.execute(new Runnable() {
@Override
public void run() {
shutdownOutput(future);
}
});
}
return future;
}
private void shutdownOutput(ChannelFuture future) {
try {
javaChannel().shutdownOutput();
outputShutdown = true;
@ -120,15 +133,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
} catch (Throwable t) {
future.setFailure(t);
}
} else {
loop.execute(new Runnable() {
@Override
public void run() {
shutdownOutput();
}
});
}
return future;
}
@Override

View File

@ -110,24 +110,28 @@ 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()) {
shutdownOutput(future);
} else {
loop.execute(new Runnable() {
@Override
public void run() {
shutdownOutput(future);
}
});
}
return future;
}
private void shutdownOutput(ChannelFuture future) {
try {
javaChannel().socket().shutdownOutput();
future.setSuccess();
} catch (Throwable t) {
future.setFailure(t);
}
} else {
loop.execute(new Runnable() {
@Override
public void run() {
shutdownOutput();
}
});
}
return future;
}
@Override

View File

@ -115,24 +115,28 @@ public class OioSocketChannel extends AbstractOioByteChannel
@Override
public ChannelFuture shutdownOutput() {
ChannelFuture future = newFuture();
final ChannelFuture future = newFuture();
EventLoop loop = eventLoop();
if (loop.inEventLoop()) {
shutdownOutput(future);
} else {
loop.execute(new Runnable() {
@Override
public void run() {
shutdownOutput(future);
}
});
}
return future;
}
private void shutdownOutput(ChannelFuture future) {
try {
socket.shutdownOutput();
future.setSuccess();
} catch (Throwable t) {
future.setFailure(t);
}
} else {
loop.execute(new Runnable() {
@Override
public void run() {
shutdownOutput();
}
});
}
return future;
}
@Override