blob: 7fff4a92721d965f936f28cd292d2aa6576193ff [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.nio.ch;
27
28import sun.misc.*;
29
30
31/**
32 * Manipulates a native array of iovec structs on Solaris:
33 *
34 * typedef struct iovec {
35 * caddr_t iov_base;
36 int iov_len;
37 * } iovec_t;
38 *
39 * @author Mike McCloskey
40 * @since 1.4
41 */
42
43class IOVecWrapper {
44
45 // Miscellaneous constants
46 static int BASE_OFFSET = 0;
47 static int LEN_OFFSET;
48 static int SIZE_IOVEC;
49
50 // The iovec array
51 private AllocatedNativeObject vecArray;
52
53 // Base address of this array
54 long address;
55
56 // Address size in bytes
57 static int addressSize;
58
59 IOVecWrapper(int newSize) {
60 newSize = (newSize + 1) * SIZE_IOVEC;
61 vecArray = new AllocatedNativeObject(newSize, false);
62 address = vecArray.address();
63 }
64
65 void putBase(int i, long base) {
66 int offset = SIZE_IOVEC * i + BASE_OFFSET;
67 if (addressSize == 4)
68 vecArray.putInt(offset, (int)base);
69 else
70 vecArray.putLong(offset, base);
71 }
72
73 void putLen(int i, long len) {
74 int offset = SIZE_IOVEC * i + LEN_OFFSET;
75 if (addressSize == 4)
76 vecArray.putInt(offset, (int)len);
77 else
78 vecArray.putLong(offset, len);
79 }
80
81 void free() {
82 vecArray.free();
83 }
84
85 static {
86 addressSize = Util.unsafe().addressSize();
87 LEN_OFFSET = addressSize;
88 SIZE_IOVEC = (short) (addressSize * 2);
89 }
90}