Package com.sun.nio.sctp

Examples of com.sun.nio.sctp.SctpChannel


  /**
   * @return true if sctp is supported by this OS and false in not
   */
  public static boolean checkSctpEnabled() {
    try {
      SctpChannel socketChannel = SctpChannel.open();
      socketChannel.close();
      return true;
    } catch (Exception e) {
      return false;
    }
  }
View Full Code Here


  /**
   * @return true if sctp is supported by this OS and false in not
   */
  public static boolean checkSctpEnabled() {
    try {
      SctpChannel socketChannel = SctpChannel.open();
      socketChannel.close();
      return true;
    } catch (Exception e) {
      return false;
    }
  }
View Full Code Here

    // For an accept to be pending the channel must be a server socket
    // channel.
    SctpServerChannel serverSocketChannel = (SctpServerChannel) key.channel();

    // Accept the connection and make it non-blocking
    SctpChannel socketChannel = serverSocketChannel.accept();

    Set<SocketAddress> peerAddresses = socketChannel.getRemoteAddresses();

    this.doAccept(serverSocketChannel, socketChannel, peerAddresses);
  }
View Full Code Here

  private void finishConnectionSctp(SelectionKey key) throws IOException {

    AssociationImpl association = (AssociationImpl) key.attachment();
    try {
      SctpChannel socketChannel = (SctpChannel) key.channel();

      if (socketChannel.isConnectionPending()) {

        // TODO Loop? Or may be sleep for while?
        while (socketChannel.isConnectionPending()) {
          socketChannel.finishConnect();
        }
      }

      if (logger.isInfoEnabled()) {
        logger.info(String.format("Association=%s connected to=%s", association.getName(), socketChannel.getRemoteAddresses()));
      }

      // Register an interest in writing on this channel
      key.interestOps(SelectionKey.OP_READ);
    } catch (Exception e) {
View Full Code Here

        return (SctpChannel) super.javaChannel();
    }

    @Override
    public boolean isActive() {
        SctpChannel ch = javaChannel();
        return ch.isOpen() && association() != null;
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @Override
    protected int doReadMessages(MessageBuf<Object> buf) throws Exception {
        SctpChannel ch = javaChannel();
        ByteBuf buffer = alloc().directBuffer(config().getReceiveBufferSize());
        boolean free = true;
        try {
            ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
            MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
            if (messageInfo == null) {
                return 0;
            }

            data.flip();
View Full Code Here

        javaChannel().close();
    }

    @Override
    protected int doReadMessages(MessageBuf<Object> buf) throws Exception {
        SctpChannel ch = javaChannel().accept();
        if (ch == null) {
            return 0;
        }
        buf.add(new NioSctpChannel(this, null, ch));
        return 1;
View Full Code Here

    protected int doReadMessages(MessageBuf<Object> buf) throws Exception {
        if (!isActive()) {
            return -1;
        }

        SctpChannel s = null;
        try {
            final int selectedKeys = selector.select(SO_TIMEOUT);
            if (selectedKeys > 0) {
                final Set<SelectionKey> selectionKeys = selector.selectedKeys();
                for (SelectionKey key : selectionKeys) {
                   if (key.isAcceptable()) {
                       s = sch.accept();
                       if (s != null) {
                           buf.add(new OioSctpChannel(this, null, s));
                       }
                   }
                }
                return selectedKeys;
            }

        } catch (Throwable t) {
            logger.warn("Failed to create a new channel from an accepted sctp channel.", t);
            if (s != null) {
                try {
                    s.close();
                } catch (Throwable t2) {
                    logger.warn("Failed to close a sctp channel.", t2);
                }
            }
        }
View Full Code Here

        return (SctpChannel) super.javaChannel();
    }

    @Override
    public boolean isActive() {
        SctpChannel ch = javaChannel();
        return ch.isOpen() && association() != null;
    }
View Full Code Here

        javaChannel().close();
    }

    @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;
View Full Code Here

TOP

Related Classes of com.sun.nio.sctp.SctpChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.