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.util.internal.PlatformDependent;
19
20
21
22
23
24
25
26
27
28 final class Iov {
29
30 private Iov() { }
31
32 static void write(long iovAddress, long bufferAddress, int length) {
33 if (Native.SIZEOF_SIZE_T == 4) {
34 PlatformDependent.putInt(iovAddress + Native.IOVEC_OFFSETOF_IOV_BASE, (int) bufferAddress);
35 PlatformDependent.putInt(iovAddress + Native.IOVEC_OFFSETOF_IOV_LEN, length);
36 } else {
37 assert Native.SIZEOF_SIZE_T == 8;
38 PlatformDependent.putLong(iovAddress + Native.IOVEC_OFFSETOF_IOV_BASE, bufferAddress);
39 PlatformDependent.putLong(iovAddress + Native.IOVEC_OFFSETOF_IOV_LEN, length);
40 }
41 }
42
43 static long readBufferAddress(long iovAddress) {
44 if (Native.SIZEOF_SIZE_T == 4) {
45 return PlatformDependent.getInt(iovAddress + Native.IOVEC_OFFSETOF_IOV_BASE);
46 }
47 assert Native.SIZEOF_SIZE_T == 8;
48 return PlatformDependent.getLong(iovAddress + Native.IOVEC_OFFSETOF_IOV_BASE);
49 }
50
51 static int readBufferLength(long iovAddress) {
52 if (Native.SIZEOF_SIZE_T == 4) {
53 return PlatformDependent.getInt(iovAddress + Native.IOVEC_OFFSETOF_IOV_LEN);
54 }
55 assert Native.SIZEOF_SIZE_T == 8;
56 return (int) PlatformDependent.getLong(iovAddress + Native.IOVEC_OFFSETOF_IOV_LEN);
57 }
58
59 static long sumSize(long iovAddress, int length) {
60 long sum = 0;
61 for (int i = 0; i < length; i++) {
62 sum += readBufferLength(iovAddress);
63 iovAddress += 2L * Native.SIZEOF_SIZE_T;
64 }
65 return sum;
66 }
67 }