Search in sources :

Example 1 with UdtMessage

use of io.netty.channel.udt.UdtMessage in project netty by netty.

the class NioUdtMessageConnectorChannel method doReadMessages.

@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    final int maximumMessageSize = config.getReceiveBufferSize();
    final ByteBuf byteBuf = config.getAllocator().directBuffer(maximumMessageSize);
    final int receivedMessageSize = byteBuf.writeBytes(javaChannel(), maximumMessageSize);
    if (receivedMessageSize <= 0) {
        byteBuf.release();
        return 0;
    }
    if (receivedMessageSize >= maximumMessageSize) {
        javaChannel().close();
        throw new ChannelException("Invalid config : increase receive buffer size to avoid message truncation");
    }
    // delivers a message
    buf.add(new UdtMessage(byteBuf));
    return 1;
}
Also used : UdtMessage(io.netty.channel.udt.UdtMessage) ByteBuf(io.netty.buffer.ByteBuf) ChannelException(io.netty.channel.ChannelException)

Example 2 with UdtMessage

use of io.netty.channel.udt.UdtMessage in project netty by netty.

the class NioUdtMessageConnectorChannel method doWriteMessage.

@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
    // expects a message
    final UdtMessage message = (UdtMessage) msg;
    final ByteBuf byteBuf = message.content();
    final int messageSize = byteBuf.readableBytes();
    if (messageSize == 0) {
        return true;
    }
    final long writtenBytes;
    if (byteBuf.nioBufferCount() == 1) {
        writtenBytes = javaChannel().write(byteBuf.nioBuffer());
    } else {
        writtenBytes = javaChannel().write(byteBuf.nioBuffers());
    }
    // wrote message completely
    if (writtenBytes > 0 && writtenBytes != messageSize) {
        throw new Error("Provider error: failed to write message. Provider library should be upgraded.");
    }
    return writtenBytes > 0;
}
Also used : UdtMessage(io.netty.channel.udt.UdtMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with UdtMessage

use of io.netty.channel.udt.UdtMessage in project netty by netty.

the class EchoMessageHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    UdtMessage udtMsg = (UdtMessage) msg;
    if (meter != null) {
        meter.mark(udtMsg.content().readableBytes());
    }
    ctx.writeAndFlush(msg);
}
Also used : UdtMessage(io.netty.channel.udt.UdtMessage)

Aggregations

UdtMessage (io.netty.channel.udt.UdtMessage)3 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelException (io.netty.channel.ChannelException)1