// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.channel.kqueue;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.UncheckedBooleanSupplier;
import io.netty.channel.unix.PreferredDirectByteBufAllocator;
import io.netty.channel.RecvByteBufAllocator;

final class KQueueRecvByteAllocatorHandle extends RecvByteBufAllocator.DelegatingHandle implements RecvByteBufAllocator.ExtendedHandle
{
    private final PreferredDirectByteBufAllocator preferredDirectByteBufAllocator;
    private final UncheckedBooleanSupplier defaultMaybeMoreDataSupplier;
    private boolean readEOF;
    private long numberBytesPending;
    
    KQueueRecvByteAllocatorHandle(final RecvByteBufAllocator.ExtendedHandle handle) {
        super(handle);
        this.preferredDirectByteBufAllocator = new PreferredDirectByteBufAllocator();
        this.defaultMaybeMoreDataSupplier = new UncheckedBooleanSupplier() {
            @Override
            public boolean get() {
                return KQueueRecvByteAllocatorHandle.this.maybeMoreDataToRead();
            }
        };
    }
    
    @Override
    public ByteBuf allocate(final ByteBufAllocator alloc) {
        this.preferredDirectByteBufAllocator.updateAllocator(alloc);
        return this.delegate().allocate(this.preferredDirectByteBufAllocator);
    }
    
    @Override
    public boolean continueReading(final UncheckedBooleanSupplier maybeMoreDataSupplier) {
        return this.readEOF || ((RecvByteBufAllocator.ExtendedHandle)this.delegate()).continueReading(maybeMoreDataSupplier);
    }
    
    @Override
    public boolean continueReading() {
        return this.continueReading(this.defaultMaybeMoreDataSupplier);
    }
    
    void readEOF() {
        this.readEOF = true;
    }
    
    void numberBytesPending(final long numberBytesPending) {
        this.numberBytesPending = numberBytesPending;
    }
    
    private boolean maybeMoreDataToRead() {
        return this.lastBytesRead() == this.attemptedBytesRead();
    }
}
