com.sun.nio.sctp.MessageInfo Java Examples

The following examples show how to use com.sun.nio.sctp.MessageInfo. 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: MessageInfoTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void checkGetterSetters(MessageInfo info) {
    check(info.streamNumber(TEST_STREAM_NUMBER).streamNumber() ==
            TEST_STREAM_NUMBER, "stream number not being set correctly");

    check(info.complete(false).isComplete() == false,
            "complete not being set correctly");

    check(info.unordered(true).isUnordered() == true,
            "unordered not being set correctly");

    check(info.payloadProtocolID(TEST_PPID).payloadProtocolID() ==
                              TEST_PPID, "PPID not being set correctly");

    check(info.timeToLive(TEST_TTL).timeToLive() == TEST_TTL,
            "TTL not being set correctly");
}
 
Example #2
Source File: MessageInfoTests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void checkGetterSetters(MessageInfo info) {
    check(info.streamNumber(TEST_STREAM_NUMBER).streamNumber() ==
            TEST_STREAM_NUMBER, "stream number not being set correctly");

    check(info.complete(false).isComplete() == false,
            "complete not being set correctly");

    check(info.unordered(true).isUnordered() == true,
            "unordered not being set correctly");

    check(info.payloadProtocolID(TEST_PPID).payloadProtocolID() ==
                              TEST_PPID, "PPID not being set correctly");

    check(info.timeToLive(TEST_TTL).timeToLive() == TEST_TTL,
            "TTL not being set correctly");
}
 
Example #3
Source File: MessageInfoTests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void checkGetterSetters(MessageInfo info) {
    check(info.streamNumber(TEST_STREAM_NUMBER).streamNumber() ==
            TEST_STREAM_NUMBER, "stream number not being set correctly");

    check(info.complete(false).isComplete() == false,
            "complete not being set correctly");

    check(info.unordered(true).isUnordered() == true,
            "unordered not being set correctly");

    check(info.payloadProtocolID(TEST_PPID).payloadProtocolID() ==
                              TEST_PPID, "PPID not being set correctly");

    check(info.timeToLive(TEST_TTL).timeToLive() == TEST_TTL,
            "TTL not being set correctly");
}
 
Example #4
Source File: SctpChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int send(ByteBuffer buffer, MessageInfo messageInfo)
        throws IOException {
    if (buffer == null)
        throw new IllegalArgumentException("buffer cannot be null");

    if (messageInfo == null)
        throw new IllegalArgumentException("messageInfo cannot be null");

    checkAssociation(messageInfo.association());
    checkStreamNumber(messageInfo.streamNumber());

    synchronized (sendLock) {
        ensureSendOpen();

        int n = 0;
        try {
            begin();

            synchronized (stateLock) {
                if(!isOpen())
                    return 0;
                senderThread = NativeThread.current();
            }

            do {
                n = send(fdVal, buffer, messageInfo);
            } while ((n == IOStatus.INTERRUPTED) && isOpen());

            return IOStatus.normalize(n);
        } finally {
            senderCleanup();
            end((n > 0) || (n == IOStatus.UNAVAILABLE));
            assert IOStatus.check(n);
        }
    }
}
 
Example #5
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 #6
Source File: SctpChannelImpl.java    From jdk8u60 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 #7
Source File: SctpMultiChannelImpl.java    From jdk8u60 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 #8
Source File: MessageInfoTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void checkDefaults(MessageInfo info) {
    check(info.isUnordered() == false, "default unordered value not false");
    check(info.timeToLive() == 0L, "timeToLive should be 0L");
    check(info.isComplete() == true, "default complete value not true");
    check(info.payloadProtocolID() == 0, "default PPID not 0");
    check(info.bytes() == 0, "default bytes value not 0");
    check(info.streamNumber() == DEFAULT_STREAM_NUMBER,
            "incorrect default stream number");
    check(info.address().equals(addr), "incorrect address");
}
 
