Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ByteBuf initial capacity size

Tags:

java

netty

Please give me advice how to increase my ByteBuf initial capacity.
In situation like:

 @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws  Exception {

    byte[] byteinput = new byte[in.readableBytes()]; 
    in.readBytes(byteinput);  

//further handling...
}

If income message more than max capacity of ByteBuf - i get cutted data. Its vital for this project to get whole, non chunked message.

I suppose i need to set initial capacity of ByteBuf somewhere in bootstraps childOptions, or in cannel.config()... inside of ChannelInitializer.
And i tried different ways like setting

ch.config().setReceiveBufferSize(1024)

but i still have same value of ByteBuf capacity(e.g. 496).

UPD

I discovered my protocol traffic with wireshark, and packets up to 1,4k going uncorrupted out and in from my test user client. This issue is only matter of netty settings. Operating system socket buffer do not cuts messages.

like image 655
Asprelis Avatar asked Oct 23 '25 19:10

Asprelis


1 Answers

That was easy as pie.

ServerBootstrap b = new ServerBootstrap(); // (2)
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class) // (3)
                .childHandler(new ChannelInitializer<SocketChannel>() { // (4)
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {

                        //decrypt  //checknum

                        ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(2048)); //set  buf size here
                         ch.pipeline().addLast(new InboundDecryptor());
 .
 .
 .
like image 120
Asprelis Avatar answered Oct 26 '25 08:10

Asprelis