Java Code Examples for io.netty.channel.ChannelOutboundBuffer#forEachFlushedMessage()

The following examples show how to use io.netty.channel.ChannelOutboundBuffer#forEachFlushedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractKQueueStreamChannel.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to write multiple {@link ByteBuf} objects.
 * @param in the collection which contains objects to write.
 * @return The value that should be decremented from the write quantum which starts at
 * {@link ChannelConfig#getWriteSpinCount()}. The typical use cases are as follows:
 * <ul>
 *     <li>0 - if no write was attempted. This is appropriate if an empty {@link ByteBuf} (or other empty content)
 *     is encountered</li>
 *     <li>1 - if a single call to write data was made to the OS</li>
 *     <li>{@link ChannelUtils#WRITE_STATUS_SNDBUF_FULL} - if an attempt to write data was made to the OS, but no
 *     data was accepted</li>
 * </ul>
 * @throws Exception If an I/O error occurs.
 */
private int doWriteMultiple(ChannelOutboundBuffer in) throws Exception {
    final long maxBytesPerGatheringWrite = config().getMaxBytesPerGatheringWrite();
    if (PlatformDependent.hasUnsafe()) {
        IovArray array = ((KQueueEventLoop) eventLoop()).cleanArray();
        array.maxBytes(maxBytesPerGatheringWrite);
        in.forEachFlushedMessage(array);

        if (array.count() >= 1) {
            // TODO: Handle the case where cnt == 1 specially.
            return writeBytesMultiple(in, array);
        }
    } else {
        ByteBuffer[] buffers = in.nioBuffers();
        int cnt = in.nioBufferCount();
        if (cnt >= 1) {
            // TODO: Handle the case where cnt == 1 specially.
            return writeBytesMultiple(in, buffers, cnt, in.nioBufferSize(), maxBytesPerGatheringWrite);
        }
    }
    // cnt == 0, which means the outbound buffer contained empty buffers only.
    in.removeBytes(0);
    return 0;
}
 
Example 2
Source File: AbstractEpollStreamChannel.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to write multiple {@link ByteBuf} objects.
 * @param in the collection which contains objects to write.
 * @return The value that should be decremented from the write quantum which starts at
 * {@link ChannelConfig#getWriteSpinCount()}. The typical use cases are as follows:
 * <ul>
 *     <li>0 - if no write was attempted. This is appropriate if an empty {@link ByteBuf} (or other empty content)
 *     is encountered</li>
 *     <li>1 - if a single call to write data was made to the OS</li>
 *     <li>{@link ChannelUtils#WRITE_STATUS_SNDBUF_FULL} - if an attempt to write data was made to the OS, but
 *     no data was accepted</li>
 * </ul>
 * @throws Exception If an I/O error occurs.
 */
private int doWriteMultiple(ChannelOutboundBuffer in) throws Exception {
    final long maxBytesPerGatheringWrite = config().getMaxBytesPerGatheringWrite();
    if (PlatformDependent.hasUnsafe()) {
        IovArray array = ((EpollEventLoop) eventLoop()).cleanArray();
        array.maxBytes(maxBytesPerGatheringWrite);
        in.forEachFlushedMessage(array);

        if (array.count() >= 1) {
            // TODO: Handle the case where cnt == 1 specially.
            return writeBytesMultiple(in, array);
        }
    } else {
        ByteBuffer[] buffers = in.nioBuffers();
        int cnt = in.nioBufferCount();
        if (cnt >= 1) {
            // TODO: Handle the case where cnt == 1 specially.
            return writeBytesMultiple(in, buffers, cnt, in.nioBufferSize(), maxBytesPerGatheringWrite);
        }
    }
    // cnt == 0, which means the outbound buffer contained empty buffers only.
    in.removeBytes(0);
    return 0;
}
 
Example 3
Source File: NativeDatagramPacketArray.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link NativeDatagramPacketArray} which is filled with the flushed messages of
 * {@link ChannelOutboundBuffer}.
 */
static NativeDatagramPacketArray getInstance(ChannelOutboundBuffer buffer) throws Exception {
    NativeDatagramPacketArray array = ARRAY.get();
    array.count = 0;
    buffer.forEachFlushedMessage(array);
    return array;
}
 
Example 4
Source File: NativeDatagramPacketArray.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link NativeDatagramPacketArray} which is filled with the flushed messages of
 * {@link ChannelOutboundBuffer}.
 */
static NativeDatagramPacketArray getInstance(ChannelOutboundBuffer buffer) throws Exception {
    NativeDatagramPacketArray array = ARRAY.get();
    array.count = 0;
    buffer.forEachFlushedMessage(array);
    return array;
}
 
Example 5
Source File: IovArrayThreadLocal.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link IovArray} which is filled with the flushed messages of {@link ChannelOutboundBuffer}.
 */
static IovArray get(ChannelOutboundBuffer buffer) throws Exception {
    IovArray array = ARRAY.get();
    array.clear();
    buffer.forEachFlushedMessage(array);
    return array;
}