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 receivedRdHup;
35
36 EpollRecvByteAllocatorHandle(ExtendedHandle handle) {
37 super(handle);
38 }
39
40 final void receivedRdHup() {
41 receivedRdHup = true;
42 }
43
44 final boolean isReceivedRdHup() {
45 return receivedRdHup;
46 }
47
48 boolean maybeMoreDataToRead() {
49 return lastBytesRead() == attemptedBytesRead();
50 }
51
52 @Override
53 public final ByteBuf allocate(ByteBufAllocator alloc) {
54
55 preferredDirectByteBufAllocator.updateAllocator(alloc);
56 return delegate().allocate(preferredDirectByteBufAllocator);
57 }
58
59 @Override
60 public final boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) {
61 return isReceivedRdHup() || ((ExtendedHandle) delegate()).continueReading(maybeMoreDataSupplier);
62 }
63
64 @Override
65 public final boolean continueReading() {
66
67 return continueReading(defaultMaybeMoreDataSupplier);
68 }
69 }