Example #9
Source File: MessageInfoTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void checkDefaults(MessageInfo info) {
    check(info.isUnordered() == false, "default unordered value not false");
    check(info.timeToLive() == 0L, "timeToLive should be 0L");
    check(info.isComplete() == true, "default complete value not true");
    check(info.payloadProtocolID() == 0, "default PPID not 0");
    check(info.bytes() == 0, "default bytes value not 0");
    check(info.streamNumber() == DEFAULT_STREAM_NUMBER,
            "incorrect default stream number");
    check(info.address().equals(addr), "incorrect address");
}
 
Example #10
Source File: NioSctpChannel.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
    SctpMessage packet = (SctpMessage) msg;
    ByteBuf data = packet.content();
    int dataLen = data.readableBytes();
    if (dataLen == 0) {
        return true;
    }

    ByteBufAllocator alloc = alloc();
    boolean needsCopy = data.nioBufferCount() != 1;
    if (!needsCopy) {
        if (!data.isDirect() && alloc.isDirectBufferPooled()) {
            needsCopy = true;
        }
    }
    ByteBuffer nioData;
    if (!needsCopy) {
        nioData = data.nioBuffer();
    } else {
        data = alloc.directBuffer(dataLen).writeBytes(data);
        nioData = data.nioBuffer();
    }
    final MessageInfo mi = MessageInfo.createOutgoing(association(), null, packet.streamIdentifier());
    mi.payloadProtocolID(packet.protocolIdentifier());
    mi.streamNumber(packet.streamIdentifier());

    final int writtenBytes = javaChannel().send(nioData, mi);
    return writtenBytes > 0;
}
 
Example #11
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int send(ByteBuffer buffer, MessageInfo messageInfo)
        throws IOException {
    if (buffer == null)
        throw new IllegalArgumentException("buffer cannot be null");

    if (messageInfo == null)
        throw new IllegalArgumentException("messageInfo cannot be null");

    checkAssociation(messageInfo.association());
    checkStreamNumber(messageInfo.streamNumber());

    synchronized (sendLock) {
        ensureSendOpen();

        int n = 0;
        try {
            begin();

            synchronized (stateLock) {
                if(!isOpen())
                    return 0;
                senderThread = NativeThread.current();
            }

            do {
                n = send(fdVal, buffer, messageInfo);
            } while ((n == IOStatus.INTERRUPTED) && isOpen());

            return IOStatus.normalize(n);
        } finally {
            senderCleanup();
            end((n > 0) || (n == IOStatus.UNAVAILABLE));
            assert IOStatus.check(n);
        }
    }
}
 
Example #12
Source File: MessageInfoTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) {
    /* TEST 1 : createOutGoing(SocketAddress,int) */
    MessageInfo info = MessageInfo.createOutgoing(addr,
                                                  DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    checkGetterSetters(info);

    /* TEST 2 : createOutGoing(Association,SocketAddress,int) */
    info = MessageInfo.createOutgoing(assoc, addr, DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    check(info.association().equals(assoc), "incorrect association");
    checkGetterSetters(info);

    /* TEST 3: null values */
    info = MessageInfo.createOutgoing(null, 0);
    check(info.address() == null, "address should be null");
    check(info.association() == null, "association should be null");
    info = MessageInfo.createOutgoing(assoc, null, 0);
    check(info.address() == null, "address should be null");

    /* Test 4: IllegalArgumentException */
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, 65537); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(null, addr, 0); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, 65537);}});

    final MessageInfo iaeInfo = MessageInfo.createOutgoing(assoc, addr, 0);
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(-1); } });
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(65537); } });
}
 
