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.channel.unix.Buffer;
19
20 import java.nio.ByteBuffer;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 final class MsgHdr {
36
37 private MsgHdr() { }
38
39 static void set(ByteBuffer memory, ByteBuffer sockAddrMemory, int addressSize, ByteBuffer iovMemory, int iovLength,
40 ByteBuffer msgControl, int cmsgHdrDataOffset, short segmentSize) {
41 int memoryPosition = memory.position();
42 memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAMELEN, addressSize);
43
44 int msgControlLen = 0;
45 long msgControlAddr;
46 if (segmentSize > 0) {
47 msgControlLen = Native.CMSG_LEN;
48 CmsgHdr.write(msgControl, cmsgHdrDataOffset, Native.CMSG_LEN, Native.SOL_UDP,
49 Native.UDP_SEGMENT, segmentSize);
50 msgControlAddr = Buffer.memoryAddress(msgControl) + msgControl.position();
51 } else {
52
53 msgControlAddr = 0;
54 }
55 if (Native.SIZEOF_SIZE_T == 4) {
56 memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAME, (int) Buffer.memoryAddress(sockAddrMemory));
57 memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, (int) Buffer.memoryAddress(iovMemory));
58 memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
59 memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, (int) msgControlAddr);
60 memory.putInt(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, msgControlLen);
61 } else {
62 assert Native.SIZEOF_SIZE_T == 8;
63 memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_NAME, Buffer.memoryAddress(sockAddrMemory));
64 memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOV, Buffer.memoryAddress(iovMemory));
65 memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_IOVLEN, iovLength);
66 memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROL, msgControlAddr);
67 memory.putLong(memoryPosition + Native.MSGHDR_OFFSETOF_MSG_CONTROLLEN, msgControlLen);
68 }
69
70 }
71 }