Java Code Examples for com.sun.nio.sctp.SctpChannel#receive()
The following examples show how to use
com.sun.nio.sctp.SctpChannel#receive() .
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: NioSctpChannel.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@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 2
Source File: NioSctpChannel.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@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 3
Source File: Receive.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 4
Source File: Branch.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 5
Source File: Branch.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 6
Source File: Branch.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 7
Source File: Receive.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 8
Source File: Branch.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 9
Source File: Branch.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 10
Source File: Receive.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 11
Source File: Receive.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 12
Source File: Branch.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 13
Source File: Receive.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 14
Source File: Receive.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 15
Source File: Branch.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 16
Source File: Receive.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 17
Source File: Branch.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 18
Source File: Receive.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }
Example 19
Source File: Branch.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
void doTest(SocketAddress peerAddress) { SctpMultiChannel channel = null; ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER); MessageInfo info = MessageInfo.createOutgoing(null, 0); try { channel = SctpMultiChannel.open(); /* setup an association implicitly by sending a small message */ int streamNumber = 0; debug("sending to " + peerAddress + " on stream number: " + streamNumber); info = MessageInfo.createOutgoing(peerAddress, streamNumber); buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buffer.flip(); int position = buffer.position(); int remaining = buffer.remaining(); debug("sending small message: " + buffer); int sent = channel.send(buffer, info); check(sent == remaining, "sent should be equal to remaining"); check(buffer.position() == (position + sent), "buffers position should have been incremented by sent"); /* Receive the COMM_UP */ buffer.clear(); BranchNotificationHandler handler = new BranchNotificationHandler(); info = channel.receive(buffer, null, handler); check(handler.receivedCommUp(), "COMM_UP no received"); Set<Association> associations = channel.associations(); check(!associations.isEmpty(),"There should be some associations"); Association bassoc = associations.iterator().next(); /* TEST 1: branch */ SctpChannel bchannel = channel.branch(bassoc); check(!bchannel.getAllLocalAddresses().isEmpty(), "branched channel should be bound"); check(!bchannel.getRemoteAddresses().isEmpty(), "branched channel should be connected"); check(channel.associations().isEmpty(), "there should be no associations since the only one was branched off"); buffer.clear(); info = bchannel.receive(buffer, null, null); buffer.flip(); check(info != null, "info is null"); check(info.streamNumber() == streamNumber, "message not sent on the correct stream"); check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1"). length, "bytes received not equal to message length"); check(info.bytes() == buffer.remaining(), "bytes != remaining"); check(Util.compare(buffer, Util.SMALL_MESSAGE), "received message not the same as sent message"); } catch (IOException ioe) { unexpected(ioe); } finally { clientFinishedLatch.countDown(); try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); } catch (InterruptedException ie) { unexpected(ie); } if (channel != null) { try { channel.close(); } catch (IOException e) { unexpected (e);} } } }
Example 20
Source File: Receive.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public void run() { try { SctpChannel sc = ssc.accept(); /* send a small message */ MessageInfo info = MessageInfo.createOutgoing(null, 0) .payloadProtocolID(PPID); ByteBuffer buf = ByteBuffer.allocateDirect(Util.SMALL_BUFFER); buf.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending small message: " + buf); sc.send(buf, info); /* send a large message */ buf = ByteBuffer.allocateDirect(Util.LARGE_BUFFER); buf.put(Util.LARGE_MESSAGE.getBytes("ISO-8859-1")); buf.flip(); debug("sending large message: " + buf); sc.send(buf, info); sc.shutdown(); debug("shutdown"); ReceiveNotificationHandler handler = new ReceiveNotificationHandler(sc); sc.receive(buf, null, handler); sc.close(); /* accept another socket for the TEST 6 */ sc = ssc.accept(); ssc.close(); clientFinishedLatch.await(10L, TimeUnit.SECONDS); serverFinishedLatch.countDown(); sc.close(); } catch (IOException ioe) { unexpected(ioe); } catch (InterruptedException ie) { unexpected(ie); } }