Example #13
Source File: SctpChannelImpl.java    From hottub 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: MessageInfoTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) {
    /* TEST 1 : createOutGoing(SocketAddress,int) */
    MessageInfo info = MessageInfo.createOutgoing(addr,
                                                  DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    checkGetterSetters(info);

    /* TEST 2 : createOutGoing(Association,SocketAddress,int) */
    info = MessageInfo.createOutgoing(assoc, addr, DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    check(info.association().equals(assoc), "incorrect association");
    checkGetterSetters(info);

    /* TEST 3: null values */
    info = MessageInfo.createOutgoing(null, 0);
    check(info.address() == null, "address should be null");
    check(info.association() == null, "association should be null");
    info = MessageInfo.createOutgoing(assoc, null, 0);
    check(info.address() == null, "address should be null");

    /* Test 4: IllegalArgumentException */
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, 65537); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(null, addr, 0); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, 65537);}});

    final MessageInfo iaeInfo = MessageInfo.createOutgoing(assoc, addr, 0);
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(-1); } });
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(65537); } });
}
 
Example #15
Source File: SctpMultiChannelImpl.java    From openjdk-jdk8u 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 #16
Source File: SctpChannelImpl.java    From jdk8u-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 #17
Source File: NioSctpChannel.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    SctpChannel ch = javaChannel();

    RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
    ByteBuf buffer = allocHandle.allocate(config().getAllocator());
    boolean free = true;
    try {
        ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes());
        int pos = data.position();

        MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
        if (messageInfo == null) {
            return 0;
        }

        allocHandle.lastBytesRead(data.position() - pos);
        buf.add(new SctpMessage(messageInfo,
                buffer.writerIndex(buffer.writerIndex() + allocHandle.lastBytesRead())));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        if (free) {
            buffer.release();
        }
    }
}
 
Example #18
Source File: MessageInfoTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void checkDefaults(MessageInfo info) {
    check(info.isUnordered() == false, "default unordered value not false");
    check(info.timeToLive() == 0L, "timeToLive should be 0L");
    check(info.isComplete() == true, "default complete value not true");
    check(info.payloadProtocolID() == 0, "default PPID not 0");
    check(info.bytes() == 0, "default bytes value not 0");
    check(info.streamNumber() == DEFAULT_STREAM_NUMBER,
            "incorrect default stream number");
    check(info.address().equals(addr), "incorrect address");
}
 
Example #19
Source File: MessageInfoTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) {
    /* TEST 1 : createOutGoing(SocketAddress,int) */
    MessageInfo info = MessageInfo.createOutgoing(addr,
                                                  DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    checkGetterSetters(info);

    /* TEST 2 : createOutGoing(Association,SocketAddress,int) */
    info = MessageInfo.createOutgoing(assoc, addr, DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    check(info.association().equals(assoc), "incorrect association");
    checkGetterSetters(info);

    /* TEST 3: null values */
    info = MessageInfo.createOutgoing(null, 0);
    check(info.address() == null, "address should be null");
    check(info.association() == null, "association should be null");
    info = MessageInfo.createOutgoing(assoc, null, 0);
    check(info.address() == null, "address should be null");

    /* Test 4: IllegalArgumentException */
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, 65537); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(null, addr, 0); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, 65537);}});

    final MessageInfo iaeInfo = MessageInfo.createOutgoing(assoc, addr, 0);
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(-1); } });
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(65537); } });
}
 
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);
    }
}
 
Example #21
Source File: MessageInfoTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) {
    /* TEST 1 : createOutGoing(SocketAddress,int) */
    MessageInfo info = MessageInfo.createOutgoing(addr,
                                                  DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    checkGetterSetters(info);

    /* TEST 2 : createOutGoing(Association,SocketAddress,int) */
    info = MessageInfo.createOutgoing(assoc, addr, DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    check(info.association().equals(assoc), "incorrect association");
    checkGetterSetters(info);

    /* TEST 3: null values */
    info = MessageInfo.createOutgoing(null, 0);
    check(info.address() == null, "address should be null");
    check(info.association() == null, "association should be null");
    info = MessageInfo.createOutgoing(assoc, null, 0);
    check(info.address() == null, "address should be null");

    /* Test 4: IllegalArgumentException */
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, 65537); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(null, addr, 0); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, 65537);}});

    final MessageInfo iaeInfo = MessageInfo.createOutgoing(assoc, addr, 0);
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(-1); } });
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(65537); } });
}
 
