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
protected ChannelBootstrap newClientBootstrap() {
ChannelBootstrap b = new ChannelBootstrap();
b.eventLoop(new SelectorEventLoop());
b.channel(new NioSocketChannel());
return b;
return new ChannelBootstrap()
.eventLoop(new SelectorEventLoop())
.channel(new NioSocketChannel());
}
@Override
protected ServerChannelBootstrap newServerBootstrap() {
ServerChannelBootstrap b = new ServerChannelBootstrap();
b.eventLoop(new SelectorEventLoop(), new SelectorEventLoop());
b.channel(new NioServerSocketChannel());
return b;
return new ServerChannelBootstrap()
.eventLoop(new SelectorEventLoop(), new SelectorEventLoop())
.channel(new NioServerSocketChannel());
}
}

View File

@ -16,20 +16,26 @@
package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap;
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 {
@Override
protected ChannelFactory newClientBootstrap() {
return new NioClientSocketChannelFactory(executor);
protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap()
.eventLoop(new SelectorEventLoop())
.channel(new NioSocketChannel());
}
@Override
protected ChannelFactory newServerBootstrap() {
return new OioServerSocketChannelFactory(executor, executor);
protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop())
.channel(new OioServerSocketChannel());
}
}

View File

@ -16,20 +16,26 @@
package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap;
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 {
@Override
protected ChannelFactory newClientBootstrap() {
return new OioClientSocketChannelFactory(executor);
protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop())
.channel(new OioSocketChannel());
}
@Override
protected ChannelFactory newServerBootstrap() {
return new NioServerSocketChannelFactory(executor);
protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap()
.eventLoop(new SelectorEventLoop(), new SelectorEventLoop())
.channel(new NioServerSocketChannel());
}
}

View File

@ -16,20 +16,25 @@
package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.oio.OioClientSocketChannelFactory;
import io.netty.channel.socket.oio.OioServerSocketChannelFactory;
import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap;
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 {
@Override
protected ChannelFactory newClientBootstrap() {
return new OioClientSocketChannelFactory(executor);
protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop())
.channel(new OioSocketChannel());
}
@Override
protected ChannelFactory newServerBootstrap() {
return new OioServerSocketChannelFactory(executor, executor);
protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop())
.channel(new OioServerSocketChannel());
}
}

View File

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

View File

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