1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.uring;
17
18 import java.nio.ByteBuffer;
19
20
21
22
23
24
25
26
27
28 final class Iov {
29
30 private Iov() { }
31
32 static void set(ByteBuffer buffer, long bufferAddress, int length) {
33 int position = buffer.position();
34 if (Native.SIZEOF_SIZE_T == 4) {
35 buffer.putInt(position + Native.IOVEC_OFFSETOF_IOV_BASE, (int) bufferAddress);
36 buffer.putInt(position + Native.IOVEC_OFFSETOF_IOV_LEN, length);
37 } else {
38 assert Native.SIZEOF_SIZE_T == 8;
39 buffer.putLong(position + Native.IOVEC_OFFSETOF_IOV_BASE, bufferAddress);
40 buffer.putLong(position + Native.IOVEC_OFFSETOF_IOV_LEN, length);
41 }
42 }
43
44 static long getBufferAddress(ByteBuffer iov) {
45 if (Native.SIZEOF_SIZE_T == 4) {
46 return iov.getInt(iov.position() + Native.IOVEC_OFFSETOF_IOV_BASE);
47 }
48 assert Native.SIZEOF_SIZE_T == 8;
49 return iov.getLong(iov.position() + Native.IOVEC_OFFSETOF_IOV_BASE);
50 }
51
52 static int getBufferLength(ByteBuffer iov) {
53 if (Native.SIZEOF_SIZE_T == 4) {
54 return iov.getInt(iov.position() + Native.IOVEC_OFFSETOF_IOV_LEN);
55 }
56 assert Native.SIZEOF_SIZE_T == 8;
57 return (int) iov.getLong(iov.position() + Native.IOVEC_OFFSETOF_IOV_LEN);
58 }
59 }