Example #22
Source File: NioSctpChannel.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    SctpChannel ch = javaChannel();

    RecvByteBufAllocator.Handle allocHandle = this.allocHandle;
    if (allocHandle == null) {
        this.allocHandle = allocHandle = config().getRecvByteBufAllocator().newHandle();
    }
    ByteBuf buffer = allocHandle.allocate(config().getAllocator());
    boolean free = true;
    try {
        ByteBuffer data = buffer.internalNioBuffer(buffer.writerIndex(), buffer.writableBytes());
        int pos = data.position();

        MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
        if (messageInfo == null) {
            return 0;
        }
        buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.position() - pos)));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    }  finally {
        int bytesRead = buffer.readableBytes();
        allocHandle.record(bytesRead);
        if (free) {
            buffer.release();
        }
    }
}
 
Example #23
Source File: MessageInfoTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void checkDefaults(MessageInfo info) {
    check(info.isUnordered() == false, "default unordered value not false");
    check(info.timeToLive() == 0L, "timeToLive should be 0L");
    check(info.isComplete() == true, "default complete value not true");
    check(info.payloadProtocolID() == 0, "default PPID not 0");
    check(info.bytes() == 0, "default bytes value not 0");
    check(info.streamNumber() == DEFAULT_STREAM_NUMBER,
            "incorrect default stream number");
    check(info.address().equals(addr), "incorrect address");
}
 
Example #24
Source File: MessageInfoTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) {
    /* TEST 1 : createOutGoing(SocketAddress,int) */
    MessageInfo info = MessageInfo.createOutgoing(addr,
                                                  DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    checkGetterSetters(info);

    /* TEST 2 : createOutGoing(Association,SocketAddress,int) */
    info = MessageInfo.createOutgoing(assoc, addr, DEFAULT_STREAM_NUMBER);
    checkDefaults(info);
    check(info.association().equals(assoc), "incorrect association");
    checkGetterSetters(info);

    /* TEST 3: null values */
    info = MessageInfo.createOutgoing(null, 0);
    check(info.address() == null, "address should be null");
    check(info.association() == null, "association should be null");
    info = MessageInfo.createOutgoing(assoc, null, 0);
    check(info.address() == null, "address should be null");

    /* Test 4: IllegalArgumentException */
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(addr, 65537); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(null, addr, 0); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, -1); } });
    testIAE(new Runnable() {
      public void run() { MessageInfo.createOutgoing(assoc, addr, 65537);}});

    final MessageInfo iaeInfo = MessageInfo.createOutgoing(assoc, addr, 0);
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(-1); } });
    testIAE(new Runnable() {
      public void run() { iaeInfo.streamNumber(65537); } });
}
 
Example #25
Source File: SctpChannelImpl.java    From TencentKona-8 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 #26
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 #27
Source File: SctpMultiChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> MessageInfo receive(ByteBuffer buffer, T attachment,
        NotificationHandler<T> handler) throws IOException {
    throw new UnsupportedOperationException(message);
}
 
Example #28
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> MessageInfo receive(ByteBuffer dst, T attachment,
        NotificationHandler<T> handler) throws IOException {
    throw new UnsupportedOperationException(message);
}
 
Example #29
Source File: SctpMultiChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int send(ByteBuffer buffer, MessageInfo messageInfo)
        throws IOException {
    throw new UnsupportedOperationException(message);
}
 
Example #30
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> MessageInfo receive(ByteBuffer buffer, T attachment,
        NotificationHandler<T> handler) throws IOException {
    throw new UnsupportedOperationException(message);
}