Java Code Examples for sun.nio.ch.Util#releaseTemporaryDirectBuffer()

The following examples show how to use sun.nio.ch.Util#releaseTemporaryDirectBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SctpMultiChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos);

    /* Substitute a native buffer. */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 2
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 3
Source File: SctpChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 4
Source File: SctpChannelImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example 5
Source File: SctpChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example 6
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example 7
Source File: SctpMultiChannelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos);

    /* Substitute a native buffer. */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 8
Source File: SctpMultiChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos);

    /* Substitute a native buffer. */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 9
Source File: SctpChannelImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 10
Source File: SctpChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 11
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 12
Source File: SctpChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 13
Source File: SctpChannelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd, ByteBuffer src, MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    SocketAddress target = messageInfo.address();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, streamNumber,
                unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, streamNumber,
                unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 14
Source File: SctpMultiChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd,
                 ByteBuffer src,
                 int assocId,
                 SocketAddress target,
                 MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, assocId,
                streamNumber, unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, assocId,
                streamNumber, unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 15
Source File: SctpChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd, ByteBuffer src, MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    SocketAddress target = messageInfo.address();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, streamNumber,
                unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, streamNumber,
                unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 16
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd,
                 ByteBuffer src,
                 int assocId,
                 SocketAddress target,
                 MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, assocId,
                streamNumber, unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, assocId,
                streamNumber, unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 17
Source File: SctpMultiChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd,
                 ByteBuffer src,
                 int assocId,
                 SocketAddress target,
                 MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, assocId,
                streamNumber, unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, assocId,
                streamNumber, unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 18
Source File: SctpMultiChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd,
                 ByteBuffer src,
                 int assocId,
                 SocketAddress target,
                 MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, assocId,
                streamNumber, unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, assocId,
                streamNumber, unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 19
Source File: SctpChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd, ByteBuffer src, MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    SocketAddress target = messageInfo.address();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, streamNumber,
                unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, streamNumber,
                unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example 20
Source File: SctpMultiChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private int send(int fd,
                 ByteBuffer src,
                 int assocId,
                 SocketAddress target,
                 MessageInfo messageInfo)
        throws IOException {
    int streamNumber = messageInfo.streamNumber();
    boolean unordered = messageInfo.isUnordered();
    int ppid = messageInfo.payloadProtocolID();

    if (src instanceof DirectBuffer)
        return sendFromNativeBuffer(fd, src, target, assocId,
                streamNumber, unordered, ppid);

    /* Substitute a native buffer */
    int pos = src.position();
    int lim = src.limit();
    assert (pos <= lim && streamNumber >= 0);

    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
    try {
        bb.put(src);
        bb.flip();
        /* Do not update src until we see how many bytes were written */
        src.position(pos);

        int n = sendFromNativeBuffer(fd, bb, target, assocId,
                streamNumber, unordered, ppid);
        if (n > 0) {
            /* now update src */
            src.position(pos + n);
        }
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}