jdk/src/share/classes/sun/nio/ch/IOUtil.java
author alanb
Sun, 15 Feb 2009 12:25:54 +0000
changeset 2057 3acf8e5e2ca0
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99 4313887: New I/O: Improved filesystem interface 4607272: New I/O: Support asynchronous I/O Reviewed-by: sherman, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
     2
 * Copyright 2000-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.FileDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * File-descriptor based I/O utilities that are shared by NIO classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class IOUtil {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private IOUtil() { }                // No instantiation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Returns the index of first buffer in bufs with remaining,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * or -1 if there is nothing left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static int remaining(ByteBuffer[] bufs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        int numBufs = bufs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        for (int i=0; i<numBufs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            if (bufs[i].hasRemaining()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Returns a new ByteBuffer array with only unfinished buffers in it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static ByteBuffer[] skipBufs(ByteBuffer[] bufs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                         int nextWithRemaining)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        int newSize = bufs.length - nextWithRemaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        ByteBuffer[] temp = new ByteBuffer[newSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        for (int i=0; i<newSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            temp[i] = bufs[i + nextWithRemaining];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static int write(FileDescriptor fd, ByteBuffer src, long position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                     NativeDispatcher nd, Object lock)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (src instanceof DirectBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            return writeFromNativeBuffer(fd, src, position, nd, lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        // Substitute a native buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int pos = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int lim = src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        ByteBuffer bb = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            bb = Util.getTemporaryDirectBuffer(rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            bb.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            bb.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            // Do not update src until we see how many bytes were written
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            src.position(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            int n = writeFromNativeBuffer(fd, bb, position, nd, lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                // now update src
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                src.position(pos + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            Util.releaseTemporaryDirectBuffer(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static int writeFromNativeBuffer(FileDescriptor fd, ByteBuffer bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                           long position, NativeDispatcher nd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                             Object lock)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        int pos = bb.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        int lim = bb.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int written = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (rem == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (position != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            written = nd.pwrite(fd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                ((DirectBuffer)bb).address() + pos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                rem, position, lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            written = nd.write(fd, ((DirectBuffer)bb).address() + pos, rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (written > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            bb.position(pos + written);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static long write(FileDescriptor fd, ByteBuffer[] bufs, NativeDispatcher nd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int nextWithRemaining = remaining(bufs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // if all bufs are empty we should return immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (nextWithRemaining < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // If some bufs are empty we should skip them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (nextWithRemaining > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            bufs = skipBufs(bufs, nextWithRemaining);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        int numBufs = bufs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // Create shadow to ensure DirectByteBuffers are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        ByteBuffer[] shadow = new ByteBuffer[numBufs];
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   140
        try {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   141
            for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   142
                if (!(bufs[i] instanceof DirectBuffer)) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   143
                    int pos = bufs[i].position();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   144
                    int lim = bufs[i].limit();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   145
                    assert (pos <= lim);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   146
                    int rem = (pos <= lim ? lim - pos : 0);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   147
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   148
                    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   149
                    shadow[i] = bb;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   150
                    // Leave slow buffer position untouched; it will be updated
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   151
                    // after we see how many bytes were really written out
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   152
                    bb.put(bufs[i]);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   153
                    bufs[i].position(pos);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   154
                    bb.flip();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   155
                } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   156
                    shadow[i] = bufs[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   157
                }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   158
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   159
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   160
            IOVecWrapper vec = null;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   161
            long bytesWritten = 0;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   162
            try {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   163
                // Create a native iovec array
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   164
                vec= new IOVecWrapper(numBufs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   165
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   166
                // Fill in the iovec array with appropriate data
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   167
                for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   168
                    ByteBuffer nextBuffer = shadow[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   169
                    // put in the buffer addresses
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   170
                    long pos = nextBuffer.position();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   171
                    long len = nextBuffer.limit() - pos;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   172
                    vec.putBase(i, ((DirectBuffer)nextBuffer).address() + pos);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   173
                    vec.putLen(i, len);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   174
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   176
                // Invoke native call to fill the buffers
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   177
                bytesWritten = nd.writev(fd, vec.address, numBufs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   178
            } finally {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   179
                vec.free();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   180
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   181
            long returnVal = bytesWritten;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   182
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   183
            // Notify the buffers how many bytes were taken
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   184
            for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   185
                ByteBuffer nextBuffer = bufs[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   186
                int pos = nextBuffer.position();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   187
                int lim = nextBuffer.limit();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   188
                assert (pos <= lim);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   189
                int len = (pos <= lim ? lim - pos : lim);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   190
                if (bytesWritten >= len) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   191
                    bytesWritten -= len;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   192
                    int newPosition = pos + len;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   193
                    nextBuffer.position(newPosition);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   194
                } else { // Buffers not completely filled
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   195
                    if (bytesWritten > 0) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   196
                        assert(pos + bytesWritten < (long)Integer.MAX_VALUE);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   197
                        int newPosition = (int)(pos + bytesWritten);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   198
                        nextBuffer.position(newPosition);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   199
                    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   200
                    break;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   201
                }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   202
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   203
            return returnVal;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   204
        } finally {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   205
            // return any substituted buffers to cache
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   206
            for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   207
                ByteBuffer bb = shadow[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   208
                if (bb != null && bb != bufs[i]) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   209
                    Util.releaseTemporaryDirectBuffer(bb);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   210
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    static int read(FileDescriptor fd, ByteBuffer dst, long position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    NativeDispatcher nd, Object lock)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (dst.isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            throw new IllegalArgumentException("Read-only buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (dst instanceof DirectBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return readIntoNativeBuffer(fd, dst, position, nd, lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // Substitute a native buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        ByteBuffer bb = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            bb = Util.getTemporaryDirectBuffer(dst.remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            int n = readIntoNativeBuffer(fd, bb, position, nd, lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            bb.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (n > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                dst.put(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Util.releaseTemporaryDirectBuffer(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static int readIntoNativeBuffer(FileDescriptor fd, ByteBuffer bb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                            long position, NativeDispatcher nd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                            Object lock)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int pos = bb.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int lim = bb.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        assert (pos <= lim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int rem = (pos <= lim ? lim - pos : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (rem == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (position != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            n = nd.pread(fd, ((DirectBuffer)bb).address() + pos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                         rem, position, lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            n = nd.read(fd, ((DirectBuffer)bb).address() + pos, rem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (n > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            bb.position(pos + n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    static long read(FileDescriptor fd, ByteBuffer[] bufs, NativeDispatcher nd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        int nextWithRemaining = remaining(bufs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // if all bufs are empty we should return immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (nextWithRemaining < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // If some bufs are empty we should skip them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (nextWithRemaining > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            bufs = skipBufs(bufs, nextWithRemaining);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        int numBufs = bufs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // Read into the shadow to ensure DirectByteBuffers are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        ByteBuffer[] shadow = new ByteBuffer[numBufs];
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   277
        boolean usingSlowBuffers = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            for (int i=0; i<numBufs; i++) {
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   280
                if (bufs[i].isReadOnly())
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   281
                    throw new IllegalArgumentException("Read-only buffer");
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   282
                if (!(bufs[i] instanceof DirectBuffer)) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   283
                    shadow[i] = Util.getTemporaryDirectBuffer(bufs[i].remaining());
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   284
                    usingSlowBuffers = true;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   285
                } else {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   286
                    shadow[i] = bufs[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   287
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   290
            IOVecWrapper vec = null;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   291
            long bytesRead = 0;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   292
            try {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   293
                // Create a native iovec array
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   294
                vec = new IOVecWrapper(numBufs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   295
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   296
                // Fill in the iovec array with appropriate data
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   297
                for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   298
                    ByteBuffer nextBuffer = shadow[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   299
                    // put in the buffer addresses
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   300
                    long pos = nextBuffer.position();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   301
                    long len = nextBuffer.remaining();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   302
                    vec.putBase(i, ((DirectBuffer)nextBuffer).address() + pos);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   303
                    vec.putLen(i, len);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   304
                }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   305
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   306
                // Invoke native call to fill the buffers
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   307
                bytesRead = nd.readv(fd, vec.address, numBufs);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   308
            } finally {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   309
                vec.free();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   310
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   311
            long returnVal = bytesRead;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   313
            // Notify the buffers how many bytes were read
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   314
            for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   315
                ByteBuffer nextBuffer = shadow[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   316
                // Note: should this have been cached from above?
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   317
                int pos = nextBuffer.position();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   318
                int len = nextBuffer.remaining();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   319
                if (bytesRead >= len) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   320
                    bytesRead -= len;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   321
                    int newPosition = pos + len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    nextBuffer.position(newPosition);
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   323
                } else { // Buffers not completely filled
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   324
                    if (bytesRead > 0) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   325
                        assert(pos + bytesRead < (long)Integer.MAX_VALUE);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   326
                        int newPosition = (int)(pos + bytesRead);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   327
                        nextBuffer.position(newPosition);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   328
                    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   329
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                }
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   331
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   332
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   333
            // Put results from shadow into the slow buffers
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   334
            if (usingSlowBuffers) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   335
                for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   336
                    if (!(bufs[i] instanceof DirectBuffer)) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   337
                        shadow[i].flip();
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   338
                        bufs[i].put(shadow[i]);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   339
                    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   340
                }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   341
            }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   342
            return returnVal;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   343
        } finally {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   344
            // return any substituted buffers to cache
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   345
            if (usingSlowBuffers) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   346
                for (int i=0; i<numBufs; i++) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   347
                    ByteBuffer bb = shadow[i];
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   348
                    if (bb != null && bb != bufs[i]) {
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   349
                        Util.releaseTemporaryDirectBuffer(bb);
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   350
                    }
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 2
diff changeset
   351
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    static FileDescriptor newFD(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        FileDescriptor fd = new FileDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        setfdVal(fd, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    static native boolean randomBytes(byte[] someBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    static native void initPipe(int[] fda, boolean blocking);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    static native boolean drain(int fd) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    static native void configureBlocking(FileDescriptor fd, boolean blocking)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    static native int fdVal(FileDescriptor fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    static native void setfdVal(FileDescriptor fd, int value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // Note that IOUtil.initIDs is called from within Util.load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Util.load();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
}