use of com.sun.nio.sctp.SctpChannel in project jdk8u_jdk by JetBrains.
the class Util method isSCTPSupported.
static boolean isSCTPSupported() {
try {
SctpChannel c = SctpChannel.open();
c.close();
return true;
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (UnsupportedOperationException e) {
out.println(e);
}
return false;
}
use of com.sun.nio.sctp.SctpChannel in project jdk8u_jdk by JetBrains.
the class SocketOptionTests method sctpPrimaryAddr.
/* SCTP_PRIMARY_ADDR */
void sctpPrimaryAddr() throws IOException {
SocketAddress addrToSet = null;
ByteBuffer buffer = ByteBuffer.allocate(Util.SMALL_BUFFER);
System.out.println("TESTING SCTP_PRIMARY_ADDR");
/* create listening channel */
SctpServerChannel ssc = SctpServerChannel.open().bind(null);
Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
if (addrs.isEmpty())
debug("addrs should not be empty");
InetSocketAddress serverAddr = (InetSocketAddress) addrs.iterator().next();
/* setup an association implicitly by sending a small message */
int streamNumber = 0;
debug("sending to " + serverAddr + " on stream number: " + streamNumber);
MessageInfo info = MessageInfo.createOutgoing(serverAddr, streamNumber);
buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
buffer.flip();
debug("sending small message: " + buffer);
SctpMultiChannel smc = SctpMultiChannel.open();
int sent = smc.send(buffer, info);
/* Receive the COMM_UP */
buffer.clear();
SOTNotificationHandler handler = new SOTNotificationHandler();
info = smc.receive(buffer, null, handler);
check(handler.receivedCommUp(), "COMM_UP no received");
Set<Association> associations = smc.associations();
check(!associations.isEmpty(), "There should be some associations");
Association assoc = associations.iterator().next();
SctpChannel peerChannel = ssc.accept();
ssc.close();
Set<SocketAddress> peerAddrs = peerChannel.getAllLocalAddresses();
debug("Peer local Addresses: ");
for (Iterator<SocketAddress> it = peerAddrs.iterator(); it.hasNext(); ) {
InetSocketAddress addr = (InetSocketAddress) it.next();
debug("\t" + addr);
// any of the peer addresses will do!
addrToSet = addr;
}
/* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */
if ("SunOS".equals(osName)) {
//smc.setOption(SCTP_PRIMARY_ADDR, addrToSet, assoc);
return;
} else {
/* Linux */
SocketAddress primaryAddr = smc.getOption(SCTP_PRIMARY_ADDR, assoc);
System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
/* Verify that this is one of the peer addresses */
boolean found = false;
// may not have more than one addr
addrToSet = primaryAddr;
for (Iterator<SocketAddress> it = peerAddrs.iterator(); it.hasNext(); ) {
InetSocketAddress addr = (InetSocketAddress) it.next();
if (addr.equals(primaryAddr)) {
found = true;
}
addrToSet = addr;
}
check(found, "SCTP_PRIMARY_ADDR returned bogus address!");
System.out.println("Try SCTP_PRIMARY_ADDR set to: " + addrToSet);
smc.setOption(SCTP_PRIMARY_ADDR, addrToSet, assoc);
System.out.println("SCTP_PRIMARY_ADDR set to: " + addrToSet);
primaryAddr = smc.getOption(SCTP_PRIMARY_ADDR, assoc);
System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");
}
}
use of com.sun.nio.sctp.SctpChannel in project netty by netty.
the class NioSctpChannel method doReadMessages.
@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();
}
}
}
use of com.sun.nio.sctp.SctpChannel in project netty by netty.
the class NioSctpServerChannel method doReadMessages.
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
SctpChannel ch = javaChannel().accept();
if (ch == null) {
return 0;
}
buf.add(new NioSctpChannel(this, ch));
return 1;
}
use of com.sun.nio.sctp.SctpChannel in project jdk8u_jdk by JetBrains.
the class SctpServerChannelImpl method accept.
@Override
public SctpChannel accept() throws IOException {
synchronized (lock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isBound())
throw new NotYetBoundException();
SctpChannel sc = null;
int n = 0;
FileDescriptor newfd = new FileDescriptor();
InetSocketAddress[] isaa = new InetSocketAddress[1];
try {
begin();
if (!isOpen())
return null;
thread = NativeThread.current();
for (; ; ) {
n = accept0(fd, newfd, isaa);
if ((n == IOStatus.INTERRUPTED) && isOpen())
continue;
break;
}
} finally {
acceptCleanup();
end(n > 0);
assert IOStatus.check(n);
}
if (n < 1)
return null;
IOUtil.configureBlocking(newfd, true);
InetSocketAddress isa = isaa[0];
sc = new SctpChannelImpl(provider(), newfd);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkAccept(isa.getAddress().getHostAddress(), isa.getPort());
return sc;
}
}
Aggregations