Browse Source

Merge pull request #661 from normanmaurer/netty_upgrade

Set higher backlog and not make an unecessary byte copy when handling js...
Mike Smith 11 years ago
parent
commit
6f78439dbb

+ 1 - 1
netty/src/main/java/hello/HelloServerHandler.java

@@ -51,7 +51,7 @@ public class HelloServerHandler extends SimpleChannelInboundHandler<Object> {
                     return;
                     return;
                 case "/json":
                 case "/json":
                     byte[] json = MAPPER.writeValueAsBytes(Collections.singletonMap("message", "Hello, World!"));
                     byte[] json = MAPPER.writeValueAsBytes(Collections.singletonMap("message", "Hello, World!"));
-                    writeResponse(ctx, request, ctx.alloc().buffer(json.length).writeBytes(json), TYPE_JSON,
+                    writeResponse(ctx, request, Unpooled.wrappedBuffer(json), TYPE_JSON,
                             String.valueOf(json.length));
                             String.valueOf(json.length));
                     return;
                     return;
             }
             }

+ 1 - 0
netty/src/main/java/hello/HelloWebServer.java

@@ -29,6 +29,7 @@ public class HelloWebServer {
             b.group(group)
             b.group(group)
              .childHandler(new HelloServerInitializer())
              .childHandler(new HelloServerInitializer())
              .channel(NioServerSocketChannel.class)
              .channel(NioServerSocketChannel.class)
+             .option(ChannelOption.SO_BACKLOG, 1024)
              .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
              .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
              
              
             Channel ch = b.bind(port).sync().channel();
             Channel ch = b.bind(port).sync().channel();