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