1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.kqueue;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.ByteBufAllocator;
20 import io.netty.channel.ChannelConfig;
21 import io.netty.channel.RecvByteBufAllocator.DelegatingHandle;
22 import io.netty.channel.RecvByteBufAllocator.ExtendedHandle;
23 import io.netty.channel.unix.PreferredDirectByteBufAllocator;
24 import io.netty.util.UncheckedBooleanSupplier;
25
26 import static java.lang.Math.max;
27 import static java.lang.Math.min;
28
29 final class KQueueRecvByteAllocatorHandle extends DelegatingHandle implements ExtendedHandle {
30 private final PreferredDirectByteBufAllocator preferredDirectByteBufAllocator =
31 new PreferredDirectByteBufAllocator();
32
33 private final UncheckedBooleanSupplier defaultMaybeMoreDataSupplier = new UncheckedBooleanSupplier() {
34 @Override
35 public boolean get() {
36 return maybeMoreDataToRead();
37 }
38 };
39 private boolean readEOF;
40 private long numberBytesPending;
41
42 KQueueRecvByteAllocatorHandle(ExtendedHandle handle) {
43 super(handle);
44 }
45
46 @Override
47 public ByteBuf allocate(ByteBufAllocator alloc) {
48
49 preferredDirectByteBufAllocator.updateAllocator(alloc);
50 return delegate().allocate(preferredDirectByteBufAllocator);
51 }
52
53 @Override
54 public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) {
55 return readEOF || ((ExtendedHandle) delegate()).continueReading(maybeMoreDataSupplier);
56 }
57
58 @Override
59 public boolean continueReading() {
60
61 return continueReading(defaultMaybeMoreDataSupplier);
62 }
63
64 void readEOF() {
65 readEOF = true;
66 }
67
68 void numberBytesPending(long numberBytesPending) {
69 this.numberBytesPending = numberBytesPending;
70 }
71
72 private boolean maybeMoreDataToRead() {
73
74
75
76
77
78
79
80
81
82
83 return lastBytesRead() == attemptedBytesRead();
84 }
85 }