sun.nio.ch.Util Java Examples

The following examples show how to use sun.nio.ch.Util. 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: SctpChannelImpl.java    From jdk8u_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 #2
Source File: SctpChannelImpl.java    From dragonwell8_jdk 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 #3
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 #4
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 #5
Source File: SctpChannelImpl.java    From jdk8u-dev-jdk 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 TencentKona-8 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: SctpChannelImpl.java    From TencentKona-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 #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 jdk8u60 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 #10
Source File: SctpMultiChannelImpl.java    From TencentKona-8 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 #11
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 #12
Source File: SctpMultiChannelImpl.java    From jdk8u-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 #13
Source File: SctpMultiChannelImpl.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)
        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 #14
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 #15
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 #16
Source File: SctpChannelImpl.java    From openjdk-jdk8u-backup 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 #17
Source File: SctpMultiChannelImpl.java    From jdk8u-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 #18
Source File: SctpChannelImpl.java    From jdk8u_jdk 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 #19
Source File: SctpChannelImpl.java    From jdk8u-jdk 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 #20
Source File: SctpChannelImpl.java    From jdk8u-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 #21
Source File: SctpMultiChannelImpl.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)
        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 #22
Source File: SctpMultiChannelImpl.java    From jdk8u_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 #23
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 #24
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 #25
Source File: SctpMultiChannelImpl.java    From openjdk-8-source 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 #26
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 #27
Source File: SctpChannelImpl.java    From openjdk-8-source 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 #28
Source File: SctpChannelImpl.java    From openjdk-8-source 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 #29
Source File: SctpChannelImpl.java    From openjdk-8 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 #30
Source File: SctpMultiChannelImpl.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)
        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);
    }
}