1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.quic;
17
18 import java.net.InetSocketAddress;
19 import java.nio.ByteBuffer;
20
21
22
23
24
25 final class QuicheRecvInfo {
26
27 private QuicheRecvInfo() { }
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 static void setRecvInfo(ByteBuffer memory, InetSocketAddress from, InetSocketAddress to) {
46 int position = memory.position();
47 try {
48 setAddress(memory, Quiche.SIZEOF_QUICHE_RECV_INFO, Quiche.QUICHE_RECV_INFO_OFFSETOF_FROM,
49 Quiche.QUICHE_RECV_INFO_OFFSETOF_FROM_LEN, from);
50 setAddress(memory, Quiche.SIZEOF_QUICHE_RECV_INFO + Quiche.SIZEOF_SOCKADDR_STORAGE,
51 Quiche.QUICHE_RECV_INFO_OFFSETOF_TO, Quiche.QUICHE_RECV_INFO_OFFSETOF_TO_LEN, to);
52 } finally {
53 memory.position(position);
54 }
55 }
56
57 private static void setAddress(ByteBuffer memory, int socketAddressOffset, int addrOffset, int lenOffset,
58 InetSocketAddress address) {
59 int position = memory.position();
60 try {
61 int sockaddrPosition = position + socketAddressOffset;
62 memory.position(sockaddrPosition);
63 long sockaddrMemoryAddress = Quiche.memoryAddressWithPosition(memory);
64 int len = SockaddrIn.setAddress(memory, address);
65 if (Quiche.SIZEOF_SIZE_T == 4) {
66 memory.putInt(position + addrOffset, (int) sockaddrMemoryAddress);
67 } else {
68 memory.putLong(position + addrOffset, sockaddrMemoryAddress);
69 }
70 Quiche.setPrimitiveValue(memory, position + lenOffset, Quiche.SIZEOF_SOCKLEN_T, len);
71 } finally {
72 memory.position(position);
73 }
74 }
75 }