1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.uring;
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;
22 import io.netty.channel.unix.PreferredDirectByteBufAllocator;
23 import io.netty.util.UncheckedBooleanSupplier;
24
25 final class IoUringRecvByteAllocatorHandle extends RecvByteBufAllocator.DelegatingHandle
26 implements RecvByteBufAllocator.ExtendedHandle {
27 private final PreferredDirectByteBufAllocator preferredDirectByteBufAllocator =
28 new PreferredDirectByteBufAllocator();
29
30 IoUringRecvByteAllocatorHandle(RecvByteBufAllocator.ExtendedHandle handle) {
31 super(handle);
32 }
33
34 private boolean rdHupReceived;
35 private boolean readComplete;
36
37 @Override
38 public void reset(ChannelConfig config) {
39 super.reset(config);
40 readComplete = false;
41 }
42
43 void rdHupReceived() {
44 this.rdHupReceived = true;
45 }
46
47 @Override
48 public ByteBuf allocate(ByteBufAllocator alloc) {
49
50 preferredDirectByteBufAllocator.updateAllocator(alloc);
51 return delegate().allocate(preferredDirectByteBufAllocator);
52 }
53
54 @Override
55 public boolean continueReading() {
56
57 return super.continueReading() || rdHupReceived;
58 }
59
60 @Override
61 public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) {
62
63 return ((RecvByteBufAllocator.ExtendedHandle) delegate()).continueReading(maybeMoreDataSupplier)
64 || rdHupReceived;
65 }
66
67 @Override
68 public void readComplete() {
69 super.readComplete();
70 readComplete = true;
71 }
72
73 boolean isReadComplete() {
74 return readComplete;
75 }
76 }