2013-06-29 2 views
1

클라이언트가 대용량 파일을 보낼 때 netty가 생성하는 인바운드 버퍼의 크기를 제한하려면 어떻게합니까? ByteBuf가 가득 차면 더 많은 데이터를받을 준비가되면 클라이언트가 네트워크를 통해 데이터 전송을 중단하길 원합니다. 여기 netty에서 인바운드 버퍼의 크기 제한 4 cr6

내 처리기 코드 :

이제 디버거에서 내가 버퍼 크기가 계산되는 라인에 도착하면
EmbeddedChannel ch = new EmbeddedChannel(new MyDecoder()); 
ch.writeInbound(Unpooled.wrappedBuffer(<<<here is a byte representation of a large file, say 100 mb>>>)); 
ch.readInbound(); // etc... 

, 난 항상 얻을 :

public class MyDecoder extends ChannelInboundHandlerAdapter { 

@Override 
public void handlerAdded(ChannelHandlerContext ctx) throws Exception { 
    // limit the size of recieving buffer to 1024 
    ctx.channel().config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(1024)); 
    } 

@Override public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception { 
    ByteBuf byteBuf = msgs.<ByteBuf>cast().get(0); 
    // stop after this line in debugger to check size of the actual payload per messageReceived invocation 
    int bufferSize = byteBuf.readableBytes(); 
    } 
} 

지금 내 테스트에서 내가 작성한다고 가정 내 큰 파일의 전체 크기. 그 시점에서 FixedRecvByteBufAllocator의 유일한 차이점은 크기가 0으로 설정된 경우입니다. 다른 모든 값은 동일한 결과를 나타냅니다.

netty 4 cr2에는 newInboundBuffer 목적을 달성하는 방법이 있지만 cr6 이후에는 그러한 구성이 없습니다.

답변

1

FixedRecvByteBufAllocator는 버퍼를 최대 1024 바이트로 제한해야합니다. 버그가 아닌 경우.