Fixed all SPDY echo tests / Handle closed old I/O channels correctly

This commit is contained in:
Trustin Lee 2012-05-25 14:24:25 -07:00
parent 01aa1647bb
commit f60f918763
6 changed files with 54 additions and 33 deletions

View File

@ -26,18 +26,15 @@ public class NioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelBootstrap newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
ChannelBootstrap b = new ChannelBootstrap(); return new ChannelBootstrap()
b.eventLoop(new SelectorEventLoop()); .eventLoop(new SelectorEventLoop())
b.channel(new NioSocketChannel()); .channel(new NioSocketChannel());
return b;
} }
@Override @Override
protected ServerChannelBootstrap newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
ServerChannelBootstrap b = new ServerChannelBootstrap(); return new ServerChannelBootstrap()
b.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()); .eventLoop(new SelectorEventLoop(), new SelectorEventLoop())
b.channel(new NioServerSocketChannel()); .channel(new NioServerSocketChannel());
return b;
} }
} }

View File

@ -16,20 +16,26 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelFactory; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.channel.socket.nio.SelectorEventLoop;
import io.netty.channel.socket.oio.BlockingChannelEventLoop;
import io.netty.channel.socket.oio.OioServerSocketChannel;
public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelFactory newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new NioClientSocketChannelFactory(executor); return new ChannelBootstrap()
.eventLoop(new SelectorEventLoop())
.channel(new NioSocketChannel());
} }
@Override @Override
protected ChannelFactory newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new OioServerSocketChannelFactory(executor, executor); return new ServerChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop())
.channel(new OioServerSocketChannel());
} }
} }

View File

@ -16,20 +16,26 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelFactory; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.SelectorEventLoop;
import io.netty.channel.socket.oio.BlockingChannelEventLoop;
import io.netty.channel.socket.oio.OioSocketChannel;
public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelFactory newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new OioClientSocketChannelFactory(executor); return new ChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop())
.channel(new OioSocketChannel());
} }
@Override @Override
protected ChannelFactory newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new NioServerSocketChannelFactory(executor); return new ServerChannelBootstrap()
.eventLoop(new SelectorEventLoop(), new SelectorEventLoop())
.channel(new NioServerSocketChannel());
} }
} }

View File

@ -16,20 +16,25 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelFactory; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory; import io.netty.channel.socket.oio.BlockingChannelEventLoop;
import io.netty.channel.socket.oio.OioServerSocketChannel;
import io.netty.channel.socket.oio.OioSocketChannel;
public class OioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { public class OioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelFactory newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new OioClientSocketChannelFactory(executor); return new ChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop())
.channel(new OioSocketChannel());
} }
@Override @Override
protected ChannelFactory newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new OioServerSocketChannelFactory(executor, executor); return new ServerChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop())
.channel(new OioServerSocketChannel());
} }
} }

View File

@ -153,6 +153,10 @@ public class OioServerSocketChannel extends AbstractServerChannel
@Override @Override
protected int doRead(Queue<Object> buf) throws Exception { protected int doRead(Queue<Object> buf) throws Exception {
if (socket.isClosed()) {
return -1;
}
Socket s = null; Socket s = null;
try { try {
s = socket.accept(); s = socket.accept();

View File

@ -193,6 +193,9 @@ public class OioSocketChannel extends AbstractChannel
@Override @Override
protected int doRead(ChannelBuffer buf) throws Exception { protected int doRead(ChannelBuffer buf) throws Exception {
if (socket.isClosed()) {
return -1;
}
try { try {
int readBytes = buf.writeBytes(is, buf.writableBytes()); int readBytes = buf.writeBytes(is, buf.writableBytes());
return readBytes; return readBytes;